2013-12-19 33 views
3

應用程序使用JAX-WS 2.2.1版本,其中發現了處理CustomException的問題。由於com.sun.xml.internal.bind.v2.runtime.IllegalAnnotationsException而無法生成類:1個IllegalAnnotationExceptions計數。所以我將JAX WS的版本更改爲JAX-WS 2.2.8,解決了上述問題(創建了CustomExceptions的類)。但現在我在嘗試使用該服務時遇到以下錯誤:將JAX-WS版本2.2.1升級到2.2.8後的NPE

Dec 20, 2013 2:42:42 AM com.sun.xml.ws.server.sei.TieHandler createResponse 
SEVERE: null 
java.lang.NullPointerException 
    at server.service.SampleServiceEndpoint.getItems(SampleServiceEndpoint.java:14) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:250) 
    at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:149) 
    at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:88) 
    at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:1136) 
    at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:1050) 
    at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:1019) 
    at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:877) 
    at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:420) 
    at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:687) 
    at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:266) 
    at com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:225) 
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:161) 
    at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:197) 
    at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:81) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) 
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) 
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) 
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) 
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023) 
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) 
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1852) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:722) 

以下是我的自定義異常類和Fault bean。

public class ConcurrencyException extends Exception { 
private ConcurrencyInfoBean faultInfo; 

    public ConcurrencyException(String message, ConcurrencyInfoBean faultInfo) { 
     super(message); 
     this.faultInfo = faultInfo; 
    } 

    public ConcurrencyException(String message, ConcurrencyInfoBean faultInfo, Throwable cause) { 
     super(message, cause); 
     this.faultInfo = faultInfo; 
    } 

    public ConcurrencyInfoBean getFaultInfo() { 
     return faultInfo; 
    } 
} 

public class ConcurrencyInfoBean { 
protected String message; 

    public ConcurrencyInfoBean() {} 

    public String getMessage() { 
     return message; 
    } 

    public void setMessage(String value) { 
     this.message = value; 
    } 
} 

對於那些以下類,其中產生的:

package client.service.jaxws; 

import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlType; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name="ConcurrencyException", propOrder={"faultInfo", "message"}) 
public class ConcurrencyException 
{ 
    protected ConcurrencyInfoBean faultInfo; 
    protected String message; 

    public ConcurrencyInfoBean getFaultInfo() 
    { 
    return this.faultInfo; 
    } 

    public void setFaultInfo(ConcurrencyInfoBean paramConcurrencyInfoBean) 
    { 
    this.faultInfo = paramConcurrencyInfoBean; 
    } 

    public String getMessage() 
    { 
    return this.message; 
    } 

    public void setMessage(String paramString) 
    { 
    this.message = paramString; 
    } 
} 

package client.service.jaxws; 

import javax.xml.ws.WebFault; 

@WebFault(name="ConcurrencyException", targetNamespace="http://service.server/") 
public class ConcurrencyException_Exception extends Exception 
{ 
    private ConcurrencyException faultInfo; 

    public ConcurrencyException_Exception(String paramString, ConcurrencyException paramConcurrencyException) 
    { 
    super(paramString); 
    this.faultInfo = paramConcurrencyException; 
    } 

    public ConcurrencyException_Exception(String paramString, ConcurrencyException paramConcurrencyException, Throwable paramThrowable) 
    { 
    super(paramString, paramThrowable); 
    this.faultInfo = paramConcurrencyException; 
    } 

    public ConcurrencyException getFaultInfo() 
    { 
    return this.faultInfo; 
    } 
} 

package client.service.jaxws; 

import javax.xml.bind.annotation.XmlAccessType; 
import javax.xml.bind.annotation.XmlAccessorType; 
import javax.xml.bind.annotation.XmlType; 

@XmlAccessorType(XmlAccessType.FIELD) 
@XmlType(name="concurrencyInfoBean", propOrder={"message"}) 
public class ConcurrencyInfoBean 
{ 
    protected String message; 

    public String getMessage() 
    { 
    return this.message; 
    } 

    public void setMessage(String paramString) 
    { 
    this.message = paramString; 
    } 
} 

在這之後我得到的Web服務端點類NPE:

@MTOM 
@WebService(name = "sampleService") 
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED) 
public class SampleServiceEndpoint extends SpringBeanAutowiringSupport { 

    @Autowired 
    LookupService lookupService; 

    @Autowired 
    PersistenceService persistenceService; 

    @WebMethod 
    public List<Items> getItems() { 
     return lookupService.getItems(); // Throws NPE 
    } 

    @WebMethod 
    public long updateItem(@WebParam(name = "item") Item item) throws ConcurrencyException{ 
     return persistenceService.updateItem(item); 
    } 

    @XmlMimeType("application/octet-stream") 
    @WebMethod 
    public DataHandler downloadFaxFile(String filename){ 
     return new DataHandler(new FileDataSource(filename)); 
    } 
} 

請求細節使用招捕獲:(請注意爲User-Agent提到的版本:JAX-WS RI 2.2.4-b01,但實際上我在服務器中使用2.2.8。)

POST http://172.16.1.17:8080/sample-server/sampleService HTTP/1.1 
Accept: text/xml, multipart/related 
Content-Type: multipart/related;start="<rootpart*[email protected]>";type="application/xop+xml";boundary="uuid:c42f6a20-3467-47db-9f42-2fd710e98a91";start-info="text/xml" 
SOAPAction: "http://service.server/sampleService/getItemsRequest" 
User-Agent: JAX-WS RI 2.2.4-b01 
Host: 172.16.1.17:8080 
Connection: keep-alive 
Content-Length: 461 
Connection: close 

--uuid:c42f6a20-3467-47db-9f42-2fd710e98a91 
Content-Id: <rootpart*[email protected]> 
Content-Type: application/xop+xml;charset=utf-8;type="text/xml" 
Content-Transfer-Encoding: binary 

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getItems xmlns:ns2="http://service.server/"></ns2:getItems></S:Body></S:Envelope> 
--uuid:c42f6a20-3467-47db-9f42-2fd710e98a91-- 

使用招捕獲的響應:

HTTP/1.1 500 Internal Server Error 
Server: Apache-Coyote/1.1 
Content-Type: multipart/related; start="<rootpart*[email protected]>"; type="application/xop+xml"; boundary="uuid:fd6818ff-12f2-490b-b0fe-7d99e1196491"; start-info="text/xml" 
Transfer-Encoding: chunked 
Date: Sat, 21 Dec 2013 08:30:25 GMT 
Connection: close 

154 
--uuid:fd6818ff-12f2-490b-b0fe-7d99e1196491 
Content-Id: <rootpart*[email protected]> 
Content-Type: application/xop+xml;charset=utf-8;type="text/xml" 
Content-Transfer-Encoding: binary 

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body> 
b5 
<S:Fault xmlns:ns4="http://www.w3.org/2003/05/soap-envelope"><faultcode>S:Server</faultcode><faultstring>java.lang.NullPointerException</faultstring></S:Fault></S:Body></S:Envelope> 
2f 

--uuid:fd6818ff-12f2-490b-b0fe-7d99e1196491-- 
0 

Spring配置文件: 1. applicationContext.xml中

<?xml version="1.0" encoding="UTF-8"?> 

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
     http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
     http://www.springframework.org/schema/context 
     http://www.springframework.org/schema/context/spring-context-3.0.xsd 
     http://www.springframework.org/schema/mvc 
     http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 

    <context:component-scan base-package="server"/> 

    <import resource="datasource.xml"/> 
    <import resource="services.xml"/> 

</beans> 
  1. 的services.xml

    <?xml version="1.0" encoding="UTF-8"?> 
    <beans xmlns="http://www.springframework.org/schema/beans" 
        xmlns:mvc="http://www.springframework.org/schema/mvc" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xmlns:context="http://www.springframework.org/schema/context" 
        xsi:schemaLocation=" 
        http://www.springframework.org/schema/beans 
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
        http://www.springframework.org/schema/context 
        http://www.springframework.org/schema/context/spring-context-3.0.xsd 
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"> 
    
    <bean id="lookupService" class="server.service.LookupServiceImpl"> 
        <property name="statusDAO" ref="statusDAO"/> 
        <property name="utilDAO" ref="utilDAO"/> 
        <property name="logDAO" ref="logDAO"/> 
        <property name="faxHistoryDAO" ref="faxHistoryDAO"/> 
    </bean> 
    
    <bean id="persistenceService" class="server.service.PersistenceServiceImpl"> 
        <property name="logDAO" ref="logDAO"/> 
        <property name="faxHistoryDAO" ref="faxHistoryDAO"/> 
    </bean> 
    
    <bean id="adminService" class="server.service.AdminServiceImpl"> 
        <property name="userDAO" ref="userDAO"/> 
    </bean> 
    
    <bean id="reportService" class="server.service.ReportServiceImpl"> 
        <property name="reportDAO" ref="reportDAO"/> 
    </bean> 
    

的環境細節: jdk1.7.0_21,tomcat的7,Windows 7的

+0

你得到了什麼NPE? –

+1

@BlaiseDoughan我更新了問題的例外情況 – Leejoy

+1

看起來像'lookupService'沒有被注入。我認爲'@ Autowired'是Spring的一個東西,而且你在其他DI框架中注入了不同的註釋。而且你爲什麼要用'... Impl'類型注入某些東西? –

回答

1

我可以修改我的web服務端點類避免了NPE,但不那麼肯定了以下解決方案是否是最佳與否,但它適用於我:

@MTOM 
@WebService(name = "sampleService") 
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle=ParameterStyle.WRAPPED) 
public class SampleServiceEndpoint extends SpringBeanAutowiringSupport { 

    @Autowired 
    LookupService lookupService; 

    @Autowired 
    PersistenceService persistenceService; 

    @WebMethod(exclude=true) 
    private void initLookupService(){ 
     if(lookupService == null) 
      processInjectionBasedOnCurrentContext(this); 
    } 

    @WebMethod(exclude=true) 
    private void initPersistenceService(){ 
     if(persistenceService == null) 
      processInjectionBasedOnCurrentContext(this); 
    } 

    @WebMethod 
    public List<Items> getItems() { 
     initLookupService(); 
     return lookupService.getItems(); 
    } 

    @WebMethod 
    public long updateItem(@WebParam(name = "item") Item item) throws ConcurrencyException{ 
     initPersistenceService() 
     return persistenceService.updateItem(item); 
    } 

    @XmlMimeType("application/octet-stream") 
    @WebMethod 
    public DataHandler downloadFaxFile(String filename){ 
     return new DataHandler(new FileDataSource(filename)); 
    } 
}