How do I marshall a SOAP response with JAX2B when the response only contains a string that itself contains a string of XML?



I have been stuck on this problem for a solid week now without making much headway. We recently got access to an API that we want to use to be able to integrate that system with a current system of ours. The API is a pretty basic (I think) SOAP API.


We are using a Java Spring MVC project to do this. I was able to use this Spring tutorial to get hooked up to the API so that I can make requests to it and successfully get responses back from it (This is the mentioned tutorial: http://ift.tt/1oamU4Z)


It uses this jaxb2 plugin to do the dirty work and create Java objects based off the WSDL of the SOAP service, which is fine:



<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>hello.wsdl</generatePackage>
<forceRegenerate>true</forceRegenerate>
<schemas>
<schema>
<url>http://ift.tt/1CIc10s;
</schema>
</schemas>
</configuration>


Of course, I have changed the generatePackage value and the schema url to match the API I am communicating with. As said, this works fine. Unfortunately, this is how the API that I am interacting with's response's are crafted:



<s:element name="GetBuildingsResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="GetBuildingsResult" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>


But, in that GetBuildingsResult string, there are actually 3 more levels of XML:



<Buildings>
<Data>
<Description>Building1Description</Description>
<Abbreviation>Building1Abbreviation</Abbreviation>
<ID>Building1ID</ID>
</Data>
<Data>
<Description>Building2Description</Description>
<Abbreviation>Building2Abbreviation</Abbreviation>
<ID>Building2ID</ID>
</Data>
</Buildings>


So there is a Buildings Array with a list of Buildings in it, each called Data, with individual details for each building inside the Data tag.


As it is, the JAX2B marshaller, when it makes the Java objects all I get is an object called GetBuildingsResponse that contains a string called GetBuildingsResult.


Is there a way that I can set it up so that JAX2B can/will look further and make , , and the elements inside of Data into object so that I don't have to manually parse these results after I have gotten them?


I'm sure that there has to be some way to do it, but as of right now I am pretty inexperienced with SOAP web services and this JAX2B plugin as well. Please let me know if I should post or give any more information.


No comments:

Post a Comment