我有一个JEE6应用程序,带有一个ejb和一个web模块,在GlassFish 3.1.1上运行 现在我想通过将它(作为会话Bean)注入几个托管Bean来访问WebService(JAX-WS)。
@Stateless
public class AnyService implements AnyServiceLocal {
@WebServiceRef(wsdlLocation = "META-INF/wsdl/AnyService/Any.wsdl")
private AnyService service;
@Override
public String findLastname(Integer key) {
Any port = service.getAnyPort();
AnyPerson sp = port.findAnynumber(key);
return sp.getLastname();
}
}
当我尝试访问它时:
@ManagedBean
@SessionScoped
public class UserBean {
@EJB
private AnyServiceLocal any;
public void findLastname() {
name = any.findLastname(Integer.valueOf(key));
}
}
我会得到这些例外
WARNUNG: A system exception occurred during an invocation on EJB AnyService method public java.lang.String de.mizui.anytest.ejb.bean.AnyService.findLastname(java.lang.Integer)
javax.ejb.EJBException
at com.sun.ejb.containers.BaseContainer.processSystemException(BaseContainer.java:5193)
at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5091)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4879)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2039)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1990)
at com.sun.ejb.containers.EJBObjectInvocationHandler.invoke(EJBObjectInvocationHandler.java:213)
at com.sun.ejb.containers.EJBObjectInvocationHandlerDelegate.invoke(EJBObjectInvocationHandlerDelegate.java:79)
at $Proxy430.findLastname(Unknown Source)
..blabla..
Caused by: javax.xml.ws.soap.SOAPFaultException: java.lang.NullPointerException
at com.sun.xml.ws.fault.SOAP11Fault.getProtocolException(SOAP11Fault.java:193)
at com.sun.xml.ws.fault.SOAPFaultBuilder.createException(SOAPFaultBuilder.java:134)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:123)
at com.sun.xml.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:93)
at com.sun.xml.ws.client.sei.SEIStub.invoke(SEIStub.java:144)
at $Proxy431.findEmployeenumber(Unknown Source)
at de.mizui.anytest.ejb.bean.AnyService.findLastname(AnyService.java:25)
..blabla..
Caused by: javax.xml.ws.WebServiceException: java.lang.NullPointerException
at com.sun.enterprise.security.jmac.provider.config.PipeHelper.makeFaultResponse(PipeHelper.java:321)
..blabla..
Caused by: java.lang.NullPointerException
at com.sun.xml.ws.tx.coordinator.CoordinationManager.lookupOrCreateCoordinator(CoordinationManager.java:175)
(somewhat shortened..)
但是当我直接从UserBean中访问WS时,它可以工作.. 期待您的想法:)
*我的第一篇文章^^
答案 0 :(得分:2)
我有解决方案! Webservices的事务必须是原子的,就像依赖注入一样。但是它试图将请求嵌入到注入事务中(hihi this rhymes),所以它不再是原子的。 您可以使用注释绕过特定方法:
@Stateless
@LocalBean
public class AnyServices{
@WebServiceRef(wsdlLocation = "META-INF/wsdl/AnyService/Any.wsdl")
private AnyService service;
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public String findLastname(Integer key) {
Any port = service.getAnyPort();
AnyPerson sp = port.findAnynumber(key);
return sp.getLastname();
}
}
< 3