Announcement Announcement Module
Collapse
No announcement yet.
Problem: Only top level element appears in processed result Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem: Only top level element appears in processed result

    I am experiencing a problem where only the top level xml element is available in the Result of a call to a web service using Spring WebServiceTemplate.

    zip file attached contains unit test and and debug trace.

    class is:

    Code:
    public void test() throws JDOMException, IOException {
    	Document request = buildRequest();
    	JDOMSource source = new JDOMSource(request);
    	JDOMResult result = new JDOMResult();
    	WebServiceTemplate template = new WebServiceTemplate();
    	template.setMessageSender(new CommonsHttpMessageSender());
    	String url = "http://www.webservicex.net/CurrencyConvertor.asmx";
    	template.sendSourceAndReceiveToResult(url, source, new WebServiceMessageCallback() {
    
    		public void doWithMessage(WebServiceMessage message) throws IOException, TransformerException {
    			SoapMessage sm = (SoapMessage) message;
    			sm.setSoapAction("http://www.webserviceX.NET/ConversionRate");
    		}
    	}, result);
    
    	Document doc = result.getDocument();
    	StringWriter sw = new StringWriter();
    	new XMLOutputter().output(doc, sw);
    	String response = sw.toString();
    	if (logger.isDebugEnabled())
    		logger.debug("Response after loading into JDOM: " + response);
    	assertEquals(expectedResponse(), response);
    }
    
    private Document buildRequest() throws JDOMException, IOException {
    	String xml = "<web:ConversionRate xmlns:web='http://www.webserviceX.NET/'><web:FromCurrency>EUR</web:FromCurrency><web:ToCurrency>GBP</web:ToCurrency></web:ConversionRate>";
    	return new SAXBuilder().build(new StringReader(xml));
    }
    
    private String expectedResponse() {
    	String xml = "<?xml version='1.0' encoding='UTF-8'?>\n<ConversionRateResponse xmlns='http://www.webserviceX.NET/'><ConversionRateResult>0.8615</ConversionRateResult></ConversionRateResponse>";
    	return xml.replace("'", "\"");
    }
    In the http client trace is see this coming back as the response SOAP Body:

    Code:
    <ConversionRateResponse xmlns="http://www.webserviceX.NET/"><ConversionRateResult>0.8619</ConversionRateResult></ConversionRateResponse>
    But my JDOMResult only contains:

    Code:
    <ConversionRateResponse xmlns="http://www.webserviceX.NET/" />
    I am using Spring 3.0.0.M3 and spring ws 1.5.8-SNAPSHOT.

    Is anyone able to reproduce my error? Or let me know what I'm doing wrong?

    Cheers.

  • #2
    So is this a bug then?

    I think this might be a bug in Spring-WS. I can open a JIRA if necessary.

    Anyone got any other thoughts?

    Comment


    • #3
      Jaxen/Eclipse Problem

      So I have some more observations.

      I recreated the unit test in a new maven project and it all worked ok.

      Then I copied over my other maven dependencies from my main project (that breaks) and I have found that as soon as I add this dependency:

      Code:
      <dependency>
      	<groupId>jaxen</groupId>
      	<artifactId>jaxen</artifactId>
      	<version>1.1</version>
      </dependency>
      Then the new clean project breaks and the unit test fails.

      However, when I remove the jaxen dependency from my main app, it still fails. But only when running the unit test INSIDE ECLIPSE. If I run "mvn clean install" on my main project then the unit test passes.

      So now I have 2 projects both with exactly the same maven dependencies:

      Main Project
      Unit test succeeds under maven
      Unit test fails under eclipse

      Isolated Test Project
      Unit test succeeds under maven
      Unit test succeeds under eclipse

      Now I am completely at a loss to understand what might be happening.
      .
      Any help or ideas would be most appreciated.

      Comment


      • #4
        SOLVED: related to Roo!?

        I finally solved it by changing my Roo/maven generated eclipse .project file from:

        Code:
        <projectDescription>
          <name>project-name</name>
          <projects/>
          <buildSpec>
            <buildCommand>
              <name>org.eclipse.wst.common.project.facet.core.builder</name>
            </buildCommand>
            <buildCommand>
              <name>org.eclipse.wst.validation.validationbuilder</name>
            </buildCommand>
            <buildCommand>
              <name>org.eclipse.ajdt.core.ajbuilder</name>
            </buildCommand>
            <buildCommand>
              <name>org.springframework.ide.eclipse.core.springbuilder</name>
            </buildCommand>
            <buildCommand>
              <name>org.eclipse.jdt.core.javabuilder</name>
            </buildCommand>
            <buildCommand>
              <name>org.maven.ide.eclipse.maven2Builder</name>
            </buildCommand>
          </buildSpec>
          <natures>
            <nature>org.maven.ide.eclipse.maven2Nature</nature>
            <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
            <nature>org.eclipse.jdt.core.javanature</nature>
            <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
            <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
            <nature>org.eclipse.ajdt.ui.ajnature</nature>
            <nature>com.springsource.sts.roo.core.nature</nature>
            <nature>org.springframework.ide.eclipse.core.springnature</nature>
          </natures>
        </projectDescription>
        to this:

        Code:
        <projectDescription>
        	<name>project-name</name>
        	<projects>
        	</projects>
        	<buildSpec>
        		<buildCommand>
        			<name>org.eclipse.jdt.core.javabuilder</name>
        			<arguments>
        			</arguments>
        		</buildCommand>
        		<buildCommand>
        			<name>org.maven.ide.eclipse.maven2Builder</name>
        			<arguments>
        			</arguments>
        		</buildCommand>
        	</buildSpec>
        	<natures>
        		<nature>org.maven.ide.eclipse.maven2Nature</nature>
        		<nature>org.eclipse.jdt.core.javanature</nature>
        	</natures>
        </projectDescription>
        And now it works fine. I'm not even using any Roo features... but I used it to generate the project initially when I was evaluating it. Ho hum.

        Comment

        Working...
        X