camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dhira...@apache.org
Subject camel git commit: CAMEL-8898: Added error handling for new LinkedIn OAuth behavior, also added w_share scope
Date Fri, 18 Sep 2015 07:46:08 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 483dafdbc -> efb28f1ce


CAMEL-8898: Added error handling for new LinkedIn OAuth behavior, also added w_share scope


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/efb28f1c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/efb28f1c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/efb28f1c

Branch: refs/heads/camel-2.15.x
Commit: efb28f1cec0cc1265ed09c8ec0271cad4626d7b2
Parents: 483dafd
Author: Dhiraj Bokde <dhirajsb@yahoo.com>
Authored: Fri Sep 18 00:42:58 2015 -0700
Committer: Dhiraj Bokde <dhirajsb@yahoo.com>
Committed: Fri Sep 18 00:44:07 2015 -0700

----------------------------------------------------------------------
 .../api/LinkedInOAuthRequestFilter.java         | 27 +++++++++++++++-----
 .../component/linkedin/api/OAuthScope.java      |  4 ++-
 2 files changed, 24 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/efb28f1c/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java
b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java
index d625bc5..7c5def9 100644
--- a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java
+++ b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/LinkedInOAuthRequestFilter.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.linkedin.api;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URL;
+import java.net.URLDecoder;
 import java.net.URLEncoder;
 import java.security.SecureRandom;
 import java.util.HashMap;
@@ -131,8 +132,8 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter
{
 
     @SuppressWarnings("deprecation")
     private String getRefreshToken() {
-        // authorize application on user's behalf
-        webClient.getOptions().setRedirectEnabled(true);
+        // disable redirect to avoid loading error redirect URL
+        webClient.getOptions().setRedirectEnabled(false);
 
         try {
             final String csrfId = String.valueOf(new SecureRandom().nextLong());
@@ -157,7 +158,24 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter
{
                 url = String.format(AUTHORIZATION_URL_WITH_SCOPE, oAuthParams.getClientId(),
csrfId,
                     builder.toString(), encodedRedirectUri);
             }
-            final HtmlPage authPage = webClient.getPage(url);
+            HtmlPage authPage;
+            try {
+                authPage = webClient.getPage(url);
+            } catch (FailingHttpStatusCodeException e) {
+                // only handle errors returned with redirects
+                if (e.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY) {
+                    final URL location = new URL(e.getResponse().getResponseHeaderValue(HttpHeaders.LOCATION));
+                    final String locationQuery = location.getQuery();
+                    if (locationQuery != null && locationQuery.contains("error="))
{
+                        throw new IOException(URLDecoder.decode(locationQuery).replaceAll("&",
", "));
+                    } else {
+                        // follow the redirect to login form
+                        authPage = webClient.getPage(location);
+                    }
+                } else {
+                    throw e;
+                }
+            }
 
             // look for <div role="alert">
             final HtmlDivision div = authPage.getFirstByXPath("//div[@role='alert']");
@@ -173,9 +191,6 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter
{
             password.setText(oAuthParams.getUserPassword());
             final HtmlSubmitInput submitInput = loginForm.getInputByName("authorize");
 
-            // disable redirect to avoid loading redirect URL
-            webClient.getOptions().setRedirectEnabled(false);
-
             // validate CSRF and get authorization code
             String redirectQuery;
             try {

http://git-wip-us.apache.org/repos/asf/camel/blob/efb28f1c/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java
b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java
index aadf353..3549061 100644
--- a/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java
+++ b/components/camel-linkedin/camel-linkedin-api/src/main/java/org/apache/camel/component/linkedin/api/OAuthScope.java
@@ -26,10 +26,12 @@ public enum OAuthScope {
     R_EMAILADDRESS("r_emailaddress"),
     R_NETWORK("r_network"),
     R_CONTACTINFO("r_contactinfo"),
+    @Deprecated // use W_SHARE instead
     RW_NUS("rw_nus"),
     RW_COMPANY_ADMIN("rw_company_admin"),
     RW_GROUPS("rw_groups"),
-    W_MESSAGES("w_messages");
+    W_MESSAGES("w_messages"),
+    W_SHARE("w_share");
 
     private final String value;
 


Mime
View raw message