Package net.oauth.client

Examples of net.oauth.client.OAuthClient


        }
    }

    public void postInvoices(ArrayOfInvoice arrayOfInvoices) throws XeroClientException, XeroClientUnexpectedException {
        try {
            OAuthClient client = new OAuthClient(new HttpClient3());
            OAuthAccessor accessor = buildAccessor();
            String contactsString = XeroXmlManager.invoicesToXml(arrayOfInvoices);
            OAuthMessage response = client.invoke(accessor, OAuthMessage.POST, endpointUrl + "Invoices", OAuth.newList("xml", contactsString));
        } catch (OAuthProblemException ex) {
            throw new XeroClientException("Error posting invoices", ex);
        } catch (Exception ex) {
            throw new XeroClientUnexpectedException("", ex);
        }
View Full Code Here


        }
    }

    public void postPayments(ArrayOfPayment arrayOfPayment) throws XeroClientException, XeroClientUnexpectedException {
        try {
            OAuthClient client = new OAuthClient(new HttpClient3());
            OAuthAccessor accessor = buildAccessor();
            String paymentsString = XeroXmlManager.paymentsToXml(arrayOfPayment);
            OAuthMessage response = client.invoke(accessor, OAuthMessage.POST, endpointUrl + "Payments", OAuth.newList("xml", paymentsString));
        } catch (OAuthProblemException ex) {
            throw new XeroClientException("Error posting payments", ex);
        } catch (Exception ex) {
            throw new XeroClientUnexpectedException("", ex);
        }
View Full Code Here

        InputStream in = null;
        FileOutputStream out = null;

        try {

            OAuthClient client = new OAuthClient(new HttpClient3());
            OAuthAccessor accessor = buildAccessor();

            OAuthMessage request = accessor.newRequestMessage(OAuthMessage.GET, endpointUrl + "Invoices" + "/" + invoiceId, null);
            request.getHeaders().add(new OAuth.Parameter("Accept", "application/pdf"));
            OAuthResponseMessage response = client.access(request, ParameterStyle.BODY);


            file = new File("Invoice-" + invoiceId + ".pdf");

            if (response != null && response.getHttpResponse() != null && (response.getHttpResponse().getStatusCode() / 2) != 2) {
View Full Code Here

        OAuthServiceProvider provider;
        OAuthConsumer consumer;
        OAuthAccessor accessor;

        OAuthClient client = new OAuthClient(new URLConnectionClient());

        oAuthParams.setErrorMessage(null);
        String temporaryCredentialsEndpointUrl = oAuthParams.getTemporaryCredentialsEndpoint();
        if (temporaryCredentialsEndpointUrl == null || "".equals(temporaryCredentialsEndpointUrl)) {
            oAuthParams.setErrorMessage("Missing temporary credentials endpoint url");
        }
        String clientId = oAuthParams.getClientID();
        if (clientId == null || "".equals(clientId)) {
            oAuthParams.setErrorMessage("Missing client identifier");
        }
        String secret = oAuthParams.getClientSecret();
        if (secret == null || "".equals(secret)) {
            oAuthParams.setErrorMessage("Missing client shared-secret");
        }

        if (oAuthParams.getErrorMessage() == null) {
            provider = new OAuthServiceProvider(temporaryCredentialsEndpointUrl,
                oAuthParams.getResourceOwnerAuthorizationEndpoint(), oAuthParams.getTokenRequestEndpoint());
            consumer = new OAuthConsumer(null, clientId,
                secret,
                provider);
            accessor = new OAuthAccessor(consumer);

            Map<String, String> parameters = new HashMap<String, String>();
            parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod());
            parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
            parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
            parameters.put(OAuth.OAUTH_CALLBACK, oAuthParams.getCallbackURL());
            parameters.put("realm", "private");
            parameters.put("scope", "read_info modify_info");


            try {
                accessor.consumer
                    .setProperty(OAuthClient.PARAMETER_STYLE, ParameterStyle.AUTHORIZATION_HEADER);
                client.getRequestToken(accessor, OAuthMessage.POST, parameters.entrySet());
            } catch (Exception e) {
                oAuthParams.setErrorMessage(e.toString());
            }

            oAuthParams.setOauthToken(accessor.requestToken);
View Full Code Here

        if (verifier == null || "".equals(verifier)) {
            oAuthParams.setErrorMessage("Missing oauth verifier");
        }

        if (oAuthParams.getErrorMessage() == null) {
            OAuthClient client = new OAuthClient(new URLConnectionClient());
            OAuthServiceProvider provider = new OAuthServiceProvider(
                oAuthParams.getTemporaryCredentialsEndpoint(),
                oAuthParams.getResourceOwnerAuthorizationEndpoint(), tokenRequestEndpoint);

            OAuthConsumer consumer = new OAuthConsumer(null, clientID,
                oAuthParams.getClientSecret(),
                provider);
            OAuthAccessor accessor = new OAuthAccessor(consumer);
            accessor.requestToken = oauthToken;
            accessor.tokenSecret = Common.findCookieValue(request, "tokenSec");
           
            Map<String, String> parameters = new HashMap<String, String>();
            parameters.put(OAuth.OAUTH_SIGNATURE_METHOD, oAuthParams.getSignatureMethod());
            parameters.put(OAuth.OAUTH_NONCE, UUID.randomUUID().toString());
            parameters.put(OAuth.OAUTH_TIMESTAMP, String.valueOf(System.currentTimeMillis() / 1000));
            parameters.put(OAuth.OAUTH_TOKEN, oauthToken);
            parameters.put(OAuth.OAUTH_VERIFIER, oAuthParams.getOauthVerifier());


            try {
                client.getAccessToken(accessor, OAuthMessage.GET, parameters.entrySet());
                oAuthParams.setOauthToken(accessor.accessToken);
            } catch (Exception e) {
                oAuthParams.setErrorMessage(e.toString());
                oAuthParams.setOauthToken(oauthToken);
                return new ModelAndView("tokenRequest");
View Full Code Here

                .newRequestMessage(OAuthMessage.POST, oAuthParams.getPostResourceURL(),
                    parameters.entrySet());
        }


        OAuthClient client = new OAuthClient(new URLConnectionClient());

        msg = client.access(msg, ParameterStyle.QUERY_STRING);

        StringBuffer bodyBuffer = readBody(msg);

        oAuthParams.setResourceResponse(bodyBuffer.toString());
        String authHeader = msg.getHeader("WWW-Authenticate");
View Full Code Here

        OAuthAccessor accessor = new OAuthAccessor(consumer);

        OAuthMessage msg = accessor
            .newRequestMessage(method, url, params.entrySet());

        OAuthClient client = new OAuthClient(new URLConnectionClient());

        return client.access(msg, style);
    }
View Full Code Here

      params.add(new OAuth.Parameter((String) p.getKey(), (String) p
          .getValue()));
    }
    OAuthAccessor accessor = createOAuthAccessor();
    accessor.tokenSecret = props.getProperty("tokenSecret");
    OAuthClient client = new OAuthClient(
        new HttpClient4(new SingleClient()));
    return client.invoke(accessor, "GET", url, params);
  }
View Full Code Here

  }

  public void request() throws Exception {
    OAuthAccessor accessor = createOAuthAccessor();
    HttpClient4 httpClient = new HttpClient4(new SingleClient());
    OAuthClient client = new OAuthClient(httpClient);
    client.getRequestToken(accessor);
    props.setProperty("requestToken", accessor.requestToken);
    props.setProperty("tokenSecret", accessor.tokenSecret);
    updateProperties("Last action: added requestToken");
  }
View Full Code Here

        OAuthAccessor accessor = consumerDataObj.getAccessor();
        OAuthMessage message = accessor.newRequestMessage("POST", rpcServerUrl, null, bodyStream);
        message.getHeaders().add(
            new SimpleEntry<String, String>(HttpMessage.CONTENT_TYPE, "application/json"));
        message.getHeaders().add(new SimpleEntry<String, String>("oauth_version", "1.0"));
        OAuthClient client = new OAuthClient(httpFetcher);
        responseStream = client.invoke(message, net.oauth.ParameterStyle.BODY).getBodyAsStream();
      }

      String responseString = HttpFetcher.readInputStream(responseStream);
      LOG.info("Response returned: " + responseString);
View Full Code Here

TOP

Related Classes of net.oauth.client.OAuthClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.