我尝试使用Netty 4.0收到以下消息,但在prolog中继续获得意外的字符。
信息如下:
Content-Type: multipart/related; boundary="-=Part.0.18fc51f6-a22b-4759-b186-5fa473d479c4=-"; type="text/xml"; start="<0>"; start-info="text/xml"
---=Part.0.1e843708-4576-408e-be3a-f33185bff722=-
Content-Type: text/xml; charset=UTF-8
Content-ID: <0>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:eb="http://www.oasis-open.org/committees/ebxml-msg/schema/msg-header-2_0.xsd" xmlns:xlink="http://www.w3.org/1999/xlink">
<soap:Header>
<eb:MessageHeader eb:version="2.0" soap:mustUnderstand="1">
<eb:From>
<eb:PartyId eb:type="urn:osb:oin">00000003273229750000</eb:PartyId>
<eb:Role>BevoegdGezag</eb:Role>
</eb:From>
<eb:To>
<eb:PartyId eb:type="urn:osb:oin">00000005123456782000_OTA</eb:PartyId>
<eb:Role>LVO</eb:Role>
</eb:To>
<eb:CPAId>CPAID_ST_OLO_0312_SSL</eb:CPAId>
<eb:ConversationId>67643250</eb:ConversationId>
<eb:Service eb:type="urn:osb:services">LVO:2:0:0:I</eb:Service>
<eb:Action>Fo01</eb:Action>
<eb:MessageData>
<eb:MessageId>67643250@soapuimockserver</eb:MessageId>
<eb:Timestamp>2017-10-14T07:54:08Z</eb:Timestamp>
<eb:TimeToLive>2017-10-15T10:54:09Z</eb:TimeToLive>
</eb:MessageData>
<eb:DuplicateElimination/>
</eb:MessageHeader>
<eb:AckRequested eb:signed="false" eb:version="2.0" soap:actor="urn:oasis:names:tc:ebxml-msg:actor:toPartyMSH" soap:mustUnderstand="1"/>
</soap:Header>
<soap:Body>
<eb:Manifest eb:version="2.0">
<eb:Reference xlink:href="cid:1" xlink:type="simple"/>
</eb:Manifest>
</soap:Body>
</soap:Envelope>
---=Part.0.1e843708-4576-408e-be3a-f33185bff722=-
Content-Type: text/xml
Content-Transfer-Encoding: binary
Content-ID: <1>
<StUF:Fo01Bericht xmlns:StUF="http://www.egem.nl/StUF/StUF0301" xmlns:BG="http://www.egem.nl/StUF/sector/bg/0310" xmlns:LVO="http://www.egem.nl/StUF/sector/lvo/0311" xmlns:smil20="http://www.w3.org/2001/SMIL20/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:gml="http://www.opengis.net/gml" xmlns:sch="http://www.ascc.net/xml/schematron" xmlns:ZKN="http://www.egem.nl/StUF/sector/zkn/0310" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:smil20lang="http://www.w3.org/2001/SMIL20/Language" xsi:schemaLocation="http://www.egem.nl/StUF/StUF0301 lvo0311msg.xsd">
<StUF:stuurgegevens>
<StUF:berichtcode>Fo01</StUF:berichtcode>
<StUF:zender>
<StUF:applicatie>SquitXO</StUF:applicatie>
</StUF:zender>
<StUF:ontvanger>
<StUF:applicatie>OLO</StUF:applicatie>
</StUF:ontvanger>
<StUF:referentienummer>67643250</StUF:referentienummer>
<StUF:tijdstipBericht>2017101409540300</StUF:tijdstipBericht>
<StUF:crossRefnummer>456</StUF:crossRefnummer>
</StUF:stuurgegevens>
<StUF:body>
<StUF:code>code0</StUF:code>
<StUF:plek>client</StUF:plek>
<StUF:omschrijving>omschrijving0</StUF:omschrijving>
</StUF:body>
</StUF:Fo01Bericht>
---=Part.0.1e843708-4576-408e-be3a-f33185bff722=---
但只有肥皂信封的信息很顺利。
我的设置直到现在都是这样。
public void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addLast(sslCtx.newHandler(ch.alloc()));
}
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpObjectAggregator(4*1024*1024));
p.addLast(new HttpResponseEncoder());
if(isCompressionDesired) {
p.addLast(new HttpContentCompressor(7));
}
p.addLast("idleStateHandler", new IdleStateHandler(0, 0, 60));
if( isAdmin ) {
p.addLast(new SnappyMockServerAdminHandler());
}
else {
p.addLast(new SnappyMockServerSimpleHandler());
}
}
我理解多部分消息需要用HttpPostRequestDecoder完成工作,但是我无法找到如何使用它。
HttpPostRequestDecoder似乎并不乐意与HttpRequestDecoder / HttpObjectAggregator相处,因为它们似乎相互矛盾。
任何想法如何实现这一目标?
答案 0 :(得分:0)
HttpPostRequestDecoder似乎并不乐意与HttpRequestDecoder / HttpObjectAggregator相处,因为它们似乎相互矛盾。
这是正确的HttpObjectAggregator
将HttpMessage及其所有HttpContents聚合到一个FullHttpRequest中,这是您在使用HttpPostRequestDecoder
时不想要的。 (Here is an example from netty's github on how to use the HttpPostRequestDecoder)
通过做这样的事情它应该有效:
public void initChannel(Channel channel) {
ChannelPipeline pipeline = channel.pipeline();
if (sslCtx != null)
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
pipeline.addLast(new HttpServerCodec());
if(isCompressionDesired)
pipeline.addLast(new HttpContentCompressor(7));
pipeline.addLast("idleStateHandler", new IdleStateHandler(0, 0, 60))
.addLast(isAdmin ? new SnappyMockServerAdminHandler() : new SnappyMockServerSimpleHandler());
}