当前位置: 代码迷 >> Java相关 >> CXF测试报错(java.net.MalformedURLException: Invalid address. Endpoint address canno),该如何处理
  详细解决方案

CXF测试报错(java.net.MalformedURLException: Invalid address. Endpoint address canno),该如何处理

热度:11019   发布时间:2013-02-25 21:48:19.0
CXF测试报错(java.net.MalformedURLException: Invalid address. Endpoint address canno)
警告: Interceptor for {http://iface.service.cxf.com/}Helloworld#{http://iface.service.cxf.com/}sayHello has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:48)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
at $Proxy33.sayHello(Unknown Source)
at com.cxf.client.HelloWorldClient.main(HelloWorldClient.java:25)
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:871)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:853)
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:799)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:547)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
... 8 more
Exception in thread "main" javax.xml.ws.WebServiceException: Could not send Message.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:135)
at $Proxy33.sayHello(Unknown Source)
at com.cxf.client.HelloWorldClient.main(HelloWorldClient.java:25)
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:871)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:853)
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:799)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:547)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:255)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:516)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:313)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:265)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
... 2 more
代码如下:
接口HelloWorld:
Java code
package com.cxf.service.iface;import javax.jws.WebParam;import javax.jws.WebService;@WebServicepublic interface HelloWorld {    public String sayHello(@WebParam(name="text") String text);  }

实现HelloWorldImpl:
Java code
package com.cxf.service.impl;import javax.jws.WebService;import com.cxf.service.iface.HelloWorld;@WebService(serviceName="Helloworld")public class HelloWorldImpl implements HelloWorld {    public String sayHello(String text) {        return "hello " + text;    }}

服务端HelloWorldService:
Java code
package com.cxf.service.app;import javax.xml.ws.Endpoint;import com.cxf.service.iface.HelloWorld;import com.cxf.service.impl.HelloWorldImpl;public class HelloWorldService {    /**     * @param args     */    public static void main(String[] args) throws Exception {        HelloWorld hello = new HelloWorldImpl();        String address = "http://localhost:8080/MyService";        Endpoint.publish(address, hello);        System.out.println("服务已发布......");        }}
  相关解决方案