springmavenjaxbmarshallingwebservicetemplate

org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception using Spring WebserviceTemplate


Have a Java based application uses different maven projects to connect to different webservices, application already had an existing maven project(say project1) which uses webServiceTemplate to call the SOAP based service and get the response.

I have now a new requirement to create another similar project for a different service but need to use the wsse security headers. I created a new maven project and called the service using the webServiceTemplate implementation.

Both the projects in standalone works fine, but when clubbed together getting the below exception

org.springframework.oxm.UncategorizedMappingException: Unknown JAXB exception; nested exception is javax.xml.bind.JAXBException: class org.com.project1.cm.CreateRequest nor any of its super class is known to this context..) 

SpringService context xml is as below

     <bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
        <property name="messageSender">
            <bean class="org.springframework.ws.transport.http.HttpComponentsMessageSender">
                <property name="credentials" ref="credentialProvider" />
                <property name="authScope" ref="authScope" />
                <property name="httpClient" ref="httpClient" />
            </bean>
        </property>
        <property name="defaultUri" value="${myproject.endpoint.url}"/>    
        <property name="marshaller" ref="marshaller" />
        <property name="unmarshaller" ref="unMarshaller" />
        <property name="interceptors">
            <list>              
                <bean
                    class="org.com.project1.cm.SoapLoggingInterceptor" >                    
                </bean>
            </list>
        </property>
    </bean>
    
    <oxm:jaxb2-marshaller id="marshaller" contextPath="org.com.project1.cm"/> 
    <oxm:jaxb2-marshaller id="unMarshaller" contextPath="org.com.project1.cm" /> 

Another project uses a similar Spring Context xml only the jaxb2-marshaller has the contextPath of new Service

Invokation of service is done with the below code in both the projects Impl class

public AttendenceResponse getAttendenceDetails(AttendenceRequest request) {
        try {
            MyData myData = AttendenceRequestMapper.getInstance().map(request.getPayload());
            AttendenceResponse aResponse = (AttendenceResponse) webServiceTemplate.marshalSendAndReceive(webServiceTemplate.getDefaultUri(), myData);

            return AttendenceResponseMapper.getInstance().map(aResponse.getMyDataResult());
          } catch (Exception e) {
             throw se;
        }
    }

For the Project 2 I had to add the wsse security headers, so added the below jars in pom.xml

<dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-security</artifactId>
            <version>2.3.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>

can you please guide me on resolving this issue?


Solution

  • The issue for this was both the projects Spring Service context xml for webservice template, marshaller and unmarshaller had the same bean name . Giving a unique bean name resolved the issue