0 0

CXF的server端如何調用外部的webservice呢?0

當我在cxf的server調用其他的webserver 就會出錯,不知是否可行?
代碼如下,
CXFtest.java
import javax.jws.WebService; 
@WebService
public interface CXFtest {
	public String sayCXF(String name);  
	
}


CXFtestImpl.java
import javax.jws.WebService; 

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;

class WebServiceClientHelper {
	public static String callService(String wsUrl, String method, Object... arg) {
		JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
		Client client = dcf.createClient(wsUrl);
		Object[] res = null;
		try {
			res = client.invoke(method, arg);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return (String) res[0];
	}
}

@WebService
public class CXFtestImpl implements CXFtest {

	@Override
	public String sayCXF(String name) {
		// TODO Auto-generated method stub
		
		String str = WebServiceClientHelper.callService("http://localhost:8080/axis2/services/Version?wsdl", "getVersion", "");
		//System.out.println(str);
		
		return "Hello " + name; 
	}
}


CXFserver.java
import org.apache.cxf.endpoint.Server;  
import org.apache.cxf.jaxws.JaxWsServerFactoryBean; 

public class CXFserver {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();  
        factory.setServiceClass(CXFtestImpl.class);  
        factory.setAddress("http://localhost:8080/CXFtest");  
                
        Server server = factory.create();  
        server.start();
	}

}

調用時出現的錯誤如下:
資訊: started o.e.j.s.h.ContextHandler{,null}
七月 04, 2012 8:36:25 下午 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
警告: Application {http://unknown.namespace/}CXFtestImplService#{http://unknown.namespace/}sayCXF has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: Failed to create service.
at org.apache.cxf.service.invoker.AbstractInvoker.createFault(AbstractInvoker.java:162)
at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.createFault(AbstractJAXWSMethodInvoker.java:213)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:128)
at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:178)
at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:64)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:75)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)
at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:107)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:122)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.serviceRequest(JettyHTTPDestination.java:344)
at org.apache.cxf.transport.http_jetty.JettyHTTPDestination.doService(JettyHTTPDestination.java:310)
at org.apache.cxf.transport.http_jetty.JettyHTTPHandler.handle(JettyHTTPHandler.java:72)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:943)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:879)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
at org.eclipse.jetty.server.Server.handle(Server.java:349)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:919)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:588)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218)
at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
at java.lang.Thread.run(Unknown Source)
Caused by: org.apache.cxf.service.factory.ServiceConstructionException: Failed to create service.
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:80)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:292)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:235)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:228)
at org.apache.cxf.endpoint.dynamic.DynamicClientFactory.createClient(DynamicClientFactory.java:183)
at WebServiceClientHelper.callService(CXFtestImpl.java:9)
at CXFtestImpl.sayCXF(CXFtestImpl.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180)
at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96)
... 30 more
Caused by: javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing 'http://localhost:8080/axis2/services/Version?wsdl'.: java.io.FileNotFoundException: http://localhost:8080/axis2/services/Version?wsdl
at com.ibm.wsdl.xml.WSDLReaderImpl.getDocument(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at com.ibm.wsdl.xml.WSDLReaderImpl.readWSDL(Unknown Source)
at org.apache.cxf.wsdl11.WSDLManagerImpl.loadDefinition(WSDLManagerImpl.java:244)
at org.apache.cxf.wsdl11.WSDLManagerImpl.getDefinition(WSDLManagerImpl.java:191)
at org.apache.cxf.wsdl11.WSDLServiceFactory.<init>(WSDLServiceFactory.java:78)
... 42 more
Caused by: java.io.FileNotFoundException: http://localhost:8080/axis2/services/Version?wsdl
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
... 48 more

SOA 
2012年7月04日 20:38

1个答案 按时间排序 按投票排序

0 0

Problem parsing 'http://localhost:8080/axis2/services/Version?wsdl'.: java.io.FileNotFoundException: http://localhost:8080/axis2/services/Version?wsdl
是不是这个url有问题,你发布的两个webservice都用的8080端口。
还有你将两个webservice都用cxf发布,cxf访问axis也可能出问题

2012年7月04日 22:43

相关推荐

    webservice动态访问天气预报(tomcat+jsp+servlet+webservice+cxf)

    Servlet调用CXF提供的Weather WebService获取对应城市的天气信息,然后将结果返回给Ajax请求;最后,JSP页面使用jQuery更新显示区域,展示天气预报数据。 通过这个项目,开发者可以学习到如何集成多种技术实现一个...

    基于J2ee的天气预报 调用webservice

    【基于J2EE的天气预报调用WebService】是Java Web开发中的一个重要应用场景,它涉及到如何通过Web服务获取并展示实时天气信息。在这个项目中,开发者使用了Java的J2EE平台,通过调用WebService接口来获取天气数据,...

    CXF-WebService开发过程中所遇到过的问题集

    在开发基于CXF的WebService时,开发者可能会遇到各种问题,这些问题涵盖了服务器配置、发布路径设置、缓存管理以及服务调用等多方面。以下是对这些常见问题的详细解答: 问题一涉及Eclipse集成的Tomcat服务器无法...

    调用XFire WebService

    1. **定义服务接口**:使用Java编程语言定义服务接口,这个接口将暴露给外部调用者。接口的方法对应于Web服务的操作。 2. **实现服务**:创建一个类来实现定义的服务接口,实现具体的服务逻辑。 3. **配置XFire**...

    WebService服务端Demo

    - **服务提供者(ServiceProvider)**: 在这个Demo中,服务端(DemoServer)就是服务提供者,它公开了一个或多个可以被外部调用的Web方法。 - **部署服务**: 服务提供者需要将服务接口和实现打包成一个可部署的...

    实现webServices接口调用demo

    本教程将深入讲解如何使用XFire在Java环境中实现Web服务接口的调用,包括内部和外部访问。 一、Web服务简介 Web服务是通过SOAP(Simple Object Access Protocol)协议,使用HTTP作为传输层,XML作为数据交换格式的...

    深入了解java WebService

    文件“WebService_JAX_Client”和“WebService_JAX_Server”可能是博主提供的示例代码,分别代表了一个JAX-WS客户端和服务端的实现。通过阅读和运行这些代码,你可以更直观地理解Web服务的工作流程。 总的来说,...

    使用Web Services Explorer测试Webservice服务.docx

    在ServiceMix中,你可以部署和配置Web服务,或者使用它作为客户端来调用外部服务。ServiceMix提供了一个基于Web的管理控制台,方便进行这些操作。通过上传WSDL文件,ServiceMix可以自动创建服务代理,使得你可以轻松...

    myeclipse搭建webservice实例讲解_myeclipse_building_webservice_

    对于外部应用想要调用这个Web服务,可以使用JAX-WS或者Apache CXF等库,根据WSDL生成客户端代理类,然后通过代理类调用服务。这一步通常发生在服务提供者和消费者不在同一项目或系统的情况下。 9. **高级特性** ...

    cxfwebservice

    4. **部署服务**:使用 CXF 提供的工具或配置,我们可以将服务绑定到一个端点(通常是 HTTP URL),使其可供外部调用。在 CXF 中,可以使用 Spring 配置文件或者 Java annotations 进行服务部署。 5. **服务调用**...

    WEBSERVICE教程

    - 相较于开源的Web Service框架,WebLogic Server具有易用性、高可靠性和优秀性能的优势,但开源框架如Axis或CXF等具有跨平台兼容性和IDE集成的优点。 3. **典型技术需求** - 在本案例中,一个综合业务支撑系统...

    C++调用Java web service帮助文档.doc

    - **Java Web Service**:基于Java的服务器端服务,提供SOAP接口供外部系统调用。 - **MS SOAP Toolkit 3.0**:微软提供的用于C++客户端开发的工具包,支持SOAP消息的构造和解析。 #### 三、准备工作 1. **安装MS ...

    cxf开发实践

    ### CXF开发实践中的关键技术知识点 #### 一、SSL/TLS 安全协议的理解与应用 **1.1 SSL/TLS 概述** - **定义与功能:** 安全套接层(Secure Sockets Layer,简称SSL)及其后续版本传输层安全(Transport Layer ...

    xfire开发Web Service接口详解

    2. 启动服务:使用XFire的Server类加载XML配置并启动服务,这将使你的Web Service可供外部访问。 六、消费Web Service 1. 生成客户端代理:XFire提供了客户端工具,可以自动生成消费Web Service的Java客户端代码。 ...

Global site tag (gtag.js) - Google Analytics