Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 55DF817F4C for ; Mon, 2 Mar 2015 18:33:07 +0000 (UTC) Received: (qmail 93055 invoked by uid 500); 2 Mar 2015 18:33:01 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 93003 invoked by uid 500); 2 Mar 2015 18:33:01 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 92994 invoked by uid 99); 2 Mar 2015 18:33:01 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Mar 2015 18:33:01 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DE1C7E03C8; Mon, 2 Mar 2015 18:33:00 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: dhirajsb@apache.org To: commits@camel.apache.org Message-Id: <2ce469032da4406086bd8b911f3ae446@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: camel git commit: CAMEL-8425: fixed invalid client id handling, added integration test for same Date: Mon, 2 Mar 2015 18:33:00 +0000 (UTC) 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 Authored: Mon Mar 2 10:32:43 2015 -0800 Committer: Dhiraj Bokde 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
+ 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 headers = new HashMap(); + // 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"); + } + }; + } +}