Example #1
0
    /**
     * Retrieves the first request in the queue and builds the full REST URI
     * given the properties of this request before creating a new HTTP request,
     * signing it, and sending it to the container.
     *
     * @param  client OpenSocialClient object with REST_BASE_URI property set
     * @return Object encapsulating the data requested from the container
     * @throws OpenSocialRequestException
     * @throws JSONException
     * @throws OAuthException
     * @throws IOException
     * @throws URISyntaxException
     */
    private OpenSocialResponse submitRest(OpenSocialClient client)
    {
        String restBaseUri =
            client.getProperty(OpenSocialClient.Properties.REST_BASE_URI);

        OpenSocialRequest r = this.requests[0];

        OpenSocialUrl requestUrl = new OpenSocialUrl(restBaseUri);

        requestUrl.addPathComponent(r.getRestPathComponent());
        if (r.getParameter("userId") != null)
        {
            requestUrl.addPathComponent(r.getParameter("userId"));
        }
        if (r.getParameter("groupId") != null)
        {
            requestUrl.addPathComponent(r.getParameter("groupId"));
        }
        if (r.getParameter("appId") != null)
        {
            requestUrl.addPathComponent(r.getParameter("appId"));
        }

        OpenSocialHttpRequest request = new OpenSocialHttpRequest(requestUrl);

        OpenSocialRequestSigner.signRequest(request, client);

        String responseString = getHttpResponse(request);

        return(OpenSocialJsonParser.getResponse(responseString, r.getId()));
    }
Example #2
0
    /**
     * Calls one of two private methods which submit the queued requests to the
     * container given the properties of the OpenSocialClient object passed in.
     *
     * @param  client OpenSocialClient object with REST_BASE_URI or RPC_ENDPOINT
     *                properties set
     * @return Object encapsulating the data requested from the container
     * @throws OpenSocialRequestException
     * @throws JSONException
     * @throws OAuthException
     * @throws IOException
     * @throws URISyntaxException
     */
    public OpenSocialResponse send(OpenSocialClient client)
    {
        if (this.requests.Count == 0)
        {
            throw new OpenSocialRequestException(
                      "One or more requests must be added before sending batch");
        }

        String rpcEndpoint =
            client.getProperty(OpenSocialClient.Properties.RPC_ENDPOINT);
        String restBaseUri =
            client.getProperty(OpenSocialClient.Properties.REST_BASE_URI);

        if (rpcEndpoint == null && restBaseUri == null)
        {
            throw new OpenSocialRequestException(
                      "REST base URI or RPC endpoint required");
        }

        if (rpcEndpoint != null)
        {
            return(this.submitRpc(client));
        }
        else
        {
            return(this.submitRest(client));
        }
    }
    /**
     * Extracts pertinent properties from passed OpenSocialClient object and
     * passes these along with OpenSocialHttpRequest object to a separate
     * method which does the actual signing.
     *
     * @param  request OpenSocialHttpRequest object which contains both the URL
     *         to sign as well as the POST body which must be included as a
     *         parameter when signing POST requests
     * @param  client OpenSocialClient object with various properties, both
     *         optional and required, used during the signing process
     * @throws OAuthException
     * @throws IOException
     * @throws URISyntaxException
     */
    public static void signRequest(
        OpenSocialHttpRequest request, OpenSocialClient client)
    {
        String token =
            client.getProperty(OpenSocialClient.Properties.TOKEN);
        String viewerId =
            client.getProperty(OpenSocialClient.Properties.VIEWER_ID);
        String consumerKey =
            client.getProperty(OpenSocialClient.Properties.CONSUMER_KEY);
        String consumerSecret =
            client.getProperty(OpenSocialClient.Properties.CONSUMER_SECRET);

        signRequest(request, token, viewerId, consumerKey, consumerSecret);
    }
Example #4
0
  /**
   * Extracts pertinent properties from passed OpenSocialClient object and
   * passes these along with OpenSocialHttpRequest object to a separate
   * method which does the actual signing.
   * 
   * @param  request OpenSocialHttpRequest object which contains both the URL
   *         to sign as well as the POST body which must be included as a
   *         parameter when signing POST requests
   * @param  client OpenSocialClient object with various properties, both
   *         optional and required, used during the signing process
   * @throws OAuthException
   * @throws IOException
   * @throws URISyntaxException
   */
  public static void signRequest(
      OpenSocialHttpRequest request, OpenSocialClient client)
    {

    String token =
      client.getProperty(OpenSocialClient.Properties.TOKEN);
    String viewerId =
      client.getProperty(OpenSocialClient.Properties.VIEWER_ID);
    String consumerKey =
      client.getProperty(OpenSocialClient.Properties.CONSUMER_KEY);
    String consumerSecret =
      client.getProperty(OpenSocialClient.Properties.CONSUMER_SECRET);

    signRequest(request, token, viewerId, consumerKey, consumerSecret);
  }
Example #5
0
    /**
     * Creates and submits a new request to retrieve the person or group of
     * people selected by the arguments and returns the response from the
     * container as an OpenSocialResponse object.
     *
     * @param  userId OpenSocial ID of the request's target
     * @param  groupId "@self" to fetch the user's profile details or "@friends"
     *         to fetch the user's friend list
     * @throws OpenSocialRequestException if there are any runtime issues with
     *         establishing a RESTful or JSON-RPC connection or parsing the
     *         response that the container returns
     * @throws JSONException
     * @throws OAuthException
     * @throws IOException
     * @throws URISyntaxException
     */
    private OpenSocialResponse fetchPeople(String userId, String groupId)
    {
        if (userId.Equals("") || groupId.Equals(""))
        {
            throw new OpenSocialRequestException("Invalid request parameters");
        }

        OpenSocialRequest r =
            OpenSocialClient.newFetchPeopleRequest(userId, groupId);

        OpenSocialBatch batch = new OpenSocialBatch();

        batch.addRequest(r, "people");

        return(batch.send(this));
    }
Example #6
0
    /**
     * Collects all of the queued requests and encodes them into a single JSON
     * string before creating a new HTTP request, attaching this string to the
     * request body, signing it, and sending it to the container.
     *
     * @param  client OpenSocialClient object with RPC_ENDPOINT property set
     * @return Object encapsulating the data requested from the container
     * @throws OpenSocialRequestException
     * @throws JSONException
     * @throws OAuthException
     * @throws IOException
     * @throws URISyntaxException
     */
    private OpenSocialResponse submitRpc(OpenSocialClient client)
    {
        String rpcEndpoint =
            client.getProperty(OpenSocialClient.Properties.RPC_ENDPOINT);

        JsonArray requestArray = new JsonArray();

        foreach (OpenSocialRequest r in this.requests)
        {
            requestArray.Put(JsonConvert.Import(r.getJsonEncoding()));
        }

        OpenSocialUrl requestUrl = new OpenSocialUrl(rpcEndpoint);

        OpenSocialHttpRequest request = new OpenSocialHttpRequest(requestUrl);

        request.setPostBody(requestArray.ToString());

        OpenSocialRequestSigner.signRequest(request, client);

        String responseString = getHttpResponse(request);

        return(OpenSocialJsonParser.getResponse(responseString));
    }
Example #7
0
  /**
   * Calls one of two private methods which submit the queued requests to the
   * container given the properties of the OpenSocialClient object passed in.
   * 
   * @param  client OpenSocialClient object with REST_BASE_URI or RPC_ENDPOINT
   *                properties set
   * @return Object encapsulating the data requested from the container
   * @throws OpenSocialRequestException
   * @throws JSONException
   * @throws OAuthException
   * @throws IOException
   * @throws URISyntaxException
   */
  public OpenSocialResponse send(OpenSocialClient client)
   {

    if (this.requests.Count == 0) {
      throw new OpenSocialRequestException(
          "One or more requests must be added before sending batch");
    }

    String rpcEndpoint =
      client.getProperty(OpenSocialClient.Properties.RPC_ENDPOINT);
    String restBaseUri =
      client.getProperty(OpenSocialClient.Properties.REST_BASE_URI);

    if (rpcEndpoint == null && restBaseUri == null) {
      throw new OpenSocialRequestException(
          "REST base URI or RPC endpoint required");
    }

    if (rpcEndpoint != null) {
      return this.submitRpc(client);
    } else {
      return this.submitRest(client);
    }
  }
Example #8
0
  /**
   * Retrieves the first request in the queue and builds the full REST URI
   * given the properties of this request before creating a new HTTP request,
   * signing it, and sending it to the container.
   * 
   * @param  client OpenSocialClient object with REST_BASE_URI property set
   * @return Object encapsulating the data requested from the container
   * @throws OpenSocialRequestException
   * @throws JSONException
   * @throws OAuthException
   * @throws IOException
   * @throws URISyntaxException
   */
  private OpenSocialResponse submitRest(OpenSocialClient client)
  {

    String restBaseUri =
      client.getProperty(OpenSocialClient.Properties.REST_BASE_URI);

    OpenSocialRequest r = this.requests[0];

    OpenSocialUrl requestUrl = new OpenSocialUrl(restBaseUri);

    requestUrl.addPathComponent(r.getRestPathComponent());
    if (r.getParameter("userId") != null) {
      requestUrl.addPathComponent(r.getParameter("userId"));
    }
    if (r.getParameter("groupId") != null) {
      requestUrl.addPathComponent(r.getParameter("groupId"));
    }
    if (r.getParameter("appId") != null) {
      requestUrl.addPathComponent(r.getParameter("appId"));
    }

    OpenSocialHttpRequest request = new OpenSocialHttpRequest(requestUrl);

    OpenSocialRequestSigner.signRequest(request, client);

    String responseString = getHttpResponse(request);
    return OpenSocialJsonParser.getResponse(responseString, r.getId());
  }
Example #9
0
  /**
   * Collects all of the queued requests and encodes them into a single JSON
   * string before creating a new HTTP request, attaching this string to the
   * request body, signing it, and sending it to the container.
   * 
   * @param  client OpenSocialClient object with RPC_ENDPOINT property set
   * @return Object encapsulating the data requested from the container
   * @throws OpenSocialRequestException
   * @throws JSONException
   * @throws OAuthException
   * @throws IOException
   * @throws URISyntaxException
   */
  private OpenSocialResponse submitRpc(OpenSocialClient client)
  {

    String rpcEndpoint =
      client.getProperty(OpenSocialClient.Properties.RPC_ENDPOINT);

    JsonArray requestArray = new JsonArray();
    foreach(OpenSocialRequest r in this.requests) {
        requestArray.Put(JsonConvert.Import(r.getJsonEncoding()));
    }

    OpenSocialUrl requestUrl = new OpenSocialUrl(rpcEndpoint);

    OpenSocialHttpRequest request = new OpenSocialHttpRequest(requestUrl);
    request.setPostBody(requestArray.ToString());

    OpenSocialRequestSigner.signRequest(request, client);

    String responseString = getHttpResponse(request);
    return OpenSocialJsonParser.getResponse(responseString);
  }