`
away888
  • 浏览: 27334 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

cxf QNAME PORT_NAME 的教訓

阅读更多
[color=brown]警告: Interceptor for {http://server.hw.demo/}HelloWorld#{http://client.webserver.com/}sayHi 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:243)
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 $Proxy35.sayHi(Unknown Source)
at com.webserver.client.Client.main(Client.java:49)
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:890)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:872)
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:798)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:546)
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 $Proxy35.sayHi(Unknown Source)
at com.webserver.client.Client.main(Client.java:49)
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:890)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:872)
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:798)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:546)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:243)
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
[/color]
關於這個錯誤,本人被困惑了兩天,特別浪費了星期天保貴的休息日。剛才,認真下來分析,嘗試,鈡於被我蒙到了。

在查看網上的相關的信息後,一直以為QNAME與PORT_NAME是targetNamespace的值,並沒有想到是客戶端的接口類包名,如本例中的接口包名“com.webserver.client”.
(本人的服務端與客戶端分屬不同的項目)
所以,記住QNAME與POR_NAME是客戶端的接口類的包名倒寫。

WSDL信息
<wsdl:definitions name="HelloWorld" targetNamespace="http://server.hw.demo/"><wsdl:types><xsd:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://server.hw.demo/"><xsd:element name="sayHi" type="tns:sayHi"/><xsd:complexType name="sayHi"><xsd:sequence><xsd:element minOccurs="0" name="arg0" type="xsd:string"/></xsd:sequence></xsd:complexType><xsd:element name="sayHiResponse" type="tns:sayHiResponse"/><xsd:complexType name="sayHiResponse"><xsd:sequence><xsd:element minOccurs="0" name="return" type="xsd:string"/>
、、、、、、、、、、



正常運行的代碼

package com.webserver.client;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;


public final class Client {

    private static final QName SERVICE_NAME 
        = new QName("http://client.webserver.com/", "HelloWorld");
    private static final QName PORT_NAME 
        = new QName("http://client.webserver.com/", "HelloWorldPort");
          //正確的寫法 ,與本地HelloWorld.java接口包名關聯。
 
    private Client() {
    } 

    public static void main(String args[]) throws Exception {
        Service service = Service.create(SERVICE_NAME);
        // Endpoint Address
        String endpointAddress = "http://localhost:8080/first_jaxws/services/HelloWorld?wsdl";

        // Add a port to the Service
        service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
        
        HelloWorld hw = service.getPort(HelloWorld.class);
        System.out.println(hw.sayHi("World"));

      /*  User user = new UserImpl("World");
        System.out.println(hw.sayHiToUser(user));

        //say hi to some more users to fill up the map a bit
        user = new UserImpl("Galaxy");
        System.out.println(hw.sayHiToUser(user));

        user = new UserImpl("Universe");
        System.out.println(hw.sayHiToUser(user));

        System.out.println();
        System.out.println("Users: ");
        Map<Integer, User> users = hw.getUsers();
        for (Map.Entry<Integer, User> e : users.entrySet()) {
            System.out.println("  " + e.getKey() + ": " + e.getValue().getName());
        }
*/
    }

}




分享到:
评论

相关推荐

    CXF_WebService_开发指南、技术文档

    HelloWorldService helloWorldService = service.getPort(HelloWorldService.class); System.out.println(helloWorldService.sayHello("World")); } } ``` 运行客户端后,可以看到输出为“Hello World”。 ####...

    CXF动态webservice客户端demo

    MyWebService myWebService = service.getPort(MyWebService.class); ``` 5. **调用Web服务**:现在,你可以像调用本地方法一样调用Web服务的操作。 ```java String response = myWebService.someOperation...

    cxf客户端调用axis服务端流程

    QName portName = new QName(serviceName.getNamespaceURI(), portName); MyServicePortType port = service.getPort(portName, MyServicePortType.class); ``` #### 5. 设置SOAP绑定和端点地址 由于服务端是...

    cxf生成webservice接口

    public HelloWorldService(URL wsdlLocation, QName serviceName) { super(wsdlLocation, serviceName); } @WebEndpoint(name = "HelloWorldPort") public HelloWorld getHelloWorldPort() { return super....

    JAVA CXF webservice的示例代码

    return super.getPort(new QName("http://example.com/helloworld", "HelloWorldPort"), HelloWorld.class); } } // 调用服务 HelloWorldService service = new HelloWorldService(WSDL_LOCATION, ...

    cxf2.5.9的使用示例

    Service service = Service.create(new URL("http://localhost:8080/cxf-webservice/HelloService?wsdl"), new QName("http://example.com/", "HelloService")); HelloService helloService = service.getPort...

    利用mule服务总线代理cxf服务

    ### 利用Mule服务总线代理CXF服务 在当今复杂的IT环境中,服务总线技术扮演着重要的角色,它能够有效地集成不同的应用程序和服务。本文将详细介绍如何利用Mule ESB(Enterprise Service Bus)作为代理来访问CXF发布...

    WebService开发客户端 cxf方式

    Service service = Service.create(new URL("http://example.com/service?wsdl"), new QName("http://example.com/namespace", "ServiceName")); MyWebServicePortType port = service.getPort(MyWebServicePortType...

    CXF配置.doc

    return (UserService)super.getPort(new QName("http://demo/cxf", "UserServicePort"), UserService.class); } } ``` 最后,通过Spring配置文件或Java配置来声明并启用CXF服务: ```xml xmlns:xsi=...

    WebService之CXF(二、客户端的生成与调用)

    Service service = Service.create(new URL("http://serviceprovider.com/service?wsdl"), new QName("http://servicenamespace.com", "ServiceName")); MyServicePortType port = service.getPort...

    springboot+webservice搭建webservice服务端及使用java客户端两种方式进行调用webservice接口

    return (GreetingService)super.getPort(new QName("http://example.com/greeting", "GreetingPort"), GreetingService.class); } } // 客户端调用示例 public class Main { public static void main(String[] ...

    CXF经典总结

    String result = port.sayHello("CXF"); System.out.println(result); // 输出: Hello CXF } } ``` 通过上述示例,我们可以看到CXF框架如何简化WebService的开发过程。无论是服务端还是客户端的实现都非常直观且...

    webservice动态调用

    - (3) 创建Service:使用`javax.xml.ws.Service`类的静态方法`create()`,传入WSDL的URL和服务QName(Qualified Name)生成服务实例。 - (4) 获取Port:从Service实例中获取Port,Port代表了与服务交互的具体接口...

    Java-Spring-WebService最基础的配置示例

    本示例将探讨如何在Spring框架中配置最基础的Web服务,特别关注的是基于CXF的Web服务。CXF是一个强大的开源框架,它支持SOAP和RESTful风格的Web服务,使得开发者能够方便地创建和消费Web服务。 首先,我们需要理解...

    java解析wsdl文档获取方法与参数

    wsdl2java.generate(codeModel, "package.name.to.generate"); // 保存生成的Java源码 codeModel.build(new File("target/generated-sources")); ``` 这样,你就有了一个可以直接调用的Java客户端,包含了所有从...

    几种访问和发布webservice服务的示例

    String sayHello(@WebParam(name = "name") String name); } ``` 然后,实现这个接口并创建一个服务器来发布服务: ```java @WebService(endpointInterface = "com.example.HelloWorld") public class ...

    Java解析wsdl文档获取具体的方法与参数

    在处理WSDL文档时,还可以使用其他工具和库,比如Apache CXF或Metro,它们提供了更强大的功能,如代码生成、调试和错误处理。此外,对于大型复杂的服务,可能还需要关注WSDL文档中的类型定义(XSD schema),这些...

    webserviceTest.rar

    QName serviceName = definition.getServiceQName(); Service service = definition.getService(serviceName); ``` 4. **获取操作与绑定信息**:服务通常由一个或多个端点(Port)组成,每个端点对应一个绑定,...

    untitledDEMO.rar

    Service service = Service.create(new URL("http://serviceurl?wsdl"), new QName("http://servicenamespace", "ServiceName")); MyServicePortType port = service.getPort(MyServicePortType.class); // 设置...

    java 调用soap

    Service service = Service.create(new URL("http://example.com/service?wsdl"), new QName("http://example.com/namespace", "serviceName")); MyServicePort port = service.getPort(MyServicePort.class); ``` ...

Global site tag (gtag.js) - Google Analytics