ITPub博客

首页 > 应用开发 > IT综合 > WebService CXF 错误:java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.

WebService CXF 错误:java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.

原创 IT综合 作者:wolaiye320 时间:2009-08-12 18:37:30 0 删除 编辑

CXF Client 类源码如下

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package com.sg.webservice.client;

import java.util.Map;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;

import com.sg.webservice.server.HelloWorld;
import com.sg.webservice.server.User;
import com.sg.webservice.server.UserImpl;

public final class Client {

private static final QName SERVICE_NAME
= new QName("http://server.webservice.com/", "HelloWorld");
private static final QName PORT_NAME
= new QName("http://server.webservice.com/", "HelloWorldPort");


private Client() {
}

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

// 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 users = hw.getUsers();
for (Map.Entry e : users.entrySet()) {
System.out.println(" " + e.getKey() + ": " + e.getValue().getName());
}

}

}

报错:

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:236)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:471)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:301)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:253)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:121)
at $Proxy45.sayHi(Unknown Source)
at com.sg.webservice.client.Client.main(Client.java:57)
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:803)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:788)
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:715)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:490)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
... 8 more
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Could not send Message.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:141)
at $Proxy45.sayHi(Unknown Source)
at com.sg.webservice.client.Client.main(Client.java:57)
Caused by: java.net.MalformedURLException: Invalid address. Endpoint address cannot be null.
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:803)
at org.apache.cxf.transport.http.HTTPConduit.getURL(HTTPConduit.java:788)
at org.apache.cxf.transport.http.HTTPConduit.setupURL(HTTPConduit.java:715)
at org.apache.cxf.transport.http.HTTPConduit.prepare(HTTPConduit.java:490)
at org.apache.cxf.interceptor.MessageSenderInterceptor.handleMessage(MessageSenderInterceptor.java:46)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:471)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:301)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:253)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:121)
... 2 more

出错原因:

private static final QName SERVICE_NAME
= new QName("http://server.webservice.com/", "HelloWorld");
private static final QName PORT_NAME
= new QName("http://server.webservice.com/", "HelloWorldPort");


中的URL不与真实包路径成相反。

解决方法将http://server.webservice.com/改成与真实包路径完全相反http://server.webservice.sg.com/


[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/1700919/viewspace-1025208/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: 草稿
请登录后发表评论 登录
全部评论

注册时间:2008-06-23

  • 博文量
    19
  • 访问量
    827664