Examples of OAuthClient


Examples of net.oauth.client.OAuthClient

    }

    public void postContacts(ArrayOfContact arrayOfContact) throws XeroClientException, XeroClientUnexpectedException {
        try {
            String contactsString = XeroXmlManager.contactsToXml(arrayOfContact);
            OAuthClient client = new OAuthClient(new HttpClient3());
            OAuthAccessor accessor = buildAccessor();
            OAuthMessage response = client.invoke(accessor, OAuthMessage.POST, endpointUrl + "Contacts", OAuth.newList("xml", contactsString));
        } catch (OAuthProblemException ex) {
            throw new XeroClientException("Error posting contancts", ex);
        } catch (Exception ex) {
            throw new XeroClientUnexpectedException("", ex);
        }
View Full Code Here

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

Examples of net.oauth.client.OAuthClient

        }
    }

    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

Examples of net.oauth.client.OAuthClient

        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

Examples of net.oauth.client.OAuthClient

        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

Examples of net.oauth.client.OAuthClient

        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

Examples of net.oauth.client.OAuthClient

                .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

Examples of net.oauth.client.OAuthClient

        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

Examples of org.apache.amber.oauth2.client.OAuthClient

            .setClientSecret(Common.CLIENT_SECRET)
            .setUsername(Common.USERNAME)
            .setPassword(Common.PASSWORD)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());

        OAuthJSONAccessTokenResponse response = oAuthClient.accessToken(request);

        assertNotNull(response.getAccessToken());
    }
View Full Code Here

Examples of org.apache.amber.oauth2.client.OAuthClient

            .tokenLocation(Common.ACCESS_TOKEN_ENDPOINT)
            .setGrantType(GrantType.PASSWORD)
            .setClientId(Common.CLIENT_ID)
            .buildBodyMessage();

        OAuthClient oAuthClient = new OAuthClient(new URLConnectionClient());
        OAuthClientResponse response = null;

        try {
            oAuthClient.accessToken(request);
            fail("exception expected");
        } catch (OAuthProblemException e) {
            assertEquals(OAuthError.TokenResponse.INVALID_REQUEST, e.getError());
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.