本文介绍了JAX-WS和CDI无法在WAS Liberty Profile 8.5.5.6上一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试结合JAX-WS Web服务端点类和简单的CDI注入时,我遇到奇怪的行为。当我尝试将对象注入WebService实现类时,永远不会调用注入对象的PostConstruct方法。确实没有调用类的构造函数。

I am experiencing strange behavior when I attempt to combine a JAX-WS web service endpoint class and a simple CDI injection. When I try to inject the object into the WebService implementation class, the injected object's PostConstruct method is never called. Indeed the classes constructor is not called either.

这是我的JAX-WS实现类和注入点:

Here is my JAX-WS implementation class and the injection point:

@WebService(serviceName="eBusinessWebService")
public class eBusinessWebServiceImpl
{

    @WebMethod
    public SubmissionValidationResults xmlValidation(String xml, String submissionType, String schemaVersion)
            throws SOAPException
    {
        // Validate schema
        SubmissionValidationResults results = fileSubmissionServiceHandler.validateXML(xml, submissionType,
                schemaVersion);

        return results;
    }

    @Inject
    private FileSubmissionServiceHandler fileSubmissionServiceHandler;

    @Inject
    private BRSubmissionService brSubmissionService;
}

这是我注入的类FileSubmissionServiceHandler:

And here is my injected class, the FileSubmissionServiceHandler:

public class FileSubmissionServiceHandler
{
    public FileSubmissionServiceHandler()
    {
        System.out.println("Constructor being called on FileSubmissionServiceHandler");
    }

    @PostConstruct
    public void init()
    {
        final String webserviceURL = "https://hostname/FileSubmissionService/FileSubmissionService.svc";
        final String username = "username";
        final String password = "password";

        this.webservice = new BasicHttpsBinding_IFileSubmissionServiceProxy(username, password);
        Descriptor desc = webservice._getDescriptor();
        desc.setEndpoint(webserviceURL);
    }

    public SubmissionValidationResults validateXML(String xml, String submissionType,
            String schemaVersion) throws WebServiceException
    {
        SubmissionValidationResults results = null;
        FormType type = FormType.getByName(submissionType);
        String submissionTypeCode = type.getCode();

        try
        {
            results = this.webservice.validateXmlFile(xml, submissionTypeCode, schemaVersion);

        }
        catch (Exception e)
        {
            logger.error("Internal FileSubmissionService threw an exception", e);
            throw e;
        }

        return convertSubmissionValidationResults(results);
    }

    private BasicHttpsBinding_IFileSubmissionServiceProxy webservice;
}

我被要求发布服务器XML(由于Liberty配置文件有两个副本,所以覆盖了端口设置一次运行):

I was asked to post my server XML (overriding port settings due to two copies of the Liberty profile running at one time):

<server description="new server">

<!-- Enable features -->
<featureManager>
    <feature>jaxws-2.2</feature>
    <feature>servlet-3.1</feature>
    <feature>cdi-1.2</feature>
</featureManager>

<!--For a user registry configuration, configure your user registry. For
    example, configure a basic user registry using the basicRegistry element.
    Specify your own user name below in the name attribute of the user element.
    For the password, generate an encoded password using bin/securityUtility
    encode and add it in the password attribute of the user element. Then uncomment
    the user element. -->
<basicRegistry id="basic" realm="BasicRealm">
    <user name="wasadmin" password="{xor}KD4sPjsyNjE=" />
</basicRegistry>

<keyStore password="{xor}KD4sPjsyNjE=" />

<!-- To access this server from a remote client add a host attribute to
    the following element, e.g. host="*" -->
<httpEndpoint host="*" httpPort="9090" httpsPort="9445"
    id="defaultHttpEndpoint" />

<wasJmsEndpoint wasJmsPort="7277" wasJmsSSLPort="7287" />

<iiopEndpoint host="localhost" id="defaultIiopEndpoint"
    iiopPort="2814">
    <iiopsOptions iiopsPort="2815" />
</iiopEndpoint>

<applicationMonitor updateTrigger="mbean" />

<enterpriseApplication id="eBusinessWebService_EAR"
    location="eBusinessWebService_EAR.ear" name="eBusinessWebService_EAR" />

和日志:

Launching defaultServer (WebSphere Application Server 8.5.5.6/wlp-1.0.9.cl50620150610-1749) on Java HotSpot(TM) 64-Bit Server VM, version 1.7.0_79-b15 (en_US)
[AUDIT   ] CWWKE0001I: The server defaultServer has been launched.
[AUDIT   ] CWWKE0100I: This product is licensed for development, and limited production use. The full license terms can be viewed here: https://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/license/base_ilan/ilan/8.5.5.6/lafiles/en.html
[AUDIT   ] CWWKZ0058I: Monitoring dropins for applications.
[WARNING ] CWNEN0047W: Resource annotations on the fields of the xxx.important.not.external.service.eBusinessWebServiceImpl class will be ignored. The annotations could not be obtained because of the exception : java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContextAware
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9090/eBusinessWebService/
[AUDIT   ] CWWKZ0001I: Application eBusinessWebService_EAR started in 3.011 seconds.
[AUDIT   ] CWWKF0012I: The server installed the following features: [jaxws-2.2, cdi-1.2, servlet-3.1, jndi-1.0, javaMail-1.5, jaxb-2.2].
[AUDIT   ] CWWKF0011I: The server defaultServer is ready to run a smarter planet.
20-01-2016 - 10:02:47 - INFO  (eBusinessWebServiceImpl.java:31) - --- Validating Incomming Form XML ---
20-01-2016 - 10:02:47 - INFO  (eBusinessWebServiceImpl.java:33) - Received Payload: XML [Hello]
20-01-2016 - 10:02:47 - INFO  (eBusinessWebServiceImpl.java:34) - SubmissionType [from the]
20-01-2016 - 10:02:47 - INFO  (eBusinessWebServiceImpl.java:35) - SchemaVersion [other side]
[WARNING ] Application {http://service.external.not.important.xxx/}eBusinessWebService#{http://service.external.not.important.xxx/}xmlValidation has thrown exception, unwinding now
java.lang.NullPointerException

我已经编辑了每个类的一些不太相关的细节,但是基本操作是相同的。当我尝试访问 validateXML时, fileSubmissionServiceHandler对象的方法,将引发空指针异常,而且我从没看到FileSubmissionServiceHandler类中postConstruct或构造方法的输出。

I have redacted some of the less relevant details of each class, but the basic operations are the same. When I attempt to access the "validateXML" method of the fileSubmissionServiceHandler object, a null pointer exception is thrown, and I never see the output from the postConstruct or constructor methods in my FileSubmissionServiceHandler class. Using the debugger, these methods are never reached.

到目前为止,我已经检查过的东西:

Things I have checked so far:


  1. 我有一个空的我的WEB-INF文件夹中的beans.xml文件

  2. 我在server.xml中包括了javaee-7.0功能,其中包括jax-ws和cdi

  3. 我还尝试将应用程序范围和请求范围都添加到FileSubmissionServiceHandler中,而没有任何效果。

有人对为什么这样做不起作用有任何想法吗?

Does anyone have any ideas why this would not work?

推荐答案

好,我终于找到了问题的原因。

Ok, I've finally isolated the cause of the problem.

名为BRSubmissionService的对象正在由CDI加载。 Spring异常中断了CDI加载。而且由于CDI无法完成,因此不会发生其余的CDI注入,并且不会加载我的FileSubmissionService对象,从而导致我的空指针异常。

The object called BRSubmissionService is being loaded by CDI. CDI loading is being interrupted by the spring exception. And because CDI is not able to complete, the remaining CDI injections do not occur and my FileSubmissionService object is not loaded, causing my null pointer exception.

解决方案是修复位于另一个jar中的BRSubmissionService对象内部的spring错误,很不幸,我是从另一个开发人员继承的。这就是生活。

The solution is to fix the spring error inside the BRSubmissionService object which is located in another jar, that unfortunately I've inherited from another developer. Such is the life.

这篇关于JAX-WS和CDI无法在WAS Liberty Profile 8.5.5.6上一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 23:08