webMethods

 View Only
Expand all | Collapse all

How to access HTTP request/response in an PLS service

  • 1.  How to access HTTP request/response in an PLS service

    Posted Fri May 29, 2020 06:12 AM

    Hello SAG community,
    we know how to access the HTTP context and control the HTTP request/response in a Java service:

    import com.wm.app.b2b.server.Service;
    ...
    Service.getHttpResponseHeader().setField("Content-Length", String.valueOf(result.getBytes().length));
    Service.setResponse(result.getBytes());

    How can we do the same in an AppPlatform service?

    Best regards,
    Marcus


    #webMethods-General
    #Application-Platform
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: How to access HTTP request/response in an PLS service

    Posted Tue June 02, 2020 01:05 PM

    Do you mean Integration Server? check documentation on service:
    pub.client:http


    #Integration-Server-and-ESB
    #webMethods-General
    #webMethods
    #Application-Platform


  • 3.  RE: How to access HTTP request/response in an PLS service

    Posted Wed June 03, 2020 07:47 AM

    Hello Tong,
    no, not using Flow services on Integration server, but Java’s own capabilities - just like the example shows for Java services.

    Best regards,
    Marcus


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB
    #Application-Platform


  • 4.  RE: How to access HTTP request/response in an PLS service

    Posted Sat June 06, 2020 12:33 PM

    if you talking about writing client in java directly, then java doc should be the place to check.
    are you using: java.net.HttpURLConnection ?
    you can use setRequestProperty to set header fields.


    #Application-Platform
    #webMethods-General
    #Integration-Server-and-ESB
    #webMethods


  • 5.  RE: How to access HTTP request/response in an PLS service

    Posted Tue June 09, 2020 06:05 AM

    Hi Tong,
    maybe my question was not unambiguous, so let me rephrase it to avoid misunderstandings:
    We know how to access the HTTP context of the REST call and control the HTTP request/response in a Java service when such a service is called via REST. How can we do the same in an AppPlatform service?

    Hence, I don’t want to fire a separate HTTP request, but want to access the HTTP context of the REST call which invoked the PLS service.

    Best regards,
    Marcus


    #Integration-Server-and-ESB
    #webMethods
    #webMethods-General
    #Application-Platform


  • 6.  RE: How to access HTTP request/response in an PLS service

    Posted Wed June 10, 2020 02:46 PM

    Hi Marcus,
    The answer depends on how you are invoking the App Platform OSGi service. Is this service annotated such that an IS flow service has been created and deployed to an IS package? In that case, you’d do the approach you are familiar with because in that case, the inbound REST call is coming to the Integration Server ( e.g. port 5555 ). If you are coming in from an OSGi web bundle WAB or a traditional Tomcat WAR project (e.g. port 8072) , you’d access the response via the Servlet API.)


    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB
    #Application-Platform


  • 7.  RE: How to access HTTP request/response in an PLS service

    Posted Thu June 11, 2020 02:34 PM

    Hi Warren,
    it’s an annotated IS service in an IS package:

    @Service
    @ExposeToIS(packageName="PackageName")
    public class ClassName {
    @ExposedMethod
    public String MethodName() {
    // code
    }
    }

    However, my very first idea was to do it the same way like in a conventional Java service, but when I want to import the com.wm.app.b2b.server.Service class, I get the error “com.wm.app.b2b.server.Service cannot be resolved to a type”.

    Best regards,
    Marcus

    PS: The approach for servlets is easy and straightforward. I implemented that several times meanwhile it is working perfectly.


    #webMethods-General
    #webMethods
    #Application-Platform
    #Integration-Server-and-ESB


  • 8.  RE: How to access HTTP request/response in an PLS service

    Posted Tue June 16, 2020 01:29 AM

    Hi Warren,
    do I have to add all additional libraries of an regular IS package manually to the Java Build Path of the PLS project in order to get it working?

    Best regards,
    Marcus


    #Integration-Server-and-ESB
    #webMethods-General
    #Application-Platform
    #webMethods


  • 9.  RE: How to access HTTP request/response in an PLS service

    Posted Thu June 18, 2020 02:49 PM

    Hi Marcus, you can’t reference ‘com.wm.app.b2b.server.Service’ from an OSGi App Platform (PLS service). The IS Service class is part of the Integration Server’s ServerClassLoader, and App Platform PLS services run as an OSGi bundle in the OSGi container. ( the server compoents for the App Platform product manage the interaction between your application services and the IS services.

    It may be a bit confusing because App Platform also supports running Tomcat WAR projects. Those WAR projects run in a Tomcat servlet container also hosted by the OSGi equinox container, so it is not a plain old Tomcat installation.

    So when you import library dependencies for your application, do not attempt to import Integration Server jars ( e.g. wm-isserver.jar ). This won’t work. So you can’t use the Service API to get to HTTP-related details in a PLS service project. -hth


    #Application-Platform
    #webMethods
    #Integration-Server-and-ESB
    #webMethods-General


  • 10.  RE: How to access HTTP request/response in an PLS service

    Posted Thu June 18, 2020 03:00 PM

    About your second question. You don’t want to add those libraries to your application service project. When you create your service project, you can click the ‘Add Library’ button on the right side of the ‘Java Build Path’ configuration( same panel in your screenshot above). Select add ‘Server runtime’ and select ‘Application Platform Integration Server (Remote)’ configuration. Doing this will add an Eclipse classpath container to your project containing the libraries included in an App Platform server installation. That includes everything you will need to annotate your OSGi services or create POJO service wrappers via the App Platform service wizard and publish your project to the server.

    When you have done this, if you open that classpath container, you can see it includes the bundles that are resident in the AP server container, so there is no need to bundle this jars in your project as they are already installed in the server. (Note, the screenshot does not show the complete set of jars included in the ‘server runtime’ classpath container.)


    #webMethods
    #Integration-Server-and-ESB
    #webMethods-General
    #Application-Platform


  • 11.  RE: How to access HTTP request/response in an PLS service

    Posted Fri June 19, 2020 05:29 AM

    Hi Warren,
    thank you for your answers!

    I thought so. Thanks for clarifying!

    Which API or library can I use then to access the HTTP context directly in the PLS service? I understood from your first answer (see below) that there is a way.

    Could you elaborate this way to access the HTTP context directly in a PLS service, please?

    Best regards,
    Marcus


    #webMethods
    #Application-Platform
    #webMethods-General
    #Integration-Server-and-ESB


  • 12.  RE: How to access HTTP request/response in an PLS service

    Posted Mon September 28, 2020 07:16 AM

    @Warren_Cooper
    Thank you for providing the APIExample archive with the demo projects! I’ve got some questions:

    1. Do such AP services always have to be registered manually with Jersey in order to be able to call it as REST service and access its Request and Response objects?

    2. If so, is there something else to be taken into account besides the registration in the main class and the Activator bean?

    3. Your example method unchunkySleep() shows how to access and write to the Response bean:

    	@Path("/sleepUnchunky")
    @GET
    public Response unchunkySleep() {
    ResponseBuilder responseBuilder = Response.status(Status.OK);
    responseBuilder.entity(sleep());
    responseBuilder.type("text/plain");        
    responseBuilder.header("Content-Length", "2");
    return responseBuilder.build();
    
    }
    

    Would we be able to access the Request bean as well if we added it to the method parameters?

    public Response unchunkySleep(Request Req) { ... }
    

    Because this is what we were looking for in the first place.

    Best regards,
    Marcus


    #Application-Platform
    #webMethods-General
    #webMethods
    #Integration-Server-and-ESB