在eclipse下发布到tomcat成功,并且能看到wsdl.我有一个问题想问各位

47 views
Skip to first unread message

cxf-zh

unread,
Sep 1, 2007, 10:33:34 AM9/1/07
to cxf-zh, 我在spring下面写了一个sample里spring_http的例子,运行客户端出错
我能在发布到服务器上去。
我想问下,我在eclipse里直接运行我写好的client代码为什么出错呢。
并且能看到wsdl文件。服务器发布也成功。我就是想问下。运行client代码是不是就当做java application运行就行了?也许我这是
一个很低级的问题。非常希望高手能帮助下。拉我后辈下。(强调一点,不用IDE工具,直接运行ant 是成功的,但是我不想现在用它的例子,我想在
IDE下面调试下,看下他是怎么组装成。怎么变成服务的。)
客户端的代码如下:
package demo.spring.client;


import demo.spring.HelloWorld;

import
org.springframework.context.support.ClassPathXmlApplicationContext;


public final class Client {

private Client() {
}

public static void main(String args[]) throws Exception {
// START SNIPPET: client
ClassPathXmlApplicationContext context
= new ClassPathXmlApplicationContext(new String[] {"demo/
spring/client/client-beans.xml"});

HelloWorld client = (HelloWorld)context.getBean("client");

String response = client.sayHi("Joe");
System.out.println("Response: " + response);
System.exit(0);
// END SNIPPET: client
}
}

这是错误的信息
rg.apache.cxf.interceptor.Fault: Connection refused: connect
at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:
74)
at
org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:
68)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:
207)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:205)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:
73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
135)
at $Proxy11.sayHi(Unknown Source)
at demo.spring.client.Client.main(Client.java:39)
Caused by: com.ctc.wstx.exc.WstxIOException: Connection refused:
connect
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:313)
at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:
72)
... 8 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:
195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at sun.net.NetworkClient.doConnect(NetworkClient.java:152)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:
792)
at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:
744)
at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:
669)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:
836)
at org.apache.cxf.transport.http.HTTPConduit
$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1787)
at org.apache.cxf.transport.http.HTTPConduit
$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1755)
at
org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:
42)
at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:96)
at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:
214)
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:311)
... 9 more
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException:
Connection refused: connect
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
169)
at $Proxy11.sayHi(Unknown Source)
at demo.spring.client.Client.main(Client.java:39)
Caused by: org.apache.cxf.interceptor.Fault: Connection refused:
connect
at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:
74)
at
org.apache.cxf.interceptor.BareOutInterceptor.handleMessage(BareOutInterceptor.java:
68)
at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:
207)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:254)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:205)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:
73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:
135)
... 2 more
Caused by: com.ctc.wstx.exc.WstxIOException: Connection refused:
connect
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:313)
at
org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor.writeParts(AbstractOutDatabindingInterceptor.java:
72)
... 8 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:
195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.Socket.connect(Socket.java:507)
at sun.net.NetworkClient.doConnect(NetworkClient.java:152)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:365)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:477)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:214)
at sun.net.www.http.HttpClient.New(HttpClient.java:287)
at sun.net.www.http.HttpClient.New(HttpClient.java:299)
at
sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:
792)
at
sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:
744)
at
sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:
669)
at
sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:
836)
at org.apache.cxf.transport.http.HTTPConduit
$WrappedOutputStream.handleHeadersTrustCaching(HTTPConduit.java:1787)
at org.apache.cxf.transport.http.HTTPConduit
$WrappedOutputStream.onFirstWrite(HTTPConduit.java:1755)
at
org.apache.cxf.io.AbstractWrappedOutputStream.write(AbstractWrappedOutputStream.java:
42)
at com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:96)
at com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:
214)
at com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:311)
... 9 more

Willem Jiang

unread,
Sep 1, 2007, 10:50:21 AM9/1/07
to cxf...@googlegroups.com
看样子是Client连接Server的时候出的错。
检查一下你Client端设置的地址信息。
或者把你的client-bean.xml贴出来。


你如果想在Eclipse中跟踪代码,建议你把CXF的Source Code下下来,跟踪里面的
Systest。
具体的步骤在CXF wiki 上有说明
download source code
http://cwiki.apache.org/CXF/source-repository.html

build source code
http://cwiki.apache.org/CXF/building.html

eclipse setup
http://cwiki.apache.org/CXF/setting-up-eclipse.html

cxf-zh

unread,
Sep 1, 2007, 11:11:06 AM9/1/07
to cxf-zh

谢谢willem ,你的提示,使我一下子就找到了错误。再次感谢willem 。在这个讨论组,我学习webservice就像在长征的路找到了组
织。在次感谢。我也想分想下我的成功
给后来学习者
这是我的client-bean.xml,一定要注意这里面的<property name="address" value="http://
localhost/WebSpring/HelloWorld"/>,这里面的value一定要与WSDL里面产生的
<soap:address location="http://localhost/WebSpring/HelloWorld" /> 里面的
location相同(前提是我们使用spring开发,默认产生address)

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schema/jaxws.xsd">

<bean id="client" class="demo.spring.HelloWorld"
factory-bean="clientFactory" factory-method="create"/>

<bean id="clientFactory"
class="org.apache.cxf.jaxws.JaxWsProxyFactoryBean">
<property name="serviceClass" value="demo.spring.HelloWorld"/>
<property name="address" value="http://localhost/WebSpring/
HelloWorld"/>
</bean>
WSDL信息:
<?xml version="1.0" encoding="utf-8" ?>
- <wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:ns1="http://spring.demo/" xmlns:soap="http://schemas.xmlsoap.org/
wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
name="HelloWorldImplService" targetNamespace="http://spring.demo/">
- <wsdl:types>
- <xsd:schema xmlns="http://spring.demo/"
attributeFormDefault="unqualified" elementFormDefault="unqualified"
targetNamespace="http://spring.demo/" xmlns:xsd="http://www.w3.org/
2001/XMLSchema">
<xsd:element name="sayHi" type="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="sayHiResponse" />
- <xsd:complexType name="sayHiResponse">
- <xsd:sequence>
<xsd:element minOccurs="0" name="return" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
- <wsdl:message name="sayHiResponse">
<wsdl:part element="ns1:sayHiResponse" name="result" />
</wsdl:message>
- <wsdl:message name="sayHi">
<wsdl:part element="ns1:sayHi" name="parameters" />
</wsdl:message>
- <wsdl:portType name="HelloWorld">
- <wsdl:operation name="sayHi">
<wsdl:input message="ns1:sayHi" name="sayHi" />
<wsdl:output message="ns1:sayHiResponse" name="sayHiResponse" />
</wsdl:operation>
</wsdl:portType>
- <wsdl:binding name="HelloWorldImplServiceSoapBinding"
type="ns1:HelloWorld">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/
soap/http" />
- <wsdl:operation name="sayHi">
<soap:operation soapAction="" style="document" />
- <wsdl:input name="sayHi">
<soap:body use="literal" />
</wsdl:input>
- <wsdl:output name="sayHiResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
- <wsdl:service name="HelloWorldImplService">
- <wsdl:port binding="ns1:HelloWorldImplServiceSoapBinding"
name="HelloWorldImplPort">
<soap:address location="http://localhost/WebSpring/HelloWorld" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

Reply all
Reply to author
Forward
0 new messages