Spring MVC RESTful interface

1

I'm new to spring and I would like to create RESTful interface. I can't get simple sample code working and I can't figure out where is the issue...

The below code triggers error:

  • Exception reading manifest from http://localhost:8080/myTestApp/test: the manifest may not be valid or the file could not be opened.
  • Source: System.Deployment

The code:

@RequestMapping(method=RequestMethod.GET, value="/test")
@ResponseBody
public String test(@RequestBody String body){
    String testString = test.CreateXml();
    return testString;
    //return "home";
}

If I first launch the project in server with the below code

@RequestMapping(method=RequestMethod.GET, value="/test")
//@ResponseBody
public String test(@RequestBody String body){
    String testString = test.CreateXml();
    //return testString;
    return "home";
}

Then I uncomment "@ResponseBody" and "return testString" and put comment for "return "home"" line while the server is up and running. So the code looks precisely like the previous what didn't worked. After the changes to code I press Save and the new code is delivered to server on fly. After these changes the "test" interface works. If I restart server I again receive error.

I'm using "Spring Tool Suite 3.4.0" and as servers tried "VMware Fabric tc Server Developer Edition v2.9" and "Tomcat v7". With both servers there is the same issue so the cause should be somewhere in spring configuration. Could anyone please help?

Below I have attached error log

PLATFORM VERSION INFO
    Windows             : 6.1.7601.65536 (Win32NT)
    Common Language Runtime     : 4.0.30319.18444
    System.Deployment.dll       : 4.0.30319.18408 built by: FX451RTMGREL
    clr.dll             : 4.0.30319.18444 built by: FX451RTMGDR
    dfdll.dll           : 4.0.30319.18408 built by: FX451RTMGREL
    dfshim.dll          : 4.0.41209.0 (Main.041209-0000)

SOURCES
    Deployment url          : http://localhost:8080/myTestApp/test

ERROR SUMMARY
    Below is a summary of the errors, details of these errors are listed later in the log.
    * Activation of http://localhost:8080/myTestApp/test resulted in exception. Following failure messages were detected:
        + Exception reading manifest from http://localhost:8080/myTestApp/test: the manifest may not be valid or the file could not be opened.
        + Parsing and DOM creation of the manifest resulted in error. Following parsing errors were noticed: 
            -HRESULT:   0x8007001f
             Start line:    0
             Start column:  0
             Host file:     
        + A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)

COMPONENT STORE TRANSACTION FAILURE SUMMARY
    No transaction error was detected.

WARNINGS
    There were no warnings during this operation.

OPERATION PROGRESS STATUS
    * [3/30/2014 8:21:24 PM] : Activation of http://localhost:8080/myTestApp/test has started.

ERROR DETAILS
    Following errors were detected during this operation.
    * [3/30/2014 8:21:35 PM] System.Deployment.Application.InvalidDeploymentException (ManifestParse)
        - Exception reading manifest from http://localhost:8080/myTestApp/test: the manifest may not be valid or the file could not be opened.
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
            at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options)
            at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
            at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
        --- Inner Exception ---
        System.Deployment.Application.InvalidDeploymentException (ManifestParse)
        - Parsing and DOM creation of the manifest resulted in error. Following parsing errors were noticed: 
            -HRESULT:   0x8007001f
             Start line:    0
             Start column:  0
             Host file:     
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Application.Manifest.AssemblyManifest.LoadCMSFromStream(Stream stream)
            at System.Deployment.Application.Manifest.AssemblyManifest..ctor(FileStream fileStream)
            at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
        --- Inner Exception ---
        System.Runtime.InteropServices.COMException
        - A device attached to the system is not functioning. (Exception from HRESULT: 0x8007001F)
        - Source: System.Deployment
        - Stack trace:
            at System.Deployment.Internal.Isolation.IsolationInterop.CreateCMSFromXml(Byte[] buffer, UInt32 bufferSize, IManifestParseErrorCallback Callback, Guid& riid)
            at System.Deployment.Application.Manifest.AssemblyManifest.LoadCMSFromStream(Stream stream)

COMPONENT STORE TRANSACTION DETAILS
    No transaction information is available.

The "Test" is sample code for REST interface. Currently it generates "dummy" xml. Below is generated dummy xml.

<root>
<!--This is a comment-->
<test name="value">My node value</test>
</root>

Below is code for the "test"

public class test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        CreateXml();
    }
    public static String CreateXml() {
        String xmlString = null;
            try {

                //Creating an empty XML Document
                DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
                DocumentBuilder docBuilder = dbfac.newDocumentBuilder();
                Document doc = docBuilder.newDocument();

                //Creating the XML tree

                //create the root element and add it to the document
                Element root = doc.createElement("root");
                doc.appendChild(root);

                //create a comment and put it in the root element
                Comment comment = doc.createComment("This is a comment");
                root.appendChild(comment);

                //create child element, add an attribute, and add to root
                Element child = doc.createElement("test");
                child.setAttribute("name", "value");
                root.appendChild(child);

                //add a text element to the child
                Text text = doc.createTextNode("My node value");
                child.appendChild(text);

                //Output the XML to a string

                //set up a transformer
                TransformerFactory transfac = TransformerFactory.newInstance();
                Transformer trans = transfac.newTransformer();
                trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
                trans.setOutputProperty(OutputKeys.INDENT, "yes");

                //create string from xml tree
                StringWriter sw = new StringWriter();
                StreamResult result = new StreamResult(sw);
                DOMSource source = new DOMSource(doc);
                trans.transform(source, result);
                xmlString = sw.toString();

                //print xml
                System.out.println("xml output :\n\n" + xmlString);

            } catch (Exception e) {
                System.out.println(e);
            }
            return xmlString;
        }
}

I haven't touched context xml and it was auto generated. Below is the servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven />

    <!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
    <resources mapping="/resources/**" location="/resources/" />

    <!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

    <context:component-scan base-package="com.mobile.myTestApp" />



</beans:beans>
java
spring
rest
tomcat
spring-mvc
asked on Stack Overflow Mar 29, 2014 by Peteris • edited Mar 30, 2014 by Peteris

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0