2

EDITS AT THE BOTTOM

Currently experiencing one error after another. It seems I make a step forward and have to take 2 steps back :) Unfortunately I have nobody locally that I can pair with so a lot of my debugging is being done over Google and SO.

I'm not very familiar with jaxb and using it to make soap calls (which is what I'm currently trying to do - connect to soap service) but I was told that this is the easiest approach for what I'm wanting to do and that I should look into this since I'm using spring-boot in the rest of the project so I found a tutorial (here) and started there.

Here is the plugin section of my pom that creates the package of classes based on the wsdl:

<plugin>
    <groupId>org.jvnet.jaxb2.maven2</groupId>
    <artifactId>maven-jaxb2-plugin</artifactId>
    <version>0.12.3</version>

    <executions>
        <execution>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>

    <configuration>
        <schemaLanguage>WSDL</schemaLanguage>
        <generatePackage>vantiveGenericWebService.wsdl</generatePackage>

        <schemas>
            <schema>
                <url>http://hostname:port/GenericWebService/ws?service=InstalledComponentService2&amp;appl=vantive&amp;wsdl</url>               
            </schema>
        </schemas>
    </configuration>
</plugin>

I'm able to create the wsdl classes fine.

I created a client class:

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import vantiveGenericWebService.wsdl.GetICDetailsByAssetTag;
import vantiveGenericWebService.wsdl.GetICDetailsByAssetTagResponse;

@Component
public class VantiveGenericWebServiceClient extends WebServiceGatewaySupport {

    Logger log = Logger.getLogger(VantiveGenericWebServiceClient.class.getName());

    public GetICDetailsByAssetTagResponse getICDetailsByAssetTag(String assetTag) {
        GetICDetailsByAssetTag request = new GetICDetailsByAssetTag();
        request.setAssetTag(assetTag);

        log.info("Requesting asset tag for: " + assetTag);

        GetICDetailsByAssetTagResponse response = (GetICDetailsByAssetTagResponse) getWebServiceTemplate().marshalSendAndReceive("http://hostname:port/GenericWebService/ws?service=InstalledComponentService2&appl=vantive", request);

        return response;
    }
}

as well as a client config class:

@Configuration
public class VantiveGenericWebServiceConfig {

    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
        marshaller.setContextPath("vantiveGenericWebService.wsdl");
        return marshaller;
    }

    @Bean
    public VantiveGenericWebServiceClient vantiveGenericWebServiceClient(Jaxb2Marshaller marshaller) {
        VantiveGenericWebServiceClient client = new VantiveGenericWebServiceClient();
        client.setDefaultUri("http://hostname:port/GenericWebService/ws?&service=InstalledComponentService2&appl=vantive");
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);

//        ClientInterceptor[] interceptors = new ClientInterceptor[] { new ClientInterceptor() {
//            @Override
//            public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
//                return false;
//            }
//
//            @Override
//            public boolean handleResponse(MessageContext messageContext) throws WebServiceClientException {
//                return true;
//            }
//
//            @Override
//            public boolean handleFault(MessageContext messageContext) throws WebServiceClientException {
//                return true;
//            }
//
//            @Override
//            public void afterCompletion(MessageContext messageContext, Exception e) throws WebServiceClientException {
//
//            }
//        }};

//        client.setInterceptors(interceptors);
        return client;
    }
}

Now on to the error! First I was getting one that looked like this:

org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
 - with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "vantiveGenericWebService.wsdl.GetICDetailsByAssetTag" as an element because it is missing an @XmlRootElement annotation]

so then I modified the GetICDetailsByAssetTag class (a class that was generated from the wsdl) to look like this:

@XmlRootElement(name = "assetTag")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "getICDetailsByAssetTag", propOrder = {
    "assetTag"
})
public class GetICDetailsByAssetTag {

which I'm not 100% sure is the correct xml root but the error goes away. Now my 2nd (and current) error is this:

org.springframework.oxm.UnmarshallingFailureException: JAXB unmarshalling exception; nested exception is javax.xml.bind.UnmarshalException: unexpected element (uri:"http://schemas.xmlsoap.org/soap/envelope/", local:"Fault"). Expected elements are <{http://hostname/vantive/ws/InstalledComponentService2}DuplicateException>,<{http://hostname/vantive/ws/InstalledComponentService2}FunctionalException>,<{http://hostname/vantive/ws/InstalledComponentService2}GetICDetailsByAssetTagResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}GetInstalledComponentDetailsByAssetTagAndStatusResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}InvalidValuesException>,<{http://hostname/vantive/ws/InstalledComponentService2}SetClientDeviceXrefResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}SetInstalledComponentAssetTagResponse>,<{http://hostname/vantive/ws/InstalledComponentService2}TechnicalException>,<{http://hostname/vantive/ws/InstalledComponentService2}assetTag>,<{http://hostname/vantive/ws/InstalledComponentService2}getICDetailsByAssetTag>,<{http://hostname/vantive/ws/InstalledComponentService2}getInstalledComponentDetailsByAssetTagAndStatus>,<{http://hostname/vantive/ws/InstalledComponentService2}installedComponentAssetTagDetails>,<{http://hostname/vantive/ws/InstalledComponentService2}installedComponentDetails>,<{http://hostname/vantive/ws/InstalledComponentService2}setClientDeviceXref>,<{http://com.savvis.it/vantive/ws/InstalledComponentService2}setClientDeviceXrefResult>,<{http://hostname/vantive/ws/InstalledComponentService2}setInstalledComponentAssetTag>,<{http://hostname/vantive/ws/InstalledComponentService2}setInstalledComponentAssetTagResult>

I can post the full stacktraces if necessary. I'm omitting right now for space.

Believe me when I say I have scoured Google and SO looking at all the posts and suggested answers for these errors (that's why I have the currently commented out interceptor code in my config) and I just can't seem to find anything that 1. fixes it and 2. explains what exactly I'm doing wrong. I don't very much care for having something that works but I also where can't tell you what's happening.

Coincidentally, the interceptor portion makes it so no error is thrown but then my response is null.

I have a feeling that my problem is going to be a simple one but since this is my first time doing something like this it's just not jumping out at me. Right now I'm just wanting to send my request and get the valid response that I'm expecting and I'll be happy.

For S&Gs, here's my soap request body too (taken from SoapUI):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins="http://hostname/vantive/ws/InstalledComponentService2">
   <soapenv:Header/>
   <soapenv:Body>
      <ins:getICDetailsByAssetTag>
         <assetTag>asserTag</assetTag>
      </ins:getICDetailsByAssetTag>
   </soapenv:Body>
</soapenv:Envelope>

EDIT After looking at this I can confirm that my ObjectFactory class (that was created via the wsdl) does have create methods that are wrapped with the JAXBElement wrapper, have @XmlElementDecl(namespace = "http://hostname/vantive/ws/InstalledComponentService2", xxx), and also name tags that correspond to the class that is wrapped by the JAXBElement wrapper.

EDIT 2 Just for clarity's sake, here is my package-info class

@XmlSchema(namespace = "http://hostname/vantive/ws/InstalledComponentService2")
package vantiveGenericWebService.wsdl;
Community
  • 1
  • 1
user1818298
  • 509
  • 2
  • 8
  • 23
  • Check out this blog post for a very good explanation regarding XmlRootElement: http://blog.bdoughan.com/2012/07/jaxb-and-root-elements.html – Jonck van der Kogel Oct 13 '16 at 20:37
  • 1
    Hey, thanks for the link @JonckvanderKogel! It was a lot of information (good stuff) and I actually walked away with more questions but I'll save those for another topic :) The one quick thing I took away was that my setting the XmlRootElement to "assetTag" might actually be the correct element...based off the soap request. – user1818298 Oct 13 '16 at 20:45

0 Answers0