我正在使用Axis 2和tomcat maven插件(使用Eclipse嵌入式Maven启动)开发Web服务。 出于测试目的,我使用AXIOM开发了一个Web服务客户端。
当我在我的系统上运行客户端(Windows 7 Pro)时,我遇到了各种各样的行为,其中大多数是失败的:
org.apache.axis2.AxisFault: Address already in use: NET_Bind
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
at com.nm.bdl.Launcher.main(Launcher.java:82)
Caused by: java.net.BindException: Address already in use: NET_Bind
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:398)
at java.net.Socket.bind(Socket.java:582)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:615)
at org.apache.commons.httpclient.protocol.ReflectionSocketFactory.createSocket(ReflectionSocketFactory.java:139)
at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:125)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
... 10 more
极少数情况下,客户端程序会成功访问Web服务。
Web服务和客户端程序运行正常,我在其他计算机(仍然是Windows 7 Pro)上进行了测试。当我从另一台计算机上成功运行Web服务客户端时,它也可以工作。
以下是pom.xml中tomcat插件的定义:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>full</version>
</dependency>
</dependencies>
<configuration>
<server>tomcat-development-server</server>
<port>9966</port>
<path>/</path>
<systemProperties>
<logs.dir>logs</logs.dir>
</systemProperties>
<useNaming>true</useNaming>
<contextFile>${basedir}/src/test/resources/tomcatconf/context.xml</contextFile>
<!--
<configurationDir>${basedir}/src/main/tomcatconf</configurationDir>
-->
</configuration>
<executions>
<execution>
<id>run-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
Web服务客户端程序:
static String address_WS = "http://localhost:9966/services/GetGedFile";
/**
* @param args
*/
public static void main(String[] args) {
final EndpointReference targetService = new EndpointReference(address_WS);
/* ... */
try {
Options options = new Options();
ServiceClient client = new ServiceClient();
options.setTo(targetService);
options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
options.setTimeOutInMilliSeconds(360000);
client.setOptions(options);
OMElement result = client.sendReceive(serviceOp);
String response = result.getFirstElement().getText();
System.err.println("WS call result: " + response);
OMNode node = result.getFirstElement().getFirstOMChild();
if (node instanceof OMText) {
OMText txt = (OMText) node;
String data = txt.getText();
byte[] dataBytes = Base64.decode(data);
String realString = new String(dataBytes,"UTF-8");
System.out.println("pseudo binary data received : " + realString);
}
} catch(AxisFault af) {
af.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
我试图清理Windows服务,停止防病毒,使用其他端口(不同于端口9966),用IP地址替换localhost:徒劳无功。 我用TCPView监视我的系统,检查轴web服务是否使用了tomcat插件中配置的相同端口。
还有其他想法吗?
编辑:另一个错误堆栈跟踪
log4j:WARN No appenders could be found for logger (org.apache.axis2.context.AbstractContext).
log4j:WARN Please initialize the log4j system properly.
org.apache.axis2.AxisFault: com.ctc.wstx.exc.WstxIOException: Unrecognized Windows Sockets error: -1: socket available
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:123)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:67)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:354)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:555)
at org.apache.axis2.client.ServiceClient.sendReceive(ServiceClient.java:531)
at com.nm.bdl.Launcher.main(Launcher.java:82)
Caused by: org.apache.axiom.om.OMException: com.ctc.wstx.exc.WstxIOException: Unrecognized Windows Sockets error: -1: socket available
at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createXMLStreamReader(AbstractOMMetaFactory.java:63)
at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createSOAPModelBuilder(AbstractOMMetaFactory.java:129)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:426)
at org.apache.axiom.om.OMXMLBuilderFactory.createSOAPModelBuilder(OMXMLBuilderFactory.java:405)
at org.apache.axis2.builder.SOAPBuilder.processDocument(SOAPBuilder.java:55)
at org.apache.axis2.transport.TransportUtils.createDocumentElement(TransportUtils.java:179)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:145)
at org.apache.axis2.transport.TransportUtils.createSOAPMessage(TransportUtils.java:108)
... 8 more
Caused by: com.ctc.wstx.exc.WstxIOException: Unrecognized Windows Sockets error: -1: socket available
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:548)
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:604)
at com.ctc.wstx.stax.WstxInputFactory.createSR(WstxInputFactory.java:629)
at com.ctc.wstx.stax.WstxInputFactory.createXMLStreamReader(WstxInputFactory.java:324)
at org.apache.axiom.util.stax.wrapper.XMLInputFactoryWrapper.createXMLStreamReader(XMLInputFactoryWrapper.java:95)
at org.apache.axiom.util.stax.wrapper.WrappingXMLInputFactory.createXMLStreamReader(WrappingXMLInputFactory.java:116)
at org.apache.axiom.util.stax.wrapper.XMLInputFactoryWrapper.createXMLStreamReader(XMLInputFactoryWrapper.java:95)
at org.apache.axiom.util.stax.wrapper.WrappingXMLInputFactory.createXMLStreamReader(WrappingXMLInputFactory.java:116)
at org.apache.axiom.util.stax.wrapper.XMLInputFactoryWrapper.createXMLStreamReader(XMLInputFactoryWrapper.java:95)
at org.apache.axiom.om.util.StAXUtils$1.run(StAXUtils.java:201)
at java.security.AccessController.doPrivileged(AccessController.java:241)
at org.apache.axiom.om.util.StAXUtils.createXMLStreamReader(StAXUtils.java:197)
at org.apache.axiom.om.impl.llom.factory.AbstractOMMetaFactory.createXMLStreamReader(AbstractOMMetaFactory.java:55)
... 15 more
Caused by: java.net.SocketException: Unrecognized Windows Sockets error: -1: socket available
at java.net.PlainSocketImpl.socketAvailable(Native Method)
at java.net.PlainSocketImpl.available(PlainSocketImpl.java:487)
at java.net.SocketInputStream.available(SocketInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:332)
at org.apache.commons.httpclient.WireLogInputStream.read(WireLogInputStream.java:69)
at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:182)
at java.io.FilterInputStream.read(FilterInputStream.java:134)
at org.apache.commons.httpclient.AutoCloseInputStream.read(AutoCloseInputStream.java:108)
at java.io.FilterInputStream.read(FilterInputStream.java:134)
at org.apache.axiom.om.util.DetachableInputStream.read(DetachableInputStream.java:147)
at java.io.FilterInputStream.read(FilterInputStream.java:134)
at java.io.PushbackInputStream.read(PushbackInputStream.java:182)
at java.io.FilterInputStream.read(FilterInputStream.java:113)
at com.ctc.wstx.io.UTF8Reader.loadMore(UTF8Reader.java:365)
at com.ctc.wstx.io.UTF8Reader.read(UTF8Reader.java:110)
at com.ctc.wstx.io.ReaderBootstrapper.initialLoad(ReaderBootstrapper.java:245)
at com.ctc.wstx.io.ReaderBootstrapper.bootstrapInput(ReaderBootstrapper.java:132)
at com.ctc.wstx.stax.WstxInputFactory.doCreateSR(WstxInputFactory.java:543)
... 27 more
答案 0 :(得分:1)
通过更改客户端程序的java运行时解决了我的问题。 我使用的是IBM Jdk 5(这是Web服务服务器的要求),我转而使用标准的Jre 6。