Search code examples
springjax-ws

Could not access remote service at [null], spring integrate with jax-ws issue


I want to integrate spring with jax-ws, so i simulate the server side and client side, both are based on spring-framework, the server side expose the service used by client, the server side configuration as below:

web.xml

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

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

applicationContext.xml

<bean class="org.springframework.remoting.jaxws.SimpleJaxWsServiceExporter">
    <property name="baseAddress" value="http://localhost:8888/services/" />
</bean>

CommonServiceImpl.java

@WebService(serviceName = "CommonService")
@Service
public class CommonServiceImpl implements ICommonService {
    @Override
    @WebMethod
    public void sayHello() {
        System.out.println("hello");
    }
}

the client side configuration as below:

web.xml same as the server.

applicationContext.xml

<bean id="service"
        class="org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean">
        <property name="wsdlDocumentUrl"
            value="http://localhost:8888/services/CommonService?wsdl" />
        <property name="serviceInterface" value="com.my.service.ICommonService" />
        <property name="serviceName" value="CommonService" />
        <property name="namespaceUri" value="http://impl.service.my.com/" />
        <property name="portName" value="CommonServiceImplPort" />
</bean>

the test class: AbstractIntegrationTest.java

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:spring/applicationContext.xml")
public abstract class AbstractIntegrationTest extends
        AbstractJUnit4SpringContextTests {

}

IntegrationTest.java

public class IntegrationTest extends AbstractIntegrationTest {

    @Resource
    private ICommonService service;

    @Test
    public void test() {
        service.sayHello();
    }
}

I deploy the server side in tomcat 7 and the server side startup work well, but when i run the junit test in client, the console print as below:

org.springframework.remoting.RemoteAccessException: Could not access remote service at [null]; nested exception is javax.xml.ws.WebServiceException: Could not find wsdl:binding operation info for web method sayHello.
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:565)
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.invoke(JaxWsPortClientInterceptor.java:541)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
    at com.sun.proxy.$Proxy25.sayHello(Unknown Source)
    at com.my.junit.test.action.IntegrationTest.test(IntegrationTest.java:17)
    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:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:72)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:81)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:216)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:82)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:60)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:67)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:162)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: javax.xml.ws.WebServiceException: Could not find wsdl:binding operation info for web method sayHello.
    at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:126)
    at com.sun.proxy.$Proxy24.sayHello(Unknown Source)
    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:483)
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:580)
    at org.springframework.remoting.jaxws.JaxWsPortClientInterceptor.doInvoke(JaxWsPortClientInterceptor.java:554)
    ... 34 more

Do i miss any configuration or something wrong? I have been search in google for a long time. Can somebody help? Thanks in advance.


Solution

  • I reviewed the code again, i found i missed the attr "endpointInterface" in @WebService, such as

    @WebService(serviceName = "CommonService", endpointInterface = "com.my.service.ICommonService")
    @Service
    public class CommonServiceImpl implements ICommonService {
    
        @Override
        @WebMethod
        public String sayHello() {
            return "This is the message from web service";
        }
    }
    

    I added it and the client work well.