Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
5 replies Latest Post - ‏2013-12-04T14:05:16Z by mburati
A.A.N.Naidu
A.A.N.Naidu
4 Posts
ACCEPTED ANSWER

Pinned topic Regarding REST SERVICES in WEF

‏2013-12-01T17:28:07Z |

Hi,

 I worked with wsdl earlier by using provider consumer model with service definition and webservice multiple operation builders.

But now i have to work with rest services,  I am having rest services which are live in my local machine. But not having idea about how to use those services in WEF. the examples which i found over wiki and internet are mostly about atom and RSS feeds only. i am looking for request based rest example

my REST service url will be  http://localhost:8086/service/feedback/provideFeedback  and the request name is ProvideFeedbackRequest . not sure which builder  have to use and how to provide the above inputs.

i am able to hit my rest service explictly from html using xmhttp.pls find the code below

var url = "http://localhost:8086/service/feedback/provideFeedback";

params ='<ProvideFeedbackRequest managerId="'+managerid+ '" projectName="'+projectTeam+ '"   quality="NA" comments="'+comments+'" empname="'+empname+'" empid = " '+empid+' "/>';   

        xmlhttp.open("POST", url, true); // async
        //Send the proper header information along with the request
        xmlhttp.setRequestHeader("Content-type", "application/xml");
        xmlhttp.setRequestHeader("Access-Control-Allow-Origin", "*");
        xmlhttp.send(params);
     Its working fine with HTMl explicit calling REST Service, can any body help me how to pass the same above inputs in builders and to call the REST service. please provide sample model for the above

Any help will be appreciated

 

  • mburati
    mburati
    2552 Posts
    ACCEPTED ANSWER

    Re: Regarding REST SERVICES in WEF

    ‏2013-12-02T16:01:43Z  in response to A.A.N.Naidu

    If you're trying to call an HTTP based request/response service that is not WSDL/SOAP specific (eg, RSS, Atom,  REST and/or other HTTP request that isn't WSDl/SOAP) then the REST Service Call builder should be able to help you out.     If you already have Java code to make the request then you could use a Linked Java Object builder to leverage that Java code.

    In the REST Service Call builder, you would choose the "POST"   HTTP Request Type,  set the Body Content Type to "application/xml"  (since your example xmlhttp request did the same,  and then you can choose "String" or "inputStream" for the Body Content Data Type.    According to the REST Service Call buidler help (url below)  setting it to String will generate an Input WEF Variable that has a bodyContent element in the XML variable where your String will go (and in your case, your XML string should be a child of that bodyContent element).   If you specify InputStream it would create a WEF variable where you would set an InputStream as the WEF Variable Object and it would read from that input stream (although that's meant more for sending files, not simple request data)).

    http://www-10.lotus.com/ldd/pfwiki.nsf/xpDocViewer.xsp?lookupName=Web+Experience+Factory+8+Documentation#action=openDocument&res_title=REST_Service_Call_builder_variables_and_inputs_wef8&content=pdcontent

    It may be difficult auto-generating the input schema for this since it's based on body content of the POST and not just based on a URL plus parameters, so you may need to uncheck Auto Create Schema.

    In the "Advanced" section you can set HTTP Headers, which is where you would set the additional http header that you're setting in your xmlhttp sample (Access-Control-Allow-Origin).

    You might try setting that up in the REST Service Call buidler and then using a Method builder to build up that XML string from arguments (managerId,ProjectName,comments,empname,empid)  which sets the bodyContent XML element child after generating that string and then use a Service Operation    builder to expose that Method as the operation that a consumer would call (instead of the REST operation directly) so that the consumer only has to deal with the individual input params and not the XML structure that your REST service input expects.

     

    I hope that info helps,

    ..Mike Burati 
    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
    • A.A.N.Naidu
      A.A.N.Naidu
      4 Posts
      ACCEPTED ANSWER

      Re: Regarding REST SERVICES in WEF

      ‏2013-12-03T13:06:11Z  in response to mburati

      Thanks mike for your valuable inputs.

      I performed the steps you suggested, After hitting the service from model  " i am getting error Message body is empty (response code 400)" .This means i think  i am not framing the request properly? I have taken an XML variable where i am filling with harcoded service request and passing the variable as value to the Body Content (in ServiceOperation->OperationInputs->InputFieldValues)

      I am attaching my sample(exported project as Web Experience Factory Zip Archive) . if possible can you please have a look and suggest your inputs

      Attachments

      • mburati
        mburati
        2552 Posts
        ACCEPTED ANSWER

        Re: Regarding REST SERVICES in WEF

        ‏2013-12-03T17:56:01Z  in response to A.A.N.Naidu

        Your sample model came close, thanks for providing that as a starting point for what you're trying to do.

        The doc could be a little more clear on how to deal with POST inputs, so I spent a little more time than I otherwise might've to make up for that, reworking your model a bit.   I'll ask that the doc be improved.

         - As noted in the builder inputs, the body content type is "String",  so you need to give it a String, not XML  (ie, if you have XML, convert it to a string first).   It would be nice if it did that for you, but it does not appear to at this time since it was told to expect a String.

         - You shouldn't have to build your own Test UI in a Service Provider model (Service Definition and Operations) - the Service Definition builder does that for you, so you can test the operations prior to letting the UI developer(s) (or yourself) build a UI consumer model against that,  so I disabled your UI builders and main and enabled Testing support in the Service Definition builder.

         - You want the Operation that the consumer calls to take individual arguments (eg, empId, resourceId etc),  build up the XML for that and then set its string representation into the Body content element of the XML variable created by the REST builder in its data service inputs, so I:

            - renamed your ActionList from newAL to  "provideFeedbackOperationAL"

            - changed the Svc Op to call that new action list instead of the real action created by the REST Service Call Builder

            - removed your hardcoded input in the Svc Op builder which was just assigning XML to an argument called BodyContent (where it really wants/expects a string within an XML element called BodyContent).

            - Changed the Action List to first assign into the REST builder generated input's body content (via the picker, makes it easier to match the structure it expects) and assign the String results of a new method called  getFeedbackRequestXMLAsString into that body content element in the auto-generated input variable

            - Passed in empId and resourceId as String arguments to both the Action List and the new method and the method call from the action list to the method.   Note, you'll need to add the rest of your args in these 3 places, to get the data all the way in from the consumer to the string rep of the XML. 

            - Changed your XML variable to a template for the XML structure of the input   (templateRequestStructure instead of sampV)

            - Have the new method fetch that template structure and assign the string args (empId, resourceId, ...) into that XML structure   and then return a toString of that whole structure (to the action list assignment that's calling that method via methodcall on the right hand side of the assignement statement into the XML input var generated by the REST builder.

        Ran it with the auto-generated service test framework and it appears to generate a POST body like what you're looking for.

        The model is attached,  you'll need to add the rest of your args where I added the initial ones.

        Sorry this was so hard to figure out from the doc.    If you use the pickers to assign things, it's easier to figure out what it's looking for and where (eg, the input structure it was expecting for the REST operation's inputs).

         - Note, you'll need to change the URL in the REST builder back to your URL - I had changed it to go through a TCP proxy monitor I had running, so I could see the http request being made.

         - I enabled Logging in the bottom of the REST builder - it'll now log the HTTP request headers, method type etc to your deployed WAR's WEB-INF/logs/debugTracing.txt.   Be sure to disable that before putting anything into production.

        I hope that info helps,
        ..Mike Burati 
        The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.

         

        Attachments

        • A.A.N.Naidu
          A.A.N.Naidu
          4 Posts
          ACCEPTED ANSWER

          Re: Regarding REST SERVICES in WEF

          ‏2013-12-04T13:35:27Z  in response to mburati

          Thanks Mike for spending your valuable time on my sample model. Your inputs are really informative and helped me to understand better.

          I am able to hit the REST service Successfully with proper request.

          I have only couple of queries left on this

          1)As we are calling service (DataServices/ProvideFeedbackRequest/execute) in the action list ( provideFeedbackOperationAL) !  after calling this service, I added a call for Page called ResultP. My intention is once after service call ,the result page should display. But some how once after service call the page is blank(not navigating to "ResultP" page .I have no control after service call :(

          2) How to handle the HTTP response header? I want to write a logic based based on the HTTP response header(result) .

              HTTP response header was printed in my debugTracing.txt and it looks like below

          Msg:      ServiceCall: HTTP.ResponseHeaders = <HTTPResponseHeaders><ResponseCode>200</ResponseCode>
          <ResponseMessage>OK</ResponseMessage>
          <Server>Apache-Coyote/1.1</Server>
          <Content-Length>81</Content-Length>
          <Content-Type>application/xml</Content-Type>
          <Date>Wed, 04 Dec 2013 12:47:35 GMT</Date>
          </HTTPResponseHeaders>
           

          Now I want to frame logic based on the <ResponseCode> of  HTTPResponseHeaders , so where i can get or access the HTTPResponseHeaders of my service?

          I am attaching my model ,If possible can you please have a look and suggest your inputs

          Current Model Flow-> FeedBackPage->SubmitB button action->FeedBackAL ->DataServices/FeedbackSD/hitFeedBack (service operation)->provideFeedbackOperationAL

           

          Attachments

          • mburati
            mburati
            2552 Posts
            ACCEPTED ANSWER

            Re: Regarding REST SERVICES in WEF

            ‏2013-12-04T14:05:16Z  in response to A.A.N.Naidu

            You typically should not be mixing your pages and page automation builder controls in a service provider model with the service definition/operations - those are there to define a service provider that a service consumer UI model then uses.   A provider operation shouldn't be dispatching to a page itself.    Typically you would get the provider operations working fully with the operation inputs and results first and then build a UI consumer model (separate model, leverages your provider via Service Consumer builder and then adds UI for those operations).

            If you're new to WEF, I recommend going through the Learning Roadmap and videos on the WEF Wiki (URL below), for these best practices and SOA layering concepts.   There are videos off that page that show service consumer/provider layering.

            Anyway, there are a couple things in your model to beware of, in addition to not mixing the UI in with the service operation itself.

             - The ActionList was set to return type Object, that should be changed to IXml    I didn't have access to your REST service, so my tweak of your model to make the REST Call didn't yet handle any results as I didn't know what you'd be getting back.

             - Your action list is calling a result page, but there was nothing putting anything on that page as far as I saw.

             - Since it's a POST, not a GET, it's not easy to get a sample result at design-time so it doesn't have a way to auto-generate a schema for the expected result.    If you have a sample result XML containing all the data element names, you may create an XML Variable builder with that data for sample result.   Then add a Simple Schema Generator builder to generate a schema for that variable.   Then you can specify that schema type as the result type in the REST Service Call builder and in the Service Operation builder result type inputs.

             - In the Action List that's the Svc Op,  instead of calling a page do a return statement returning the results of the data service it just executed.

             - Then try that all with the Service Definition testing support and if it's giving you back the results correctly for the operation, then that should be ready to build your separate UI consumer model from.

            As for response headers, according to the REST Service Call builder help, it adds those to <buildercallname>_replyHeaders variable that you may then leverage.    Unfortunately, I believe the java.net.HttpUrlConnection class that this builder leverages to do the real work tends to throw an Exception for non-2xx response codes so you may need to handle an exception calling the service rather than just relying on looking for the response code in that variable.   See the wiki and the builder help for handling errors.

            http://www-10.lotus.com/ldd/pfwiki.nsf/xpDocViewer.xsp?lookupName=Web+Experience+Factory+8+Documentation#action=openDocument&res_title=REST_Service_Call_builder_results_variables_wef8&content=pdcontent

            Please see how far you can get with that info plus the builder help, learning roadmap and wikis, and if you're still stuck after that try posting back with a variable containing the sample expected response data and someone may be able to help get you past the next step.

            I hope that info helps,
            ..Mike Burati 
            The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM.
            Updated on 2013-12-04T14:12:19Z at 2013-12-04T14:12:19Z by mburati