简单问题:
- 我有一个 webMethods“REST 服务”(_post)。
- 在“REST-Service”服务中,我调用了一个自写的 Java 服务。
- 在 java 服务中,我想获取请求的原始主体。
有什么想法吗?
最佳答案
根据 Content-Type
header ,webMethods 选择一个 ContentHandler
来解析输入。原始主体可以通过这样的 ContentHandler
来保存,但是并没有以统一的方式完成。
示例 1,对于 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
关于java - 在 webMethods Java 服务中获取请求对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33546852/