How to access xCP stateless process resource through REST webservice

Options
srinivasa_prasad_a
edited October 13, 2014 in Documentum #1

I have access one of my xCP 2.1 project stateless process resource through REST webservice.

{

  • "id": "types/processes.json/xcp_getfolderid",
  • "title": "xcp_getfolderid",
  • "summary": "get Folder Id From Folder Path",
  • "updated": "2014-05-26T08:03:35.765-04:00",
  • "content": {
    • "content-type": "application/vnd.emc.xcp+json",
    • "src": "types/processes.json/xcp_getfolderid"
    },
  • "links": [
    • {
      • "rel": "self",
      • "href": "types/processes.json/xcp_getfolderid"
      }
    ]

}

where the process needs input parameters as folder path/name/type/id.

How to pass the input parameters to below URL http://****.****.com:8080/MYAPP/types/processes.json/xcp_getfolderid to get the folder id response.

Right now I am getting error as

<dm:error><dm:status>404</dm:status><dm:code>E_RESOURCE_NOT_FOUND</dm:code><dm:message>Operation on object failed because the specified resource by ID, name, type or path is not found</dm:message><dm:details/></dm:error>

Thanks,

Srini

Comments

  • Sandor
    edited June 23, 2014 #2
    Options

    Hi Srini,

    You are trying to start the stateless process by calling the definition of the process; note the 'types' entry in your URL.

    You should try a POST to the instances URL:

    http://****.****.com:8080/MYAPP/processes/xcp_getfolderid

    The JSON body:

    { "run-stateless" : "true",

      "data" : {

      "variables" : {

                    "folder_path" : "/Temp"

        }

    }

    }

    Good luck!

    Cheers,

    Sandor

  • NiallSynapps
    edited August 6, 2014 #3
    Options

    Hey Sandor,

    Trying to call an SP from another SP using Send HTTP/RESTful request.  Have you seen any examples on how to do this?

    Cheers Niall

  • Koen_Verheyen
    edited August 6, 2014 #4
    Options

    Hello Niall,

    Why would you do this, if you can just call a stateless process using the "Call Stateless Process" activity.

    Friendly Regards,

    Koen Verheyen.

  • NiallSynapps
    edited August 6, 2014 #5
    Options

    To call an SP in another xCP app.

    Niall

  • NiallSynapps
    edited August 6, 2014 #6
    Options

    Apparently there is a REST API generated for SP’s in xCP2.1, however I can't find any info on how to call them, other than this post.


    I forgot that most of the Netherlands will be on holiday so probably won't get anything from Sandor on this.


    Niall

  • Koen_Verheyen
    edited August 6, 2014 #7
    Options

    One can share Stateless Processes over applications by using projects.

  • NiallSynapps
    edited August 6, 2014 #8
    Options

    That's not what I want.  I want to be able to deploy mini-xCP apps that contain sets of services that are consumed at run-time by other xCP apps.

    Niall.

  • dnvhariprasad
    edited August 21, 2014 #9
    Options

    Even in that case, you can use sub-projects and call the stateless process across applications. After all stateless processes are normal REST services, you can very well use JSON libraries in your java module (assuming you are using java services) and call the stateless processes.  However authorization would be a challenge if you want to use completely different applications.

  • NiallSynapps
    edited August 21, 2014 #10
    Options

    Yes - but I don't want the tight coupling between the projects.

    http(s)://<host>:<port>//<your app>/processes/<your process name> or for a specific instance

    http(s)://<host>:<port>//<your app>/processes/<your process name>/<r_object_id>

    JSON request is constructed in the following format:

    {

         "name" : "process",

         "type" : "<your process name>",

         "run-stateless" : "true",

         "data" : {

              "variables": {

                   "<your int variable> : "3",

                   "<your string variable> : "String",

                   "<your multi-value var> : ["A","B","C"]

                                  }

                   }

    }

    Authentication from another xCP process is OK (in most cases) because you can get a ticket and pass that through with the user name in the JSON.

    Niall

  • dnvhariprasad
    edited August 21, 2014 #11
    Options

    following is the code we used (we used for Unit Testing and you can use the same for normal java as well).  This will help you in passing parameters.

    Libraries we used

    import com.jayway.restassured.http.ContentType;

    import org.junit.Test;

    import static org.hamcrest.Matchers.hasItem;


    private final static String GET_REQUEST = "/application/processes/" + "<process_name>";


        private final static String INPUT_PARAM_TYPE = "type";


        private final static String INPUT_PARAM_TYPE_VALUE = "xxxxxx_initiate_staless_ds";


        private final static String OUTPUT_PARAM_ITEMS_DISPLAY = "items.display";
        private final static String OUTPUT_PARAM_ITEMS_VALUE = "items.value";


        private final static String OUTPUT_PARAM_ITEMS_DISPLAY_VALUE = "<value to be passed>";
        private final static String OUTPUT_PARAM_ITEMS_VALUE_VALUE = "<value to be passed>";


        @Test
        public void getProjectContainers() {
            request(true).
                    contentType(ContentType.JSON).
                    queryParam(INPUT_PARAM_TYPE, INPUT_PARAM_TYPE_VALUE).
                expect().
                    contentType(ContentType.JSON).
                    body(OUTPUT_PARAM_ITEMS_DISPLAY, hasItem(OUTPUT_PARAM_ITEMS_DISPLAY_VALUE)).
                    body(OUTPUT_PARAM_ITEMS_VALUE, hasItem(OUTPUT_PARAM_ITEMS_VALUE_VALUE)).
                    statusCode(200).
                when().
                    log().all(true).
                    get(GET_REQUEST);


            //http://10.131.225.177:8000/<app_name>/application/processes
            // /xxxx_containers_initiate?
            // _dc=1373980393574&type=xxxxx_staless_ds
        }
  • Sandor
    edited August 25, 2014 #12
    Options

    Hi Niall,

    Indeed, I was on Holidays!

    You can use the send HTTP/RESTful Request activity to call other Stateless Process that are exposed as REST service.

    Tips:

    Use the POST prototcol

    Don't use Multipart/Formdata

    Make sure the Headings are mapped correctly (e.g. Authorization and Content-Type)

    Map the JSON body as String-to-Byte

    And of course, use the correct URL mapping.

    This should work (it did for me).

    Good luck!

    Sandor

  • NiallSynapps
    edited September 4, 2014 #13
    Options

    Hey Sandor - great to hear from you again.

    That's exactly what I've done and it worked for me to.

    Thanks for your help.

    Niall

  • NiallSynapps
    edited September 4, 2014 #14
    Options

    Hi Hari,

    Thanks for your help and the code snippet.  Although we didn't use your approach we will definitely be using it when calling out to other non-xCP services.

    Excellent.

    Cheers Niall

  • Vanson_Crasta
    edited October 13, 2014 #15
    Options

    Hi Sandor,

    I am getting 404 error when invoking the stateless process.

    Could you please throw in more details?

    What should be the values for

    Header >

         1. User- Agent

         2. Content-Type

         3. Content- Encoding

    Body >

         1. Content-Type

         2. Data (For - string-to-byte what should be the 2nd parameter. Should it be 'UTF-8' or something else)