1

我有一个 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 时,它就可以工作了。期待您的想法 :)

*耶,我的第一篇文章^^

4

1 回答 1

3

我有解决办法!与 Web 服务的事务必须是原子的,例如依赖注入。但它试图将请求嵌套到注入事务中(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

于 2012-07-06T07:48:08.133 回答