You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dh...@apache.org on 2015/03/02 19:33:00 UTC
camel git commit: CAMEL-8425: fixed invalid client id handling,
added integration test for same
Repository: camel
Updated Branches:
refs/heads/master 934d0f14a -> 69fd8434b
CAMEL-8425: fixed invalid client id handling, added integration test for same
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/69fd8434
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/69fd8434
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/69fd8434
Branch: refs/heads/master
Commit: 69fd8434b052461437807f5f51f9c7aefb5151aa
Parents: 934d0f1
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Mon Mar 2 10:32:43 2015 -0800
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Mon Mar 2 10:32:55 2015 -0800
----------------------------------------------------------------------
.../api/LinkedInOAuthRequestFilter.java | 18 +++++
.../api/AbstractResourceIntegrationTest.java | 2 +-
.../ComponentConfigurationIntegrationTest.java | 83 ++++++++++++++++++++
3 files changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/69fd8434/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 ed11944..d625bc5 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
@@ -42,12 +42,15 @@ import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.WebClientOptions;
import com.gargoylesoftware.htmlunit.WebRequest;
import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
+import com.gargoylesoftware.htmlunit.util.WebConnectionWrapper;
+import org.apache.http.HttpHeaders;
import org.apache.http.HttpHost;
import org.apache.http.HttpStatus;
import org.apache.http.conn.params.ConnRoutePNames;
@@ -107,6 +110,15 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter {
options.setProxyConfig(proxyConfig);
}
+ // disable default gzip compression, as error pages are sent with no compression and htmlunit doesn't negotiate
+ new WebConnectionWrapper(webClient) {
+ @Override
+ public WebResponse getResponse(WebRequest request) throws IOException {
+ request.setAdditionalHeader(HttpHeaders.ACCEPT_ENCODING, "identity");
+ return super.getResponse(request);
+ }
+ };
+
if (!lazyAuth) {
try {
updateOAuthToken();
@@ -147,6 +159,12 @@ public final class LinkedInOAuthRequestFilter implements ClientRequestFilter {
}
final HtmlPage authPage = webClient.getPage(url);
+ // look for <div role="alert">
+ final HtmlDivision div = authPage.getFirstByXPath("//div[@role='alert']");
+ if (div != null) {
+ throw new IllegalArgumentException("Error authorizing application: " + div.getTextContent());
+ }
+
// submit login credentials
final HtmlForm loginForm = authPage.getFormByName("oauth2SAuthorizeForm");
final HtmlTextInput login = loginForm.getInputByName("session_key");
http://git-wip-us.apache.org/repos/asf/camel/blob/69fd8434/components/camel-linkedin/camel-linkedin-api/src/test/java/org/apache/camel/component/linkedin/api/AbstractResourceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-api/src/test/java/org/apache/camel/component/linkedin/api/AbstractResourceIntegrationTest.java b/components/camel-linkedin/camel-linkedin-api/src/test/java/org/apache/camel/component/linkedin/api/AbstractResourceIntegrationTest.java
index b0f3ad8..55405a2 100644
--- a/components/camel-linkedin/camel-linkedin-api/src/test/java/org/apache/camel/component/linkedin/api/AbstractResourceIntegrationTest.java
+++ b/components/camel-linkedin/camel-linkedin-api/src/test/java/org/apache/camel/component/linkedin/api/AbstractResourceIntegrationTest.java
@@ -35,7 +35,7 @@ import org.slf4j.LoggerFactory;
/**
* Base class for resource tests.
*/
-public class AbstractResourceIntegrationTest extends Assert {
+public abstract class AbstractResourceIntegrationTest extends Assert {
protected static final Logger LOG = LoggerFactory.getLogger(PeopleResourceIntegrationTest.class);
protected static final String DEFAULT_FIELDS = "";
http://git-wip-us.apache.org/repos/asf/camel/blob/69fd8434/components/camel-linkedin/camel-linkedin-component/src/test/java/org/apache/camel/component/linkedin/ComponentConfigurationIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-linkedin/camel-linkedin-component/src/test/java/org/apache/camel/component/linkedin/ComponentConfigurationIntegrationTest.java b/components/camel-linkedin/camel-linkedin-component/src/test/java/org/apache/camel/component/linkedin/ComponentConfigurationIntegrationTest.java
new file mode 100644
index 0000000..3c8e6d3
--- /dev/null
+++ b/components/camel-linkedin/camel-linkedin-component/src/test/java/org/apache/camel/component/linkedin/ComponentConfigurationIntegrationTest.java
@@ -0,0 +1,83 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * Camel Api Route test generated by camel-component-util-maven-plugin
+ * Generated on: Wed Jul 09 19:57:10 PDT 2014
+ */
+package org.apache.camel.component.linkedin;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.linkedin.internal.CommentsResourceApiMethod;
+import org.apache.camel.component.linkedin.internal.LinkedInApiCollection;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Test class for component configuration validation.
+ */
+public class ComponentConfigurationIntegrationTest extends AbstractLinkedInTestSupport {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ComponentConfigurationIntegrationTest.class);
+ private static final String PATH_PREFIX = LinkedInApiCollection.getCollection().getApiName(CommentsResourceApiMethod.class).getName();
+
+ @Override
+ protected CamelContext createCamelContext() throws Exception {
+ final CamelContext camelContext = super.createCamelContext();
+ // replace client id with invalid value
+ camelContext.getComponent("linkedin", LinkedInComponent.class).getConfiguration().setClientId("bad_client_id");
+ return camelContext;
+ }
+
+ @Test
+ public void testGetComment() throws Exception {
+ final Map<String, Object> headers = new HashMap<String, Object>();
+ // parameter type is String
+ headers.put("CamelLinkedIn.comment_id", "123");
+ // parameter type is String
+ headers.put("CamelLinkedIn.fields", "");
+
+ try {
+ requestBodyAndHeaders("direct://GETCOMMENT", null, headers);
+ fail("Bad client Id must cause an exception on first message");
+ } catch (CamelExecutionException e) {
+ Throwable t = e;
+ while (t.getCause() != null && t.getCause() != t) {
+ t = t.getCause();
+ }
+ if (!(t instanceof IllegalArgumentException)) {
+ throw e;
+ }
+ }
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ // dummy test route for getComment
+ from("direct://GETCOMMENT")
+ .to("linkedin://" + PATH_PREFIX + "/getComment");
+ }
+ };
+ }
+}