在webMethods Java服务中获取请求对象

3

简单问题:

  • 我有一个webMethods“REST服务”(_post)。
  • 在“REST服务”服务中,我调用了一个自编写的Java服务。
  • 在Java服务内部,我想获取请求的原始主体。

有什么想法吗?

1个回答

3
根据“Content-Type”头,webMethods会选择一个“ContentHandler”来解析输入。这样的“ContentHandler”可以保留原始正文,但其方式不统一。
例如,对于“Content-Type: application/x-www-form-urlencoded”:
InvokeState is = InvokeState.getCurrentState();
byte[] bytesIn = (byte[])is.getPrivateData("$msgBytesIn");
String body = null;
if (bytesIn!=null) {
    body = new String(bytesIn, StandardCharsets.UTF_8);
}
// body now contains the request body

例子2,对于Content-Type: multipart/form-data

IDataCursor pipelineCursor = pipeline.getCursor();
InputStream bodyStream = (InputStream)IDataUtil.get( pipelineCursor, "contentStream" );
pipelineCursor.destroy();
// bodyStream now contains the request body

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接