Search code examples
javaweb-servicesservicerequestwebmethods

Get request object in webMethods Java service


Simple question:

  • I have a webMethods "REST-Service" (_post).
  • Inside the "REST-Service" service I call a self written java service.
  • Inside the java service I want to get the raw body of the request.

Any ideas?


Solution

  • Depending on the Content-Type header, webMethods chooses a ContentHandler to parse the inputs. The raw body can be preserved by such a ContentHandler, but it's not done in a uniform way.

    example 1, for 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
    

    example 2, for Content-Type: multipart/form-data:

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