Web Services class not known in context
teakins Apr 6, 2010 1:08 AMThis is probably a simple one, but I'm stuck. I call a new Web Service, queryByObject, which could return several different objects.
I have the below test case to return a User object. If I change the method signature to return a User, it works. If I leave it as an Object, I get 'javax.xml.bind.JAXBException: class pfcommon.data.User nor any of its super class is known to this context.' Even with the XmlSeeAlso, it just won't add User into the schema.
Any help really appreciated! I put in all the components that I felt were relevant. JBoss 5.1.0.
Also, if there's anything else wrong in my style, happy to take comments, this is my first attempt at expanding my working EJBs to also be Web Services.
Thanks,
Tim
//Interface
@WebService
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
@XmlSeeAlso({pfcommon.data.User.class})
public interface TestConnectionInterface {
...
/**
* Select back one value
*/
@WebMethod
public Object queryForObject(String queryName, HashMap<String, Object> criteria);
...
}
//Remote
@Remote
public interface TestConnectionInterfaceRemote extends TestConnectionInterface { }
//Implementation
@Stateless
@WebService(endpointInterface="pfcommon.ejb.library.connect.TestConnectionInterface")
@XmlSeeAlso({pfcommon.data.User.class})
public class TestConnection implements TestConnectionInterfaceRemote, TestConnectionInterfaceLocal, TestConnectionInterface {
...
@Override
public Object queryForObject(String queryName, HashMap<String, Object> criteria) {
l.info("queryName=" + queryName);
//Simplified sample of something that could happen here
User ret = new User();
l.info("queryForObject ret="+ret);
return ret;
}
...
}
//Client
public void testWebServiceTestConnectionQuery() throws Exception {
boolean successfulTest = true;
String endpointURI = "http://192.168.1.7:8080/PersonalFinancier-PersonalFinancier/TestConnection?wsdl";
try {
URL wsdlURL = new URL(endpointURI);
QName serviceName = new QName("http://connect.ejb.pf/", "TestConnectionService");
Service service = Service.create(wsdlURL, serviceName);
TestConnectionInterface tc = service.getPort(TestConnectionInterface.class);
assertNotNull(tc);
HashMap<String, Object> filterCriteria = new HashMap<String, Object>();
filterCriteria.put("username", "bob");
l.info("Attempting to call dummy queryForObject method");
User ret = (User) tc.queryForObject(PFConsts.SELECT_USER_BY_ACTIVE, filterCriteria);
l.info("User = ["+ret+"]");
} catch (Exception e) {
e.printStackTrace();
successfulTest = false;
}
assertTrue(successfulTest);
}
http://192.168.1.7:8080/jbossws/services
Registered Service Endpoints
Endpoint Name jboss.ws:context=PersonalFinancier-PersonalFinancier,endpoint=TestConnection
Endpoint Address http://192.168.1.7:8080/PersonalFinancier-PersonalFinancier/TestConnection?wsdl
http://192.168.1.7:8080/PersonalFinancier-PersonalFinancier/TestConnection?wsdl
<definitions name="TestConnectionService" targetNamespace="http://connect.ejb.pf/">
<import location="http://192.168.1.7:8080/PersonalFinancier-PersonalFinancier/TestConnection?wsdl&resource=TestConnectionInterface_PortType2174988315873883329.wsdl" namespace="http://connect.library.ejb.pfcommon/"/>
<service name="TestConnectionService">
<port binding="ns1:TestConnectionInterfaceBinding" name="TestConnectionPort">
<soap:address location="http://192.168.1.7:8080/PersonalFinancier-PersonalFinancier/TestConnection"/>
</port>
</service>
</definitions>
//Server Exception
...
00:40:14,236 INFO [EJB3EndpointDeployer] Deploy AbstractBeanMetaData@33435a77{name=jboss.j2ee:ear=PersonalFinancier.ear,jar=PersonalFinancier.jar,name=TestConnection,service=EJB3_endpoint bean=org.jboss.ejb3.endpoint.deployers.impl.EndpointImpl properties=[container] constructor=null autowireCandidate=true}
00:40:14,329 INFO [SessionSpecContainer] Starting jboss.j2ee:ear=PersonalFinancier.ear,jar=PersonalFinancier.jar,name=TestConnection,service=EJB3
00:40:14,329 INFO [EJBContainer] STARTED EJB: pf.ejb.connect.TestConnection ejbName: TestConnection
00:40:14,365 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
PersonalFinancier/TestConnection/remote - EJB3.x Default Remote Business Interface
PersonalFinancier/TestConnection/remote-pfcommon.ejb.library.connect.TestConnectionInterfaceRemote - EJB3.x Remote Business Interface
PersonalFinancier/TestConnection/local - EJB3.x Default Local Business Interface
PersonalFinancier/TestConnection/local-pfcommon.ejb.library.connect.TestConnectionInterfaceLocal - EJB3.x Local Business Interface
...
00:40:14,670 INFO [DefaultEndpointRegistry] register: jboss.ws:context=PersonalFinancier-PersonalFinancier,endpoint=TestConnection
00:40:16,225 INFO [WSDLFilePublisher] WSDL published to: file:/usr/java/jboss-5.1.0.GA-dev/server/pfdev/data/wsdl/PersonalFinancier.ear/PersonalFinancier.jar/TestConnectionService1705653235957235278.wsdl
...
00:40:20,905 WARN [StatelessBeanContext] EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected
00:40:20,905 INFO [STDOUT] Parameter constructor!
00:40:20,905 INFO [TestConnection] Successful basic connection. Now returning value [id=null fieldValue=Remote Simple Test].
00:40:20,905 WARN [StatelessBeanContext] EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected
00:40:26,754 WARN [StatelessBeanContext] EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected
00:40:26,755 INFO [TestConnection] queryName=selectUserByActive
00:40:26,770 INFO [TestConnection] queryForObject ret=
00:40:26,770 WARN [StatelessBeanContext] EJBTHREE-1337: do not get WebServiceContext property from stateless bean context, it should already have been injected
00:40:26,776 ERROR [RequestHandlerImpl] Error processing web service request
org.jboss.ws.WSException: javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[javax.xml.bind.JAXBException: class pfcommon.data.User nor any of its super class is known to this context.]
at org.jboss.ws.WSException.rethrow(WSException.java:68)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleRequest(RequestHandlerImpl.java:336)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.doPost(RequestHandlerImpl.java:205)
at org.jboss.wsf.stack.jbws.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:131)
at org.jboss.wsf.common.servlet.AbstractEndpointServlet.service(AbstractEndpointServlet.java:85)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
...
Thanks again!