2016-12-05 9 views
0

私は石鹸のWebサービスを公開するためにCXF +春を使用していると私はSOAPUI経由で呼び出すとき、私はなぜ今org.apache.cxf.interceptor.Fault

Application {http://art/}VmxServiceImplService#{http://art/}getV has thrown exception, unwinding now 
org.apache.cxf.interceptor.Fault 

を得る巻き戻し、私のCXFとSpring構成throwning例外で私のコードを深く見れば、サービス実装が2回開始していることがわかります。最初はモックを利用でき、2回目はnullと表示されます。最初に、アプリケーションをデプロイして初めて呼び出すときに対応します。この場合、setVmxMockでbreack点が明らかに第二。vmxMockを充填示し、更なるコールがvmxMockヌルを示しています。

私は春のMVCを使用したとき、私は顔をした同様の問題をremenberが、それは全くそうではありません。その場合、web.xmlで変更することで修正しました

<servlet-name>Servlet-plus-any-word</servlet-name> 

不幸にも、CXFServletでは同じ方法が使用できませんでした。

私はContextLoaderListenerをCXFServletから分離するための特定のトリックが欠けていると思いますが、どのように行うのかわかりません。だから、私の真っ向からの質問です:私はCXFと春のセットアップそのような単純なWebサービスのために間違って何をしているのですか?

サービスインタフェース:

import javax.jws.WebMethod; 
import javax.jws.WebService; 

@WebService 
public interface VmxService { 

    @WebMethod 
    public VmxModel getV(); 

} 

サービス実装

//import javax.jws.WebService; 

//@WebService(endpointInterface = "art.VmxService", serviceName = "vmxService") 
public class VmxServiceImpl implements VmxService { 

    private VmxMock vmxMock; 

    public VmxServiceImpl() { 
    } 

    public void setVmxMock(VmxMock m) { 
     this.vmxMock = m; 
    } 

    @Override 
    public VmxModel getV() { 
     return this.vmxMock.getVm(); 
    } 

} 

モデル:

import java.io.Serializable; 
import javax.xml.bind.annotation.XmlRootElement; 

@XmlRootElement(name = "VmxModel") 
public class VmxModel implements Serializable { 

    private static final long serialVersionUID = 1L; 

    private String retorno; 

    public VmxModel() { 
     System.out.println(); 

    } 

    public String getRetorno() { 
     return retorno; 
    } 

    public void setRetorno(String s) { 
     retorno = s; 
    } 
} 

モック

public class VmxMock { 

    VmxModel vm = new VmxModel(); 

    public VmxMock(){ 
     this.vm.setRetorno("retorno"); 
    } 

    public VmxModel getVm(){ 
     return vm; 
    } 

} 

春-beans.xmlの

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

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" 
    xsi:schemaLocation=" 
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> 


    <import resource="classpath:META-INF/cxf/cxf.xml" /> 

    <bean id="vmxMock" class="art.VmxMock" /> 

    <bean id="vmxServiceImpl" class="art.VmxServiceImpl"> 
     <property name="vmxMock"> 
      <ref bean="vmxMock" /> 
     </property> 
    </bean> 

    <jaxws:endpoint id="vmxService" implementor="art.VmxServiceImpl" 
     address="/VmxService" /> 

</beans> 

web.xmlの(おそらくエラーの根本的な原因はここにある)

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    id="WebApp_ID" version="3.0"> 
    <display-name>art</display-name> 

    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>classpath:spring-beans.xml</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <servlet> 
     <description>CXF Servlet</description> 
     <servlet-name>CXFServlet</servlet-name> 
     <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>CXFServlet</servlet-name> 
     <url-pattern>/*</url-pattern> 
    </servlet-mapping> 
</web-app> 

ポンポン:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>grp</groupId> 
    <artifactId>art</artifactId> 
    <packaging>war</packaging> 

    <version>0.0.1-SNAPSHOT</version> 
    <name>art Maven Webapp</name> 
    <url>http://maven.apache.org</url> 
    <properties> 
     <jdk.version>1.8</jdk.version> 
     <cxf.version>3.1.8</cxf.version> 
     <spring.version>4.3.4.RELEASE</spring.version> 
     <!-- <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> --> 
    </properties> 

    <dependencies> 
     <!-- Spring dependencies --> 
     <dependency> 
      <groupId>org.springframework</groupId> 
      <artifactId>spring-web</artifactId> 
      <version>${spring.version}</version> 
     </dependency> 
     <!-- Apache cxf dependencies --> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-frontend-jaxws</artifactId> 
      <version>${cxf.version}</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.cxf</groupId> 
      <artifactId>cxf-rt-transports-http</artifactId> 
      <version>${cxf.version}</version> 
     </dependency> 
     <!-- servlet & jsp --> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>javax.servlet-api</artifactId> 
      <version>3.0.1</version> 
      <scope>provided</scope> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet.jsp</groupId> 
      <artifactId>javax.servlet.jsp-api</artifactId> 
      <version>2.3.1</version> 
     </dependency> 
     <dependency> 
      <groupId>javax.servlet</groupId> 
      <artifactId>jstl</artifactId> 
      <version>1.1.2</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <finalName>art</finalName> 
     <!-- <pluginManagement> --> 

      <plugins> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-compiler-plugin</artifactId> 
        <version>3.2</version> 
        <configuration> 
         <source>${jdk.version}</source> 
         <target>${jdk.version}</target> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.cxf</groupId> 
        <artifactId>cxf-java2ws-plugin</artifactId> 
        <version>${cxf.version}</version> 
        <executions> 
         <execution> 
          <id>process-classes</id> 
          <phase>process-classes</phase> 
          <configuration> 

           <className>art.VmxService</className> 

           <outputFile>${project.basedir}/src/main/resources/VmxService.wsdl</outputFile> 
           <genWsdl>true</genWsdl> 
           <verbose>true</verbose> 

           <address>http://localhost:9080/art/VmxService</address> 
          </configuration> 
          <goals> 
           <goal>java2ws</goal> 
          </goals> 
         </execution> 
        </executions> 
       </plugin> 

      </plugins> 
<!--  </pluginManagement> --> 
    </build> 
</project> 

のWebSphereリバティプロファイルのコンソールエラー

[05/12/16 19:09:22:593 BRST] 00000172 org.apache.cxf.phase.PhaseInterceptorChain     W Application {http://art/}VmxServiceImplService#{http://art/}getV has thrown exception, unwinding now 
org.apache.cxf.interceptor.Fault 
    at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162) 
    at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:267) 
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128) 
    at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:232) 
    at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:85) 
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:74) 
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:59) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor$2.run(ServiceInvokerInterceptor.java:126) 
    at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37) 
    at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:131) 
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:308) 
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121) 
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:252) 
    at org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:234) 
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:208) 
    at org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:160) 
    at org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:180) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:299) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:218) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) 
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:274) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1290) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:778) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:475) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1161) 
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:82) 
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:938) 
    at com.ibm.ws.webcontainer.osgi.DynamicVirtualHost$2.run(DynamicVirtualHost.java:278) 
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink$TaskWrapper.run(HttpDispatcherLink.java:967) 
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.wrapHandlerAndExecute(HttpDispatcherLink.java:359) 
    at com.ibm.ws.http.dispatcher.internal.channel.HttpDispatcherLink.ready(HttpDispatcherLink.java:318) 
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:471) 
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.handleNewRequest(HttpInboundLink.java:405) 
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.processRequest(HttpInboundLink.java:285) 
    at com.ibm.ws.http.channel.internal.inbound.HttpInboundLink.ready(HttpInboundLink.java:256) 
    at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:174) 
    at com.ibm.ws.tcpchannel.internal.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:83) 
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.requestComplete(WorkQueueManager.java:504) 
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.attemptIO(WorkQueueManager.java:574) 
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager.workerRun(WorkQueueManager.java:929) 
    at com.ibm.ws.tcpchannel.internal.WorkQueueManager$Worker.run(WorkQueueManager.java:1018) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.NullPointerException 
    at art.VmxServiceImpl.getV(VmxServiceImpl.java:25) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:498) 
    at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180) 
    at org.apache.cxf.jaxws.JAXWSMethodInvoker.performInvocation(JAXWSMethodInvoker.java:66) 
    at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) 
    ... 43 more 

答えて

0
<jaxws:endpoint id="vmxService" implementor="#vmxServiceImpl" address="/VmxService" /> 

と変更

<jaxws:endpoint id="vmxService" implementor="art.VmxServiceImpl" address="/VmxService" /> 

あなたは、クラス名ではなく、参照を提供しています。 JAX-WS configurationimplementor属性の説明を参照してください。

JAXWSエンドポイントの実装。 JAX-WSエンドポイントを起動するときは、このので

「#REF_BEAN_NAME」の形式で

をここで実装クラス名、または単に参照のBean名を指定することができ、CXFは art.VmxServiceImplの新しいインスタンスを作成しています。この新しいインスタンスで vmxMockはnullで、

return this.vmxMock.getVm(); 

は、あなたのスタックトレース

Caused by: java.lang.NullPointerException 
    at art.VmxServiceImpl.getV(VmxServiceImpl.java:25) 
+0

PedroFB、感謝の主要なエラーが発生します。問題を修正しました。あなたが気にしなければ最後のコメンテントは、あなたがSoap Servicesだけを持つプロジェクトのためにSpringとCXFの両方を選ぶという方向に向かっていると思いますか?私は、CXFまたはSpringのみで同じ石鹸サービスを作成できることがわかります。 – DemeCarvO

+0

春は邪魔ではありません。 CXFは春を使わずに使うことができますが、設定や使い方は簡単です。実際、デフォルト実装がJVMに同梱されているため、CXFではなくSpringを使用せずにJAX-WSを使用することができます。 Spring-WSはJAX-WSと同じではありません。 「Spring Web Servicesは、契約最初のSOAPサービス開発を容易にすることを目指しています。私の場合は、Spring + CXFのJAX-WSプロジェクトがいくつかあります – pedrofb

関連する問題