You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/10/09 09:46:55 UTC
[1/4] git commit: CAMEL-7899 Fixed the issue that camel-jetty doesn't
support multiple http method for the rest service
Repository: camel
Updated Branches:
refs/heads/master 399153be9 -> 6fd10088a
CAMEL-7899 Fixed the issue that camel-jetty doesn't support multiple http method for the rest service
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/892d3696
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/892d3696
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/892d3696
Branch: refs/heads/master
Commit: 892d3696e4f4949242ca94ee5f61f820c80061d5
Parents: 399153b
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Oct 9 15:36:45 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 15:36:45 2014 +0800
----------------------------------------------------------------------
.../camel/component/http/CamelServlet.java | 4 ++--
.../HttpServletResolveConsumerStrategy.java | 6 ++++-
.../component/jetty/JettyHttpComponent.java | 5 +++-
.../jetty/rest/RestJettyPojoInOutTest.java | 15 ++++++++++++
.../servlet/rest/RestServletPojoInOutTest.java | 24 ++++++++++++++++++++
5 files changed, 50 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/892d3696/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
index f70b57b..b6cece8 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/CamelServlet.java
@@ -179,12 +179,12 @@ public class CamelServlet extends HttpServlet {
public void connect(HttpConsumer consumer) {
log.debug("Connecting consumer: {}", consumer);
- consumers.put(consumer.getPath(), consumer);
+ consumers.put(consumer.getEndpoint().getEndpointUri(), consumer);
}
public void disconnect(HttpConsumer consumer) {
log.debug("Disconnecting consumer: {}", consumer);
- consumers.remove(consumer.getPath());
+ consumers.remove(consumer.getEndpoint().getEndpointUri());
}
public String getServletName() {
http://git-wip-us.apache.org/repos/asf/camel/blob/892d3696/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
index dee20c3..de7ed4a 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpServletResolveConsumerStrategy.java
@@ -34,7 +34,11 @@ public class HttpServletResolveConsumerStrategy implements ServletResolveConsume
if (answer == null) {
for (String key : consumers.keySet()) {
- if (consumers.get(key).getEndpoint().isMatchOnUriPrefix() && path.startsWith(key)) {
+ //We need to look up the consumer path here
+ String consumerPath = consumers.get(key).getPath();
+ HttpConsumer consumer = consumers.get(key);
+ // Just make sure the we get the right consumer path first
+ if (consumerPath.equals(path) || (consumer.getEndpoint().isMatchOnUriPrefix() && path.startsWith(consumerPath))) {
answer = consumers.get(key);
break;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/892d3696/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
index d006577..750be5d 100644
--- a/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
+++ b/components/camel-jetty/src/main/java/org/apache/camel/component/jetty/JettyHttpComponent.java
@@ -162,7 +162,6 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
List<Filter> filters = resolveAndRemoveReferenceListParameter(parameters, "filtersRef", Filter.class);
Long continuationTimeout = getAndRemoveParameter(parameters, "continuationTimeout", Long.class);
Boolean useContinuation = getAndRemoveParameter(parameters, "useContinuation", Boolean.class);
- String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParametersRef", SSLContextParameters.class);
@@ -179,10 +178,14 @@ public class JettyHttpComponent extends HttpComponent implements RestConsumerFac
String address = remaining;
URI addressUri = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(address));
URI endpointUri = URISupport.createRemainingURI(addressUri, parameters);
+ // need to keep the httpMethodRestrict parameter for the endpointUri
+ String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
// restructure uri to be based on the parameters left as we dont want to include the Camel internal options
URI httpUri = URISupport.createRemainingURI(addressUri, parameters);
// create endpoint after all known parameters have been extracted from parameters
JettyHttpEndpoint endpoint = new JettyHttpEndpoint(this, endpointUri.toString(), httpUri);
+
+
if (headerFilterStrategy != null) {
endpoint.setHeaderFilterStrategy(headerFilterStrategy);
} else {
http://git-wip-us.apache.org/repos/asf/camel/blob/892d3696/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
index f41dcaa..3f9dd28 100644
--- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
+++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyPojoInOutTest.java
@@ -31,6 +31,14 @@ public class RestJettyPojoInOutTest extends BaseJettyTest {
assertNotNull(out);
assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
+
+ @Test
+ public void testJettyGetRequest() throws Exception {
+ String out = template.requestBody("http://localhost:" + getPort() + "/users/lives", null, String.class);
+
+ assertNotNull(out);
+ assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -43,9 +51,16 @@ public class RestJettyPojoInOutTest extends BaseJettyTest {
// use the rest DSL to define the rest services
rest("/users/")
+ // just return the default country here
+ .get("lives").to("direct:start")
.post("lives").type(UserPojo.class).outType(CountryPojo.class)
.route()
.bean(new UserService(), "livesWhere");
+
+ CountryPojo country = new CountryPojo();
+ country.setIso("EN");
+ country.setCountry("England");
+ from("direct:start").transform().constant(country);
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/892d3696/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
index 7ada95a..f9dde3a 100644
--- a/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
+++ b/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/rest/RestServletPojoInOutTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.servlet.rest;
import java.io.ByteArrayInputStream;
+import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.PostMethodWebRequest;
import com.meterware.httpunit.WebRequest;
import com.meterware.httpunit.WebResponse;
@@ -44,6 +45,22 @@ public class RestServletPojoInOutTest extends ServletCamelRouterTestSupport {
assertNotNull(out);
assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
+
+ @Test
+ public void testServletPojoGet() throws Exception {
+
+ WebRequest req = new GetMethodWebRequest(CONTEXT_URL + "/services/users/lives");
+ ServletUnitClient client = newClient();
+ client.setExceptionsThrownOnErrorStatus(false);
+ WebResponse response = client.getResponse(req);
+
+ assertEquals(200, response.getResponseCode());
+
+ String out = response.getText();
+
+ assertNotNull(out);
+ assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -55,9 +72,16 @@ public class RestServletPojoInOutTest extends ServletCamelRouterTestSupport {
// use the rest DSL to define the rest services
rest("/users/")
+ // just return the default country here
+ .get("lives").to("direct:start")
.post("lives").type(UserPojo.class).outType(CountryPojo.class)
.route()
.bean(new UserService(), "livesWhere");
+
+ CountryPojo country = new CountryPojo();
+ country.setIso("EN");
+ country.setCountry("England");
+ from("direct:start").transform().constant(country);
}
};
}
[2/4] git commit: CAMEL-7899 Fixed the same issue in camel-netty-http
Posted by ni...@apache.org.
CAMEL-7899 Fixed the same issue in camel-netty-http
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2a45170b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2a45170b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2a45170b
Branch: refs/heads/master
Commit: 2a45170bb2c9c52d61b4fe38f6fabd4845b9912b
Parents: 892d369
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Oct 9 15:37:35 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 15:37:35 2014 +0800
----------------------------------------------------------------------
.../netty/http/DefaultContextPathMatcher.java | 4 +--
.../netty/http/RestContextPathMatcher.java | 26 +++++++++++++++++++-
.../HttpServerMultiplexChannelHandler.java | 4 +--
.../http/rest/RestNettyHttpPojoInOutTest.java | 18 +++++++++++++-
.../netty/http/rest/RestPathMatchingTest.java | 2 +-
5 files changed, 47 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2a45170b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
index 9f7d98f..9ba2248 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/DefaultContextPathMatcher.java
@@ -23,8 +23,8 @@ import java.util.Locale;
*/
public class DefaultContextPathMatcher implements ContextPathMatcher {
- private final String path;
- private final boolean matchOnUriPrefix;
+ protected final String path;
+ protected final boolean matchOnUriPrefix;
public DefaultContextPathMatcher(String path, boolean matchOnUriPrefix) {
this.path = path.toLowerCase(Locale.US);
http://git-wip-us.apache.org/repos/asf/camel/blob/2a45170b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
index 8e35f50..efc9258 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/RestContextPathMatcher.java
@@ -24,10 +24,12 @@ import java.util.Locale;
public class RestContextPathMatcher extends DefaultContextPathMatcher {
private final String rawPath;
+ private final String comparePath;
- public RestContextPathMatcher(String rawPath, String path, boolean matchOnUriPrefix) {
+ public RestContextPathMatcher(String rawPath, String path, String restrictMethod, boolean matchOnUriPrefix) {
super(path, matchOnUriPrefix);
this.rawPath = rawPath;
+ this.comparePath = rawPath + "?" + restrictMethod;
}
@Override
@@ -98,5 +100,27 @@ public class RestContextPathMatcher extends DefaultContextPathMatcher {
// assume matching
return true;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ RestContextPathMatcher that = (RestContextPathMatcher) o;
+
+ if (comparePath.equals(that.comparePath)) {
+ return super.equals(o);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * comparePath.hashCode() + (matchOnUriPrefix ? 1 : 0);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2a45170b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
index b452bb8..8c835e2 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -72,7 +72,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
String rawPath = consumer.getConfiguration().getPath();
String path = pathAsKey(consumer.getConfiguration().getPath());
// use rest path matcher in case Rest DSL is in use
- ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getConfiguration().isMatchOnUriPrefix());
+ ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(), consumer.getConfiguration().isMatchOnUriPrefix());
consumers.put(matcher, new HttpServerChannelHandler(consumer));
}
@@ -80,7 +80,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelUpstreamHand
String rawPath = consumer.getConfiguration().getPath();
String path = pathAsKey(consumer.getConfiguration().getPath());
// use rest path matcher in case Rest DSL is in use
- ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getConfiguration().isMatchOnUriPrefix());
+ ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(), consumer.getConfiguration().isMatchOnUriPrefix());
consumers.remove(matcher);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2a45170b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
index 4709fef..355fe61 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestNettyHttpPojoInOutTest.java
@@ -24,13 +24,22 @@ import org.junit.Test;
public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
@Test
- public void testJettyPojoInOut() throws Exception {
+ public void testNettyPojoInOut() throws Exception {
String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
String out = template.requestBody("netty-http:http://localhost:" + getPort() + "/users/lives", body, String.class);
assertNotNull(out);
assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
+
+ @Test
+ public void testNettyGetRequest() throws Exception {
+ String out = template.requestBody("netty-http:http://localhost:" + getPort() + "/users/lives", null, String.class);
+
+ assertNotNull(out);
+ assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -43,9 +52,16 @@ public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
// use the rest DSL to define the rest services
rest("/users/")
+ // just return the default country here
+ .get("lives").to("direct:start")
.post("lives").type(UserPojo.class).outType(CountryPojo.class)
.route()
.bean(new UserService(), "livesWhere");
+
+ CountryPojo country = new CountryPojo();
+ country.setIso("EN");
+ country.setCountry("England");
+ from("direct:start").transform().constant(country);
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2a45170b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
index af364ae..b128286 100644
--- a/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
+++ b/components/camel-netty-http/src/test/java/org/apache/camel/component/netty/http/rest/RestPathMatchingTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.component.netty.http.RestContextPathMatcher;
public class RestPathMatchingTest extends TestCase {
- private RestContextPathMatcher matcher = new RestContextPathMatcher("", "", true);
+ private RestContextPathMatcher matcher = new RestContextPathMatcher("", "", null, true);
public void testRestPathMatcher() throws Exception {
assertTrue(matcher.matchRestPath("/foo/", "/foo/", true));
[4/4] git commit: CAMEL-7894 Enabled the failed tests of
camel-netty4-http
Posted by ni...@apache.org.
CAMEL-7894 Enabled the failed tests of camel-netty4-http
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6fd10088
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6fd10088
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6fd10088
Branch: refs/heads/master
Commit: 6fd10088afa18294102f4ef176314cb93a4055d4
Parents: 7533958
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Oct 9 15:40:48 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 15:40:48 2014 +0800
----------------------------------------------------------------------
.../netty4/http/NettyHttpBasicAuthConstraintMapperTest.java | 2 --
.../http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java | 2 --
.../netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java | 2 --
3 files changed, 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/6fd10088/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthConstraintMapperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthConstraintMapperTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthConstraintMapperTest.java
index b2dc7f7..3468b91 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthConstraintMapperTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthConstraintMapperTest.java
@@ -19,10 +19,8 @@ package org.apache.camel.component.netty4.http;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
-import org.junit.Ignore;
import org.junit.Test;
-@Ignore("TODO fix it")
public class NettyHttpBasicAuthConstraintMapperTest extends BaseNettyTest {
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/6fd10088/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
index 7954212..4375a51 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpBasicAuthCustomSecurityAuthenticatorTest.java
@@ -22,10 +22,8 @@ import javax.security.auth.login.LoginException;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
-import org.junit.Ignore;
import org.junit.Test;
-@Ignore("TODO fix it")
public class NettyHttpBasicAuthCustomSecurityAuthenticatorTest extends BaseNettyTest {
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/6fd10088/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
index 2522682..64fea57 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/NettyHttpSimpleBasicAuthConstraintMapperTest.java
@@ -19,10 +19,8 @@ package org.apache.camel.component.netty4.http;
import org.apache.camel.CamelExecutionException;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.JndiRegistry;
-import org.junit.Ignore;
import org.junit.Test;
-@Ignore("TODO fix it")
public class NettyHttpSimpleBasicAuthConstraintMapperTest extends BaseNettyTest {
@Override
[3/4] git commit: CAMEL-7899 merged the patch to camel-netty4-http
Posted by ni...@apache.org.
CAMEL-7899 merged the patch to camel-netty4-http
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7533958f
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7533958f
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7533958f
Branch: refs/heads/master
Commit: 7533958f3d41a5d9a441cebae41e837f2859e552
Parents: 2a45170
Author: Willem Jiang <wi...@gmail.com>
Authored: Thu Oct 9 15:38:00 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Thu Oct 9 15:38:00 2014 +0800
----------------------------------------------------------------------
.../netty4/http/DefaultContextPathMatcher.java | 4 +--
.../netty4/http/RestContextPathMatcher.java | 27 +++++++++++++++++++-
.../HttpServerMultiplexChannelHandler.java | 4 +--
.../http/rest/RestNettyHttpPojoInOutTest.java | 19 +++++++++++++-
.../netty4/http/rest/RestPathMatchingTest.java | 2 +-
5 files changed, 49 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7533958f/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
index f30cc66..96dbe78 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/DefaultContextPathMatcher.java
@@ -23,8 +23,8 @@ import java.util.Locale;
*/
public class DefaultContextPathMatcher implements ContextPathMatcher {
- private final String path;
- private final boolean matchOnUriPrefix;
+ protected final String path;
+ protected final boolean matchOnUriPrefix;
public DefaultContextPathMatcher(String path, boolean matchOnUriPrefix) {
this.path = path.toLowerCase(Locale.US);
http://git-wip-us.apache.org/repos/asf/camel/blob/7533958f/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
index 587eef7..a07435d 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/RestContextPathMatcher.java
@@ -18,16 +18,19 @@ package org.apache.camel.component.netty4.http;
import java.util.Locale;
+
/**
* A {@link org.apache.camel.component.netty.http.ContextPathMatcher} that supports the Rest DSL.
*/
public class RestContextPathMatcher extends DefaultContextPathMatcher {
private final String rawPath;
+ private final String comparePath;
- public RestContextPathMatcher(String rawPath, String path, boolean matchOnUriPrefix) {
+ public RestContextPathMatcher(String rawPath, String path, String restrictMethod, boolean matchOnUriPrefix) {
super(path, matchOnUriPrefix);
this.rawPath = rawPath;
+ this.comparePath = rawPath + "?" + restrictMethod;
}
@Override
@@ -98,5 +101,27 @@ public class RestContextPathMatcher extends DefaultContextPathMatcher {
// assume matching
return true;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ RestContextPathMatcher that = (RestContextPathMatcher) o;
+
+ if (comparePath.equals(that.comparePath)) {
+ return super.equals(o);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return 31 * comparePath.hashCode() + (matchOnUriPrefix ? 1 : 0);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7533958f/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
index b83cd45..348641f 100644
--- a/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
+++ b/components/camel-netty4-http/src/main/java/org/apache/camel/component/netty4/http/handlers/HttpServerMultiplexChannelHandler.java
@@ -74,7 +74,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
String rawPath = consumer.getConfiguration().getPath();
String path = pathAsKey(consumer.getConfiguration().getPath());
// use rest path matcher in case Rest DSL is in use
- ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getConfiguration().isMatchOnUriPrefix());
+ ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(), consumer.getConfiguration().isMatchOnUriPrefix());
consumers.put(matcher, new HttpServerChannelHandler(consumer));
}
@@ -82,7 +82,7 @@ public class HttpServerMultiplexChannelHandler extends SimpleChannelInboundHandl
String rawPath = consumer.getConfiguration().getPath();
String path = pathAsKey(consumer.getConfiguration().getPath());
// use rest path matcher in case Rest DSL is in use
- ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getConfiguration().isMatchOnUriPrefix());
+ ContextPathMatcher matcher = new RestContextPathMatcher(rawPath, path, consumer.getEndpoint().getHttpMethodRestrict(), consumer.getConfiguration().isMatchOnUriPrefix());
consumers.remove(matcher);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7533958f/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
index a783b91..e215a9c 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestNettyHttpPojoInOutTest.java
@@ -24,13 +24,21 @@ import org.junit.Test;
public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
@Test
- public void testJettyPojoInOut() throws Exception {
+ public void testNettyPojoInOut() throws Exception {
String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
String out = template.requestBody("netty4-http:http://localhost:" + getPort() + "/users/lives", body, String.class);
assertNotNull(out);
assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
}
+
+ @Test
+ public void testNettyGetRequest() throws Exception {
+ String out = template.requestBody("netty4-http:http://localhost:" + getPort() + "/users/lives", null, String.class);
+
+ assertNotNull(out);
+ assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+ }
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
@@ -43,9 +51,18 @@ public class RestNettyHttpPojoInOutTest extends BaseNettyTest {
// use the rest DSL to define the rest services
rest("/users/")
+ // just return the default country here
+ .get("lives").to("direct:start")
.post("lives").type(UserPojo.class).outType(CountryPojo.class)
.route()
.bean(new UserService(), "livesWhere");
+
+ CountryPojo country = new CountryPojo();
+ country.setIso("EN");
+ country.setCountry("England");
+
+ from("direct:start").transform().constant(country);
+
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7533958f/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
----------------------------------------------------------------------
diff --git a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
index b297288..228a4c5 100644
--- a/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
+++ b/components/camel-netty4-http/src/test/java/org/apache/camel/component/netty4/http/rest/RestPathMatchingTest.java
@@ -21,7 +21,7 @@ import org.apache.camel.component.netty4.http.RestContextPathMatcher;
public class RestPathMatchingTest extends TestCase {
- private RestContextPathMatcher matcher = new RestContextPathMatcher("", "", true);
+ private RestContextPathMatcher matcher = new RestContextPathMatcher("", "", null, true);
public void testRestPathMatcher() throws Exception {
assertTrue(matcher.matchRestPath("/foo/", "/foo/", true));