Class WRSCaller

java.lang.Object
com.ptc.odata.windchill.internalinvoker.WRSCaller

public class WRSCaller extends Object
Helper class to make calls to WRS from a Java process.
Authentication, CSRF Nonce token, etc. is handled internally by this class.
WRS calls behave as they would if invoked from a "regular" HTTP client calling WRS from the outside:
- A parent Transaction encapsulating a WRSCaller invocation cannot rollback data modification made by WRSCaller (POST, PUT, PATCH, DELETE).
- Access controls of the current principal are honored.

A typical invocation looks like the following:
WRSCaller caller = new WRSCaller();
ODataSerializableResponse response = caller.get("ProdMgmt/Parts", new HashMapinvalid input: '<'>(), new HashMapinvalid input: '<'>());


Customization examples using WRSCaller are available in WT_HOME/prog_examples/WRSCallerExamples

Supported API: true

Extendable: false
  • Field Details

    • LINE_RETURN

      public static final String LINE_RETURN
      Line return with carriage return \r\n
      Supported API: true
      See Also:
  • Method Details

    • get

      public ODataSerializableResponse get(String endpoint, Map<String,String> queryParams, Map<String,String> headers) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a GET request to the specified endpoint, with the specified query parameters and request headers. Use this when calling OData Functions, or querying entity sets.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$filter"="Name eq 'GOLF_CART'", "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format, unless it's a file download operation.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • post

      public ODataSerializableResponse post(String endpoint, Map<String,String> queryParams, Map<String,String> headers, org.json.JSONObject body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a POST request to the specified endpoint, with the specified JSON body and request headers. Use this when calling OData Actions, or when creating entities.

      To make batch requests, use batch(String, Map, String, String) instead.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      body - the request body as JSON object.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format, unless it's a file download operation.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • post

      public ODataSerializableResponse post(String endpoint, Map<String,String> queryParams, Map<String,String> headers, String body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a POST request to the specified endpoint, with the specified JSON body and request headers. Use this when calling OData Actions, or when creating entities.

      To make batch requests, use batch(String, Map, String, String) instead.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      body - the request body as JSON String.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format, unless it's a file download operation.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • batch

      public ODataSerializableResponse batch(String endpoint, Map<String,String> headers, String batchDelimiter, String body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Convenience method to make batch requests to the specified endpoint.
      Note that request body must be provided as a String and must be properly formatted, following the OData specifications.
      When uploading files, use invalid input: '{@link com.ptc.odata.windchill.internalinvoker.WRSCaller#batch(String, Map, String, byte[]))'} instead.

      Supported API: true
      Parameters:
      endpoint - the relative URL for the batch request (e.g. "/v6/ProdMgmt/$batch"). Must not include hostname or servlet name.
      headers - the request headers. Accept and Content-Type headers should not be passed.
      batchDelimiter - the delimiter used in the batch request (e.g.: "batch_request").
      body - the batch request body, as String. It must be properly formatted (i.e. contain the right delimiters).
      Returns:
      the batch response, as ODataSerializableResponse.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • batch

      public ODataSerializableResponse batch(String endpoint, Map<String,String> headers, String batchDelimiter, byte[] body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Convenience method to make batch requests to the specified endpoint.
      Use this method if files are being uploaded as part of the batch request.
      Note that request body must be provided as a byte array. The body must still be properly formatted according to the odata specifications, and files should be serialized appropriately (such as using ByteArrayOutputStream and Files.readAllBytes)
      Supported API: true
      Parameters:
      endpoint - the relative URL for the batch request (e.g. "/v6/ProdMgmt/$batch"). Must not include hostname or servlet name.
      headers - the request headers. Accept and Content-Type headers should not be passed.
      batchDelimiter - the delimiter used in the batch request (e.g.: "batch_request").
      body - the batch request body, as byte array. It must be properly formatted (i.e. contain the right delimiters).
      Returns:
      the batch response, as ODataSerializableResponse.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • put

      public ODataSerializableResponse put(String endpoint, Map<String,String> queryParams, Map<String,String> headers, org.json.JSONObject body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a PUT request to the specified endpoint, with the specified JSON body and request headers. Use this when replacing data for entities.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      body - the request body as JSON object.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • put

      public ODataSerializableResponse put(String endpoint, Map<String,String> queryParams, Map<String,String> headers, String body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a PUT request to the specified endpoint, with the specified JSON body and request headers. Use this when replacing data for entities.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      body - the request body as JSON String.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • patch

      public ODataSerializableResponse patch(String endpoint, Map<String,String> queryParams, Map<String,String> headers, org.json.JSONObject body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a PATCH request to the specified endpoint, with the specified JSON body and request headers. Use this when updating entities.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      body - the request body as JSON object.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • patch

      public ODataSerializableResponse patch(String endpoint, Map<String,String> queryParams, Map<String,String> headers, String body) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a PATCH request to the specified endpoint, with the specified JSON body and request headers. Use this when updating entities.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      queryParams - the query parameters as a map (e.g. "$select"="Identity")
      headers - the request headers. Accept and Content-Type headers should not be passed.
      body - the request body as JSON String.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body will be in a JSON format.
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException
    • delete

      public ODataSerializableResponse delete(String endpoint, Map<String,String> headers) throws org.apache.olingo.commons.api.ex.ODataException, WTException, IOException
      Makes a DELETE request to the specified endpoint, with the specified request headers. Use this when deleting entities.

      Supported API: true
      Parameters:
      endpoint - the relative URL (e.g. "/v6/ProdMgmt/Parts"). Must not include hostname or servlet name. May or may not include domain version.
      headers - the request headers. Accept and Content-Type headers should not be passed.
      Returns:
      the response for this request, as ODataSerializableResponse. Response body is null. To check successful deletion, check the status code (should be 204).
      Throws:
      org.apache.olingo.commons.api.ex.ODataException
      WTException
      IOException