gpt4 book ai didi

java - 通过套接字发送 XMLEncoded SOAP 请求导致无法创建信封

转载 作者:行者123 更新时间:2023-12-01 12:52:59 26 4
gpt4 key购买 nike

我有一个非常专业的环境,我的任务是通过套接字发送以下 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 header 再次从那里复制。最后,我可以使用 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 包含这些字符?

最佳答案

另外两件事是不同的

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

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

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 并查看这是否会改变您收到的响应消息。

关于java - 通过套接字发送 XMLEncoded SOAP 请求导致无法创建信封,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24079714/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com