spring - JAXBException: class java.util.ArrayList nor any of its super class is known to this context -
i new spring integration , while working project requirement. facing below issue marshall pojo(java object) soap response(using spring integration ws): please find below details same:
i have sample xsd file below:
</xsd:element> <xsd:element name="myuserresponses"> <xsd:complextype> <xsd:sequence> <xsd:element minoccurs="0" maxoccurs="unbounded" name="myuserresponse" type="tns:myuserresponse" /> </xsd:sequence> </xsd:complextype> </xsd:element> <xsd:complextype name="myuserresponse"> <xsd:sequence> <xsd:element minoccurs="0" maxoccurs="1" name="somenumber" type="xsd:string"/> <xsd:element minoccurs="0" maxoccurs="1" name="referenceid" type="xsd:string" /> </xsd:sequence> </xsd:complextype> </xsd:schema>
i have created below java object files using xjc compiler:
package com.myuser.echannel; import javax.xml.bind.annotation.xmlaccesstype; import javax.xml.bind.annotation.xmlaccessortype; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmlrootelement; import javax.xml.bind.annotation.xmltype; /** * <p>java class anonymous complex type. * * <p>the following schema fragment specifies expected content contained within class. * * <pre> * <complextype> * <complexcontent> * <restriction base="{http://www.w3.org/2001/xmlschema}anytype"> * <sequence> * <element name="somenumber" type="{http://www.w3.org/2001/xmlschema}string" minoccurs="0"/> * <element name="referenceid" type="{http://www.w3.org/2001/xmlschema}string" minoccurs="0"/> * </sequence> * </restriction> * </complexcontent> * </complextype> * </pre> * * */ @xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = { "somenumber", "referenceid" }) @xmlrootelement(name = "myuserrequest") public class myuserrequest { @xmlelement(name = "somenumber") protected string somenumber; @xmlelement(name = "referenceid") protected string referenceid; /** * gets value of somenumber property. * * @return * possible object * {@link string } * */ public string getsomenumber() { return somenumber; } /** * sets value of somenumber property. * * @param value * allowed object * {@link string } * */ public void setsomenumber(string value) { this.somenumber = value; } /** * gets value of referenceid property. * * @return * possible object * {@link string } * */ public string getreferenceid() { return referenceid; } /** * sets value of referenceid property. * * @param value * allowed object * {@link string } * */ public void setreferenceid(string value) { this.referenceid = value; } }
another java object:
package com.myuser.echannel; import javax.xml.bind.annotation.xmlaccesstype; import javax.xml.bind.annotation.xmlaccessortype; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmltype; /** * <p>java class myuserresponse complex type. * * <p>the following schema fragment specifies expected content contained within class. * * <pre> * <complextype name="myuserresponse"> * <complexcontent> * <restriction base="{http://www.w3.org/2001/xmlschema}anytype"> * <sequence> * <element name="somenumber" type="{http://www.w3.org/2001/xmlschema}string" minoccurs="0"/> * <element name="referenceid" type="{http://www.w3.org/2001/xmlschema}string" minoccurs="0"/> * </sequence> * </restriction> * </complexcontent> * </complextype> * </pre> * * */ @xmlaccessortype(xmlaccesstype.field) @xmltype(name = "myuserresponse", proporder = { "somenumber", "referenceid" }) public class myuserresponse { @xmlelement(name = "somenumber") protected string somenumber; @xmlelement(name = "referenceid") protected string referenceid; /** * gets value of somenumber property. * * @return * possible object * {@link string } * */ public string getsomenumber() { return somenumber; } /** * sets value of somenumber property. * * @param value * allowed object * {@link string } * */ public void setsomenumber(string value) { this.somenumber = value; } /** * gets value of referenceid property. * * @return * possible object * {@link string } * */ public string getreferenceid() { return referenceid; } /** * sets value of referenceid property. * * @param value * allowed object * {@link string } * */ public void setreferenceid(string value) { this.referenceid = value; } }
myuserresponses.java file below:
package com.myuser.echannel; import java.util.arraylist; import java.util.list; import javax.xml.bind.annotation.xmlaccesstype; import javax.xml.bind.annotation.xmlaccessortype; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmlrootelement; import javax.xml.bind.annotation.xmltype; /** * <p>java class anonymous complex type. * * <p>the following schema fragment specifies expected content contained within class. * * <pre> * <complextype> * <complexcontent> * <restriction base="{http://www.w3.org/2001/xmlschema}anytype"> * <sequence> * <element name="myuserresponse" type="{http://tempuri.org/}myuserresponse" maxoccurs="unbounded" minoccurs="0"/> * </sequence> * </restriction> * </complexcontent> * </complextype> * </pre> * * */ @xmlaccessortype(xmlaccesstype.field) @xmltype(name = "", proporder = { "myuserresponse" }) @xmlrootelement(name = "myuserresponses") public class myuserresponses { @xmlelement(name = "myuserresponse") protected list<myuserresponse> myuserresponse; /** * gets value of myuserresponse property. * * <p> * accessor method returns reference live list, * not snapshot. therefore modification make * returned list present inside jaxb object. * why there not <code>set</code> method myuserresponse property. * * <p> * example, add new item, follows: * <pre> * getmyuserresponse().add(newitem); * </pre> * * * <p> * objects of following type(s) allowed in list * {@link myuserresponse } * * */ public list<myuserresponse> getmyuserresponse() { if (myuserresponse == null) { myuserresponse = new arraylist<myuserresponse>(); } return this.myuserresponse; } }
object factory:
package com.myuser.echannel; import javax.xml.bind.annotation.xmlregistry; /** * object contains factory methods each * java content interface , java element interface * generated in com.myuser.echannel package. * <p>an objectfactory allows programatically * construct new instances of java representation * xml content. java representation of xml * content can consist of schema derived interfaces * , classes representing binding of schema * type definitions, element declarations , model * groups. factory methods each of these * provided in class. * */ @xmlregistry public class objectfactory { /** * create new objectfactory can used create new instances of schema derived classes package: com.myuser.echannel * */ public objectfactory() { } /** * create instance of {@link myuserresponses } * */ public myuserresponses createmyuserresponses() { return new myuserresponses(); } /** * create instance of {@link myuserresponse } * */ public myuserresponse createmyuserresponse() { return new myuserresponse(); } /** * create instance of {@link myuserrequest } * */ public myuserrequest createmyuserrequest() { return new myuserrequest(); } }
package-info.java file:
@javax.xml.bind.annotation.xmlschema(namespace = "http://tempuri.org/", elementformdefault = javax.xml.bind.annotation.xmlnsform.qualified) package com.myuser.echannel;
i handling soap request request body below spring integration layer(which below web.xml , spring context files):
web.xml:
<servlet> <servlet-name>spring-ws</servlet-name> <servlet-class>org.springframework.ws.transport.http.messagedispatcherservlet</servlet-class> <init-param> <param-name>contextconfiglocation</param-name> <param-value>web-inf/spring-ws-config.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>spring-ws</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
spring-ws-config.xml file:
<context:component-scan base-package="com.nbad.echannel"/> <import resource="classpath:/web-inf/inbound-gateway-config.xml"/> <!-- ensures incoming requests routed ws:inbound-gateway --> <!-- <bean class="org.springframework.ws.server.endpoint.mapping.uriendpointmapping"> <property name="defaultendpoint" ref="ws-inbound-gateway"/> </bean> --> <bean class="org.springframework.ws.server.endpoint.mapping.payloadrootqnameendpointmapping"> <property name="mappings"> <props> <prop key="{http://tempuri.org/}myuserrequest">ws-myuser-gateway</prop> </props> </property> </bean> </beans> <context:component-scan base-package="com.mypackage"/> <import resource="classpath:/com/mypackage/si/jdbc/config/spring-integration-context.xml"/> <int:channel id="ffuserrequestchannel"/> <int-ws:inbound-gateway id="ws-ffuser-gateway" request-channel="ffuserrequestchannel" marshaller="marshaller" unmarshaller="marshaller"/> <bean id="marshaller" class="org.springframework.oxm.jaxb.jaxb2marshaller"> <property name="contextpath" value="com.mypackage.model" /> </bean> <int:service-activator input-channel="myuserrequestchannel"> <bean class="com.mypackage.serviceimpl.myuserimpl"> <constructor-arg ref = "myuserrequest"></constructor-arg> </bean> </int:service-activator> <bean id="myuserrequest" class="com.mypackage.model.myuserrequest"></bean> <bean id="myuserresponse" class="com.mypackage.model.myuserresponse"></bean> </beans>
as above, using jaxb2marshaller marshalling , unmarshalling purpose. serviceimpl file below:
package com.mypackage.serviceimpl; import java.util.arraylist; import java.util.list; import org.springframework.beans.factory.annotation.autowired; import org.springframework.ws.server.endpoint.annotation.payloadroot; import org.springframework.ws.server.endpoint.annotation.requestpayload; import org.springframework.ws.server.endpoint.annotation.responsepayload; import com.mypackage.model.*; import com.mypackage.service.myuser; import com.mypackage.si.jdbc.service.myuserjdbc; /** * @author vinay agrawal */ public class myuserimpl implements myuser{ @autowired myuserrequest request; @autowired myuserjdbc myuserjdbc; public myuserimpl() { } public myuserimpl(myuserrequest request) { super(); this.request = request; } @override @payloadroot(localpart = "issueresponsefor" , namespace = "http://tempuri.org/") @responsepayload public list<myuserresponse>issueresponsefor(@requestpayload myuserrequest request) { list<myuserresponse> myuserresponse = new arraylist<myuserresponse>(); myuserresponse = (list<myuserresponse>)myuserjdbc.getmyuserresponse(request); return myuserresponse; } }
here calling db layer , getting list of myuserresponse(multiple records) db , using spring integration marshaller jaxb2marshaller, expecting marshall java object soap response , should display list in soapui myuserresponse list. getting below error on soap ui , junit:
<soap-env:envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/"> <soap-env:header/> <soap-env:body> <soap-env:fault> <faultcode>soap-env:server</faultcode> <faultstring xml:lang="en">unknown jaxb exception; nested exception javax.xml.bind.jaxbexception: class java.util.arraylist nor of super class known context.</faultstring> </soap-env:fault> </soap-env:body> </soap-env:envelope>
error generated junit:
org.springframework.ws.soap.client.soapfaultclientexception: unknown jaxb exception; nested exception javax.xml.bind.jaxbexception: class java.util.arraylist nor of super class known context. @ org.springframework.ws.soap.client.core.soapfaultmessageresolver.resolvefault(soapfaultmessageresolver.java:37) @ org.springframework.ws.client.core.webservicetemplate.handlefault(webservicetemplate.java:776) @ org.springframework.ws.client.core.webservicetemplate.dosendandreceive(webservicetemplate.java:602) @ org.springframework.ws.client.core.webservicetemplate.sendandreceive(webservicetemplate.java:539) @ org.springframework.ws.client.core.webservicetemplate.dosendandreceive(webservicetemplate.java:494) @ org.springframework.ws.client.core.webservicetemplate.sendsourceandreceivetoresult(webservicetemplate.java:438) @ org.springframework.ws.client.core.webservicetemplate.sendsourceandreceivetoresult(webservicetemplate.java:423) @ com.nbad.echannel.common.incontainertests.testwebservicerequestandresponse(incontainertests.java:44) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43) @ java.lang.reflect.method.invoke(method.java:606) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:47) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:44) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:17) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:271) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:70) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:50) @ org.junit.runners.parentrunner$3.run(parentrunner.java:238) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:63) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:236) @ org.junit.runners.parentrunner.access$000(parentrunner.java:53) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:229) @ org.junit.runners.parentrunner.run(parentrunner.java:309) @ org.eclipse.jdt.internal.junit4.runner.junit4testreference.run(junit4testreference.java:50) @ org.eclipse.jdt.internal.junit.runner.testexecution.run(testexecution.java:38) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:467) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.runtests(remotetestrunner.java:683) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.run(remotetestrunner.java:390) @ org.eclipse.jdt.internal.junit.runner.remotetestrunner.main(remotetestrunner.java:197)
my soap request below:
<soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:sch="http://tempuri.org/"> <soapenv:header/> <soapenv:body> <sch:myuserrequest> <sch:somenumber>8009618916</sch:somenumber> <sch:referenceid>referenceidreferenceid</sch:referenceid> </sch:myuserrequest> </soapenv:body> </soapenv:envelope>
again receive proper response(one record) if changes in xsd file getting single record , corresponding changes in java object file created face issue when try multiple record response.
please me find doing mistake or missing something.
just quote link got:
the above exception occurs because jaxb expects @xmlrootelement annotation on entity, gets marshal. mandatory , can not skipped. @xmlrootelement annotation required meta data root element of xml marshalled java object. arraylist class or java collection class not have jaxb annotations on it. due jaxb unable parse such java objects , raises error.
[solved]: javax.xml.bind.jaxbexception: class java.util.arraylist nor of super class known context
seems myuserresponse
not have @xmlrootelement
annotaion.
Comments
Post a Comment