通过无法创建信封的套接字结果发送XMLEncoded SOAP请求

时间:2014-06-06 10:32:54

标签: java sockets soap

我有一个非常专业的环境,我的任务是通过套接字发送以下HTTP请求:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
    <soapenv:Header/>
    <soapenv:Body>
        <ns1:CreateTsiIncidentRequest>
            <ns1:keys>
                <ns1:IncidentID type="String"/>
            </ns1:keys>
            <ns1:model>
                <ns1:instance>
                    <ns1:Criticality type="String">MEDIUM</ns1:Criticality>
                    <ns1:AssignmentGroup type="String">TESTSMX_TEST-ASSIGNMENT-GROUP</ns1:AssignmentGroup>
                    <ns1:Description type="String">unverzüglich gemäß den Incident-/Changeprozessen zu korrigieren. Bei Fragen wenden Sie sich bitte an das zuständige Engineering, DPS Security ( DPS-Security@t-systems.com ), oder an die Toolbetreiber &amp;quot;AuditServer&amp;quot; ( siux-win-audit-sup@t-systems.com ). </ns1:Description>
                    <ns1:ContactFirstName type="String">SARAH</ns1:ContactFirstName>
                    <ns1:Title type="String">SIUX / WinAudit (FATAL)</ns1:Title>
                    <ns1:Category2 type="String">OTHER</ns1:Category2>
                    <ns1:ReportedByUserID type="String">SARAHWS</ns1:ReportedByUserID>
                    <ns1:ServiceRestriction type="String">MEDIUM</ns1:ServiceRestriction>
                    <ns1:Category1 type="String">SECURITY</ns1:Category1>
                    <ns1:CustomerName type="String">TSI DUMMY COMPANY</ns1:CustomerName>
                    <ns1:ReportedByFirstName type="String">SARAH</ns1:ReportedByFirstName>
                    <ns1:ReportedByLastName type="String">SARAH</ns1:ReportedByLastName>
                    <ns1:CustomerLocation type="String">TSI DUMMY LOCATION</ns1:CustomerLocation>
                    <ns1:NotifiedBy type="String">sarah</ns1:NotifiedBy>
                    <ns1:AffectedCI type="String">TENEBROUS</ns1:AffectedCI>
                </ns1:instance>
            </ns1:model>
        </ns1:CreateTsiIncidentRequest>
    </soapenv:Body>
</soapenv:Envelope>

通过SOAPUI发送此请求,我得到了正确的响应。但是,当我通过JAVA代码发送它时,我收到以下FAULT消息:

Response in 203 ms... 576 bytes.
HTTP/1.1 500 Internal Server Errors
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=781DBD31B6DFEFD940ED16386C22FF36; Path=/SM
Connection: close
Content-Type: text/xml;charset=UTF-8
Transfer-Encoding: chunked
Date: Fri, 06 Jun 2014 10:09:01 GMT
Connection: close

SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>Unable to create envelope from given source: </faultstring><faultactor>Server</faultactor></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

我试图搜索这个错误信息,这究竟是什么意思,但它似乎是如此基本,我无法在任何地方找到它。处理请求发送的JAVA代码如下所示:

OutputStream os = null;
    try {
        os = connection.getOutputStream();
    } catch (IOException ex) {
        Logger.getLogger(TEST_EX.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        if (os != null) {
            StringBuilder requestBuilder = new StringBuilder();
            requestBuilder.append(String.format("POST %s HTTP/1.1\r\n", path));
            requestBuilder.append(String.format("%s: %s\r\n", "Accept-Encoding", "deflate"));
            requestBuilder.append(String.format("%s: %s\r\n", "Content-Type", "text/xml;charset=UTF-8"));
            requestBuilder.append(String.format("%s: %s\r\n", "SOAPAction", soapAction));
            requestBuilder.append(String.format("%s: %s\r\n", "Content-Length", request.length()));
            requestBuilder.append(String.format("%s: %s\r\n", "Host", String.format("%s:%s", endpoint, port)));
            requestBuilder.append(String.format("%s: %s\r\n", "Connection", "Keep-Alive"));
            requestBuilder.append(String.format("%s: %s\r\n", "Authorization", String.format("Basic %s", enc)));
            requestBuilder.append("\r\n");

            final String RequestHeaders = requestBuilder.toString();
            final byte[] HeaderBytes = RequestHeaders.getBytes(Charset.forName("UTF-8"));
            final byte[] RequestBytes = request.getBytes(Charset.forName("UTF-8"));

            try {
                os.write(HeaderBytes, 0, HeaderBytes.length);
                os.write(RequestBytes, 0, RequestBytes.length);

                // Wait for response and then start processing it:
                InputStream is = connection.getInputStream();
                while (is.available() <= 0) {
                    try {
                        Thread.sleep(50);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(TEST_EX.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }

                byte[] bytes = convert(is);
                response = new String(bytes, 0, bytes.length, Charset.forName("UTF-8"));
            } catch (final IOException ex) {
                Logger.getLogger(TEST_EX.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

请求是来自正在运行的SOAPUI示例的Ctrl + C和Ctrl + V.再次从那里复制HTTP标头。最后,我可以使用JAVA源提供Wireshark跟踪消息的内容:

    POST /SM/7/ws HTTP/1.1

Accept-Encoding: deflate

Content-Type: text/xml;charset=UTF-8

SOAPAction: "Create"

Content-Length: 2101

Host: 10.163.209.211:4650

Connection: Keep-Alive

Authorization: Basic V1NURVNUOlN0YXJ0MTIz



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
    <soapenv:Header/>
    <soapenv:Body>
        <ns1:CreateTsiIncidentRequest>
            <ns1:keys>
                <ns1:IncidentID type="String"/>
            </ns1:keys>
            <ns1:model>
                <ns1:instance>
                    <ns1:Criticality type="String">MEDIUM</ns1:Criticality>
                    <ns1:AssignmentGroup type="String">TESTSMX_TEST-ASSIGNMENT-GROUP</ns1:AssignmentGroup>
                    <ns1:Description type="String">unverzüglich gemäß den Incident-/Changeprozessen zu korrigieren. Bei Fragen wenden Sie sich bitte an das zustündige Engineering, DPS Security ( DPS-Security@t-systems.com ), oder an die Toolbetreiber &amp;quot;AuditServer&amp;quot; ( siux-win-audit-sup@t-systems.com ). </ns1:Description>
                    <ns1:ContactFirstName type="String">SARAH</ns1:ContactFirstName>
                    <ns1:Title type="String">SIUX / WinAudit (FATAL)</ns1:Title>
                    <ns1:Category2 type="String">OTHER</ns1:Category2>
                    <ns1:ReportedByUserID type="String">SARAHWS</ns1:ReportedByUserID>
                    <ns1:ServiceRestriction type="String">MEDIUM</ns1:ServiceRestriction>
                    <ns1:Category1 type="String">SECURITY</ns1:Category1>
                    <ns1:CustomerName type="String">TSI DUMMY COMPANY</ns1:CustomerName>
                    <ns1:ReportedByFirstName type="String">SARAH</ns1:ReportedByFirstName>
                    <ns1:ReportedByLastName type="String">SARAH</ns1:ReportedByLastName>
                    <ns1:CustomerLocation type="String">TSI DUMMY LOCATION</ns1:CustomerLocation>
                    <ns1:NotifiedBy type="String">sarah</ns1:NotifiedBy>
                    <ns1:AffectedCI type="String">TENEBROUS</ns1:AffectedCI>
                </ns1:instance>
            </ns1:model>
        </ns1:CreateTsiIncidentRequest>
    </soapenv:Body>
</soapenv:Envelope>HTTP/1.1 500 Internal Server Error

Server: Apache-Coyote/1.1

Set-Cookie: JSESSIONID=9FB420040977A242EF2822F5A03F1E9C; Path=/SM

Connection: close

Content-Type: text/xml;charset=UTF-8

Transfer-Encoding: chunked

Date: Fri, 06 Jun 2014 10:26:46 GMT

Connection: close



12f

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>Unable to create envelope from given source: </faultstring><faultactor>Server</faultactor></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

0

使用SOAP-UI:

    POST /SM/7/ws HTTP/1.1

Accept-Encoding: gzip,deflate

Content-Type: text/xml;charset=UTF-8

SOAPAction: "Create"

Content-Length: 2154

Host: 10.163.209.211:4650

Connection: Keep-Alive

User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

Authorization: Basic V1NURVNUOlN0YXJ0MTIz



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.hp.com/SM/7" xmlns:com="http://schemas.hp.com/SM/7/Common" xmlns:xm="http://www.w3.org/2005/05/xmlmime">
    <soapenv:Header/>
    <soapenv:Body>
        <ns1:CreateTsiIncidentRequest>
            <ns1:keys>
                <ns1:IncidentID type="String"/>
            </ns1:keys>
            <ns1:model>
                <ns1:instance>
                    <ns1:Criticality type="String">MEDIUM</ns1:Criticality>
                    <ns1:AssignmentGroup type="String">TESTSMX_TEST-ASSIGNMENT-GROUP</ns1:AssignmentGroup>
                    <ns1:Description type="String">unverzüglich gemäß den Incident-/Changeprozessen zu korrigieren. Bei Fragen wenden Sie sich bitte an das zustündige Engineering, DPS Security ( DPS-Security@t-systems.com ), oder an die Toolbetreiber &amp;quot;AuditServer&amp;quot; ( siux-win-audit-sup@t-systems.com ). </ns1:Description>
                    <ns1:ContactFirstName type="String">SARAH</ns1:ContactFirstName>
                    <ns1:Title type="String">SIUX / WinAudit (FATAL)</ns1:Title>
                    <ns1:Category2 type="String">OTHER</ns1:Category2>
                    <ns1:ReportedByUserID type="String">SARAHWS</ns1:ReportedByUserID>
                    <ns1:ServiceRestriction type="String">MEDIUM</ns1:ServiceRestriction>
                    <ns1:Category1 type="String">SECURITY</ns1:Category1>
                    <ns1:CustomerName type="String">TSI DUMMY COMPANY</ns1:CustomerName>
                    <ns1:ReportedByFirstName type="String">SARAH</ns1:ReportedByFirstName>
                    <ns1:ReportedByLastName type="String">SARAH</ns1:ReportedByLastName>
                    <ns1:CustomerLocation type="String">TSI DUMMY LOCATION</ns1:CustomerLocation>
                    <ns1:NotifiedBy type="String">sarah</ns1:NotifiedBy>
                    <ns1:AffectedCI type="String">TENEBROUS</ns1:AffectedCI>
                </ns1:instance>
            </ns1:model>
        </ns1:CreateTsiIncidentRequest>
    </soapenv:Body>
</soapenv:Envelope>
HTTP/1.1 200 OK

Server: Apache-Coyote/1.1

Keep-Alive: timeout=1200000, max=1000

Connection: Keep-Alive

Content-Encoding: gzip

Content-Type: text/xml;charset=utf-8

Transfer-Encoding: chunked

Date: Fri, 06 Jun 2014 10:28:11 GMT



a

..........

536

.W.n.6.~.B.C.U...fu.a....,;....0....\%R%............-..e...
.!......<....`.......K?....}.3*z..Km.e.3...q...t.....SC..xmhh....g.....G...x4&..r.E...(.BD)...2..]C.....K....j.).D.at.n....{..gz...?......,...
.n.h.t.f1/:1...7...^..c0c......9'9....Egq.Z...<7....l."y..5...`5`.&O.uBa.4VC...(.X.IX.c3A...B...w.....f5..`u.3.4..d.../.m.}...e..'9..f.^h........2..m..iM.".3..X..#.....E..%.)."..+'tF.5TR.......F......>.L..qQ}......4...-..TS.+...'.....z...M.g..Q...
'...l.wj.u...D.8..a.;.f.el!lkV$k...Rce[..$.9L....h
..A..o.......z...P..Nf7..2..!.1'......y.....c......?...s...........K...yDS\p.....|)...9I...v,c.....#.>&..C..h...; ..E..H.QDQ...W...4!)F.M..X9~..7.
p\...L5......RH.........-.6.b..C..;,9& x.C...W
_...sX..#0..../..#..EY..uP.`..[P...d..7...V..!(.Q..r&0.....ys....A.u....K[...Z.0_..t.P.D....W.....I.d.7H&.n.........3....2....'...a?1..D........X.....\..;..w;.......J......(.r.m...^7j.A..+...l.....l.|........UU.2R3......6M._..Q..w
<.n....q......l.....#.b.r.....t+=..........`....,(.bN
U.dkt.d.#........*.F.V.\eQ....2.+.4 .....?....7.+.1...<>........u.K..fS/|....`..,......C....C........z;.O...p......5..d.j..T.
_%+)H'&......:.Y..=..........Cw....Q........j.Y[9n..O.nS**@3...~4@........qmb[c&.=Q..2.......+.U...J.!P......3ho...i0.R.!.f8iU..Q.p..ui......~.y..U.u.E$J9...|O...^@...>f.s..v1....!.v..s8..0..`Nq......ZC.
...K,......m...<...a...

0

我理解的唯一区别是:我不是将gzip作为Accept-Encoding发送,但即使我这样做,我也会得到完全相同的消息。有人能找到这里出了什么问题吗?

额外信息:

如果我从请求中删除了öüűőßä这样的特殊字符,我会收到有效的回复。我认为问题与这些角色有关,但老实说我不知道​​是什么,因为我发送它是UTF-8而UTF-8包含这些字符如果我没有弄错?

2 个答案:

答案 0 :(得分:1)

另外两件事是不同的

  1. 您没有通过套接字发送用户代理
  2. 两个请求的内容长度不同。
  3. 此外,您的套接字响应报告:

    Content-Type: text/xml;charset=UTF-8
    Transfer-Encoding: chunked
    

    而soapui回应报告:

    Content-Encoding: gzip
    Content-Type: text/xml;charset=utf-8
    Transfer-Encoding: chunked
    

    尝试接受gzip并查看是否会更改您收到的响应消息。

答案 1 :(得分:0)

我发现了问题。这是显而易见的,但我无法找到它。所以我有一个看起来像的HTTP标头:

Content-Length: request.length()\r\n

实际上是请求字符串中的字符数。为了解决这个问题,我实际上需要这个标题看起来像这样:

final byte[] RequestBytes = request.getBytes(Charset.forName("UTF-8"));
Content-Length: RequestBytes.length\r\n