Eclipse生成的Web服务客户端非常慢

时间:2009-12-31 16:09:18

标签: java eclipse web-services axis

前面的一点信息:

我有一个SOAP服务(使用JAX-WS(Endpoint类)托管,但我认为这不重要)。

我可以使用Visual Studio生成客户端(C#)来连接并使用Web服务。

我使用Eclipse Web Tools(new - > other - > web services - > web services client)生成了一个java客户端。

然后我写了一个JUnit测试来测试客户端。测试通过,但运行需要很长时间。每次服务呼叫需要300秒(给予或花费几秒钟)。此外,计算机的速度并不重要。如果我在非常慢的工作笔记本电脑上运行它,它需要花费相同的时间,就好像我在快速的家用机器上运行它。

我在org.apache.axis.encoding.DeserializationContext中调试了以下函数的轴代码:

public void parse() throws SAXException
    {
        if (inputSource != null) {
            SAXParser parser = XMLUtils.getSAXParser();
            try {
                parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
                parser.parse(inputSource, this);

                try {
                    // cleanup - so that the parser can be reused.
                    parser.setProperty("http://xml.org/sax/properties/lexical-handler", nullLexicalHandler);
                } catch (Exception e){
                    // Ignore.
                }

没什么好奇的,但是对parser.parse()的调用占用了300秒。来自Web服务的时间非常短,因此解析起来不会花费太多时间。

如果有人想知道,解析器的实际类型是com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl

我无法调试它,因为我没有源代码(而且我已经厌倦了调试50个深入常用库的调用)。

我目前正在运行探查器以包含Sun的软件包。我会在完成后发布我的发现(添加所有这些包会显着减慢测试速度)

我正在使用Eclipse 3.5.1而我正在使用axis 1.4

编辑:

这是JUnit测试:

@Test
public void testExecuter() throws IOException, InterruptedException, RemoteException, ServiceException
{
    //Listener l = new Listener(3456);
    //l.start();
    Executer exec = new ExecuterServiceLocator().getExecuterPort();
    //Executer exec = new ExecuterProxy("http://localhost:3456/Executer");
    System.out.println("executer created");
    _return remote = exec.execute("perl -e \"print 5\"", new EvAction[0]);
    System.out.println("after call 1");
    assertEquals("5", remote.getStdout());
    assertEquals("", remote.getStderr());
    assertEquals(0, remote.getReturnCode());
}

注意:创建Executer的两种方式都会发生相同的事情

EDIT2:

以下是我用来启动服务的代码:

public static void main(String[] args) {
    Endpoint.create(new Executer()).publish("http://localhost:3456/Executer");
}

我无法发布网址,因为我现在正在一台机器上开发它。但是,如果我转到http://localhost:3456/Executer?WSDL

,则会生成WSDL
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
-->
−
<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
-->
−
<definitions targetNamespace="http://executer/" name="ExecuterService">
−
<types>
−
<xsd:schema>
<xsd:import namespace="http://executer/" schemaLocation="http://localhost:3456/Executer?xsd=1"/>
</xsd:schema>
</types>
−
<message name="Execute">
<part name="parameters" element="tns:Execute"/>
</message>
−
<message name="ExecuteResponse">
<part name="parameters" element="tns:ExecuteResponse"/>
</message>
−
<message name="IOException">
<part name="fault" element="tns:IOException"/>
</message>
−
<message name="InterruptedException">
<part name="fault" element="tns:InterruptedException"/>
</message>
−
<portType name="Executer">
−
<operation name="Execute">
<input message="tns:Execute"/>
<output message="tns:ExecuteResponse"/>
<fault message="tns:IOException" name="IOException"/>
<fault message="tns:InterruptedException" name="InterruptedException"/>
</operation>
</portType>
−
<binding name="ExecuterPortBinding" type="tns:Executer">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
−
<operation name="Execute">
<soap:operation soapAction=""/>
−
<input>
<soap:body use="literal"/>
</input>
−
<output>
<soap:body use="literal"/>
</output>
−
<fault name="IOException">
<soap:fault name="IOException" use="literal"/>
</fault>
−
<fault name="InterruptedException">
<soap:fault name="InterruptedException" use="literal"/>
</fault>
</operation>
</binding>
−
<service name="ExecuterService">
−
<port name="ExecuterPort" binding="tns:ExecuterPortBinding">
<soap:address location="http://localhost:3456/Executer"/>
</port>
</service>
</definitions>

编辑:

我认为这可能会导致问题:

我使用TCPMonitor来查看SOAP请求,我注意到客户端正在说HTTP / 1.0而服务器正在说HTTP / 1.1,但我不知道这是否导致问题。我目前正试图弄清楚如何使客户端说HTTP / 1.1。

以下是有人想知道的SOAP消息:

POST /Executer HTTP/1.0
Content-Type: text/xml; charset=utf-8
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: Axis/1.4
Host: USENBOONETL1C:2222
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: ""
Content-Length: 354

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><Execute xmlns="http://executer/"><arg0 xmlns="">perl -e &quot;print 5&quot;</arg0></Execute></soapenv:Body></soapenv:Envelope>

和回复:

HTTP/1.1 200 OK
Content-type: text/xml;
charset="utf-8"
Content-length: 266

<?xml version="1.0" ?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:ExecuteResponse xmlns:ns2="http://executer/"><return><stdout>5</stdout><stderr></stderr><returnCode>0</returnCode></return></ns2:ExecuteResponse></S:Body></S:Envelope>

编辑:

最后!结果是将HTTP客户端更改为CommonsHTTPClient并使用HTTP / 1.1修复了问题:

这是我添加到客户端的代码修复它:

BasicClientConfig basicClientConfig = new BasicClientConfig();
SimpleChain simpleChain = new SimpleChain();

simpleChain.addHandler(new CommonsHTTPSender());
basicClientConfig.deployTransport("http", simpleChain);

ExecuterServiceLocator l = new ExecuterServiceLocator(basicClientConfig);
...

注意:您必须将common-httpclient.jarcommon.codec.jar添加到类路径中。

4 个答案:

答案 0 :(得分:2)

我遇到了同样的问题并解决了修改http版本的问题。

更简单的方法是,在存根类中调用Call实例上的setProperty方法:

_call.setProperty(MessageContext.HTTP_TRANSPORT_VERSION,HTTPConstants.HEADER_PROTOCOL_V11);

答案 1 :(得分:1)

1)验证C#和Java客户端是否向服务器发送完全相同的请求。如果你正在使用Jetty,打开request logging可能会为你提供所需的数据。

2)一旦SAX解析器开始在客户端上运行,它将进行回调,直接或间接地调用生成的客户端中的方法。您应该能够在生成的客户端方法的开头和结尾(和/或return s)设置断点,并使用这些断点来确定延迟[s]发生的位置[s]。

(顺便说一句,在SAX API中,http://xml.org/sax/properties/lexical-handler等URL在本地用于标识属性名称;没有任何内容可以在该地址查找任何内容。有关详细信息,请参阅http://xerces.apache.org/xerces2-j/properties.html。 / p>

答案 2 :(得分:1)

你的问题正是我现在面临的问题。有趣的是,我经历了几乎相同的循环(端点服务,.net客户端工作正常,eclipse生成的客户端需要花费5分钟来处理)。实际上,感谢您发布更新和解决方案。我不是一个精通java的人,所以请问你是否将解决方案应用于同一个eclipse生成的客户端代码?或者你做了一些完全不同的事情?如果您修改了eclipse生成的客户端代码,那么您在哪里添加了这些行?

谢谢,我真的很感谢帮助:)

干杯, Arash的

答案 3 :(得分:0)

很可能是超时。可能是那个解析器试图从互联网上下载东西(DTD,XSD等),但你是在代理/防火墙后面。

在运行测试时,尝试对服务器进行堆栈跟踪以查看正在进行的操作(例如jps / jstat)。