我有一个非常专业的环境,我的任务是通过套接字发送以下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包含这些字符?

最佳答案

另外两件事是不同的


您不是通过套接字发送用户代理
两个请求的内容长度不同。


另外,您的套接字响应报告:

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,然后查看是否会更改您收到的响应消息。

08-27 23:36
查看更多