This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 85127610297ba9fdcf686c53cc773f1de5f927cc Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Jul 29 10:25:43 2019 +0200 Camel-Jetty: Fixed CS --- .../camel/component/jetty/BaseJettyTest.java | 4 +- .../camel/component/jetty/CustomFiltersTest.java | 20 +++---- .../apache/camel/component/jetty/HandlerTest.java | 63 +++++++++++----------- .../jetty/HttpAuthMethodPriorityTest.java | 37 +++++++------ .../HttpBasicAuthComponentConfiguredTest.java | 33 ++++++------ .../camel/component/jetty/HttpBasicAuthTest.java | 24 ++++----- .../camel/component/jetty/HttpBindingRefTest.java | 10 ++-- .../jetty/HttpFilterCamelHeadersTest.java | 6 +-- .../component/jetty/HttpGZipEncodingTest.java | 47 ++++++++-------- .../camel/component/jetty/HttpUrlRewriteTest.java | 8 ++- .../HttpsRouteSslContextParametersInUriTest.java | 2 +- .../jetty/MultiPartFormWithCustomFilterTest.java | 58 ++++++++++---------- .../jetty/rest/RestJettyDefaultValueTest.java | 31 +++++------ .../rest/RestJettyGetCustomHttpBindingTest.java | 18 +++---- .../component/jetty/rest/RestJettyGetToDTest.java | 20 +++---- .../jetty/rest/RestJettyGetWildcardsTest.java | 32 +++++------ 16 files changed, 191 insertions(+), 222 deletions(-) diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java index b630238..d0f3022 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/BaseJettyTest.java @@ -32,7 +32,7 @@ import org.junit.BeforeClass; public abstract class BaseJettyTest extends CamelTestSupport { private static volatile int port; - + private static volatile int port2; private final AtomicInteger counter = new AtomicInteger(1); @@ -88,7 +88,7 @@ public abstract class BaseJettyTest extends CamelTestSupport { protected static int getPort() { return port; } - + protected static int getPort2() { return port2; } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java index 8d5cdc1..2fff8ca 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/CustomFiltersTest.java @@ -43,8 +43,9 @@ public class CustomFiltersTest extends BaseJettyTest { private static class MyTestFilter implements Filter { private String keyWord; + @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // set a marker attribute to show that this filter class was used ((HttpServletResponse)response).addHeader("MyTestFilter", "true"); ((HttpServletResponse)response).setHeader("KeyWord", keyWord); @@ -59,14 +60,14 @@ public class CustomFiltersTest extends BaseJettyTest { @Override public void destroy() { // do nothing here - } + } } - + private void sendRequestAndVerify(String url) throws Exception { HttpClient httpclient = new HttpClient(); - + PostMethod httppost = new PostMethod(url); - + StringRequestEntity reqEntity = new StringRequestEntity("This is a test", null, null); httppost.setRequestEntity(reqEntity); @@ -81,7 +82,7 @@ public class CustomFiltersTest extends BaseJettyTest { // just make sure the KeyWord header is set assertEquals("Did not set the right KeyWord header", "KEY", httppost.getResponseHeader("KeyWord").getValue()); } - + @Test public void testFilters() throws Exception { sendRequestAndVerify("http://localhost:" + getPort() + "/testFilters"); @@ -93,17 +94,18 @@ public class CustomFiltersTest extends BaseJettyTest { filters.add(new MyTestFilter()); return filters; } - + protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { - + // Test the filter list options from("jetty://http://localhost:{{port}}/testFilters?filtersRef=myFilters&filterInit.keyWord=KEY").process(new Processor() { public void process(Exchange exchange) throws Exception { Message in = exchange.getIn(); String request = in.getBody(String.class); - // The other form date can be get from the message header + // The other form date can be get from the message + // header exchange.getOut().setBody(request + " response"); } }); diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java index 2e5195a..6b911d0 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HandlerTest.java @@ -30,11 +30,11 @@ import org.eclipse.jetty.server.handler.StatisticsHandler; import org.junit.Test; public class HandlerTest extends BaseJettyTest { - @BindToRegistry("statisticsHandler1") + @BindToRegistry("statisticsHandler1") private StatisticsHandler statisticsHandler1 = new StatisticsHandler(); - @BindToRegistry("statisticsHandler2") + @BindToRegistry("statisticsHandler2") private StatisticsHandler statisticsHandler2 = new StatisticsHandler(); - @BindToRegistry("statisticsHandler3") + @BindToRegistry("statisticsHandler3") private StatisticsHandler statisticsHandler3 = new StatisticsHandler(); private String htmlResponse = "<html><body>Book 123 is Camel in Action</body></html>"; @@ -47,16 +47,16 @@ public class HandlerTest extends BaseJettyTest { assertEquals(0, statisticsHandler1.getRequests()); assertEquals(0, statisticsHandler2.getRequests()); assertEquals(0, statisticsHandler3.getRequests()); - - InputStream html = (InputStream) template.requestBody("http://localhost:" + port1, ""); + + InputStream html = (InputStream)template.requestBody("http://localhost:" + port1, ""); BufferedReader br = IOHelper.buffered(new InputStreamReader(html)); - + assertEquals(htmlResponse, br.readLine()); assertEquals(1, statisticsHandler1.getRequests()); assertEquals(0, statisticsHandler2.getRequests()); assertEquals(0, statisticsHandler3.getRequests()); } - + @Test public void testWithTwoHandlers() throws Exception { // First test the situation where one should invoke the handler once @@ -64,9 +64,9 @@ public class HandlerTest extends BaseJettyTest { assertEquals(0, statisticsHandler2.getRequests()); assertEquals(0, statisticsHandler3.getRequests()); - InputStream html = (InputStream) template.requestBody("http://localhost:" + port2, ""); + InputStream html = (InputStream)template.requestBody("http://localhost:" + port2, ""); BufferedReader br = IOHelper.buffered(new InputStreamReader(html)); - + assertEquals(htmlResponse, br.readLine()); assertEquals(0, statisticsHandler1.getRequests()); assertEquals(1, statisticsHandler2.getRequests()); @@ -80,14 +80,14 @@ public class HandlerTest extends BaseJettyTest { assertEquals(0, statisticsHandler2.getRequests()); assertEquals(0, statisticsHandler3.getRequests()); - InputStream html1 = (InputStream) template.requestBody("http://localhost:" + port2, ""); + InputStream html1 = (InputStream)template.requestBody("http://localhost:" + port2, ""); BufferedReader br1 = IOHelper.buffered(new InputStreamReader(html1)); assertEquals(htmlResponse, br1.readLine()); - - InputStream html2 = (InputStream) template.requestBody("http://localhost:" + port2 + "/endpoint2", ""); + + InputStream html2 = (InputStream)template.requestBody("http://localhost:" + port2 + "/endpoint2", ""); BufferedReader br2 = IOHelper.buffered(new InputStreamReader(html2)); assertEquals(htmlResponse, br2.readLine()); - + assertEquals(0, statisticsHandler1.getRequests()); assertEquals(2, statisticsHandler2.getRequests()); assertEquals(2, statisticsHandler3.getRequests()); @@ -100,26 +100,23 @@ public class HandlerTest extends BaseJettyTest { port1 = getPort(); port2 = getNextPort(); - from("jetty:http://localhost:" + port1 + "/?handlers=#statisticsHandler1") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(htmlResponse); - } - }); - - from("jetty:http://localhost:" + port2 + "/?handlers=#statisticsHandler2,#statisticsHandler3") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(htmlResponse); - } - }); - from("jetty:http://localhost:" + port2 + "/endpoint2?handlers=#statisticsHandler2,#statisticsHandler3") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - exchange.getOut().setBody(htmlResponse); - } - }); + from("jetty:http://localhost:" + port1 + "/?handlers=#statisticsHandler1").process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody(htmlResponse); + } + }); + + from("jetty:http://localhost:" + port2 + "/?handlers=#statisticsHandler2,#statisticsHandler3").process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody(htmlResponse); + } + }); + from("jetty:http://localhost:" + port2 + "/endpoint2?handlers=#statisticsHandler2,#statisticsHandler3").process(new Processor() { + public void process(Exchange exchange) throws Exception { + exchange.getOut().setBody(htmlResponse); + } + }); }; }; } -} \ No newline at end of file +} diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java index d3662cb..cc9fc41 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpAuthMethodPriorityTest.java @@ -42,7 +42,7 @@ import org.junit.Test; @Ignore public class HttpAuthMethodPriorityTest extends BaseJettyTest { - + @BindToRegistry("myAuthHandler") public SecurityHandler getSecurityHandler() throws IOException { Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); @@ -58,20 +58,22 @@ public class HttpAuthMethodPriorityTest extends BaseJettyTest { HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties"); sh.setLoginService(loginService); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm})); + sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm})); return sh; } @Test public void testAuthMethodPriorityBasicDigest() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=Basic,Digest&authUsername=donald&authPassword=duck", "Hello World", String.class); + String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=Basic,Digest&authUsername=donald&authPassword=duck", "Hello World", + String.class); assertEquals("Bye World", out); } @Test public void testAuthMethodPriorityNTLMBasic() throws Exception { - String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=NTLM,Basic&authUsername=donald&authPassword=duck", "Hello World", String.class); + String out = template.requestBody("http://localhost:{{port}}/test?authMethod=Basic&authMethodPriority=NTLM,Basic&authUsername=donald&authPassword=duck", "Hello World", + String.class); assertEquals("Bye World", out); } @@ -82,9 +84,8 @@ public class HttpAuthMethodPriorityTest extends BaseJettyTest { fail("Should have thrown an exception"); } catch (FailedToCreateProducerException e) { IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause().getCause()); - //JAXB 2.2 uses a slightly different message - boolean b = cause.getMessage().contains("No enum const") - && cause.getMessage().contains("org.apache.camel.component.http4.AuthMethod.foo"); + // JAXB 2.2 uses a slightly different message + boolean b = cause.getMessage().contains("No enum const") && cause.getMessage().contains("org.apache.camel.component.http4.AuthMethod.foo"); assertTrue("Bad fault message: " + cause.getMessage(), b); } } @@ -105,18 +106,16 @@ public class HttpAuthMethodPriorityTest extends BaseJettyTest { return new RouteBuilder() { @Override public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - Principal user = req.getUserPrincipal(); - assertNotNull(user); - assertEquals("donald", user.getName()); - } - }) - .transform(constant("Bye World")); + from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler").process(new Processor() { + public void process(Exchange exchange) throws Exception { + HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); + assertNotNull(req); + Principal user = req.getUserPrincipal(); + assertNotNull(user); + assertEquals("donald", user.getName()); + } + }).transform(constant("Bye World")); } }; } -} \ No newline at end of file +} diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java index 4f188dc..2c02d65 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthComponentConfiguredTest.java @@ -39,7 +39,7 @@ import org.junit.Test; public class HttpBasicAuthComponentConfiguredTest extends BaseJettyTest { - @BindToRegistry("myAuthHandler") + @BindToRegistry("myAuthHandler") public SecurityHandler getSecurityHandler() throws IOException { Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); constraint.setAuthenticate(true); @@ -54,7 +54,7 @@ public class HttpBasicAuthComponentConfiguredTest extends BaseJettyTest { HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties"); sh.setLoginService(loginService); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm})); + sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm})); return sh; } @@ -63,7 +63,7 @@ public class HttpBasicAuthComponentConfiguredTest extends BaseJettyTest { public void testHttpBasicAuth() throws Exception { String out = template.requestBody("http://localhost:{{port}}/test", "Hello World", String.class); assertEquals("Bye World", out); - + out = template.requestBody("http://localhost:{{port}}/anotherTest", "Hello World", String.class); assertEquals("See you later", out); } @@ -81,21 +81,18 @@ public class HttpBasicAuthComponentConfiguredTest extends BaseJettyTest { HttpComponent http = context.getComponent("http", HttpComponent.class); http.setHttpConfiguration(config); - from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - Principal user = req.getUserPrincipal(); - assertNotNull(user); - assertEquals("donald", user.getName()); - } - }) - .transform(constant("Bye World")); - - from("jetty://http://localhost:{{port}}/anotherTest?handlers=myAuthHandler") - .transform(constant("See you later")); + from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler").process(new Processor() { + public void process(Exchange exchange) throws Exception { + HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); + assertNotNull(req); + Principal user = req.getUserPrincipal(); + assertNotNull(user); + assertEquals("donald", user.getName()); + } + }).transform(constant("Bye World")); + + from("jetty://http://localhost:{{port}}/anotherTest?handlers=myAuthHandler").transform(constant("See you later")); } }; } -} \ No newline at end of file +} diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java index 240da90..a69f83c 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBasicAuthTest.java @@ -39,7 +39,7 @@ import org.junit.Test; public class HttpBasicAuthTest extends BaseJettyTest { - @BindToRegistry("myAuthHandler") + @BindToRegistry("myAuthHandler") public SecurityHandler getSecurityHandler() throws IOException { Constraint constraint = new Constraint(Constraint.__BASIC_AUTH, "user"); constraint.setAuthenticate(true); @@ -54,7 +54,7 @@ public class HttpBasicAuthTest extends BaseJettyTest { HashLoginService loginService = new HashLoginService("MyRealm", "src/test/resources/myRealm.properties"); sh.setLoginService(loginService); - sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[]{cm})); + sh.setConstraintMappings(Arrays.asList(new ConstraintMapping[] {cm})); return sh; } @@ -81,17 +81,15 @@ public class HttpBasicAuthTest extends BaseJettyTest { return new RouteBuilder() { @Override public void configure() throws Exception { - from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); - assertNotNull(req); - Principal user = req.getUserPrincipal(); - assertNotNull(user); - assertEquals("donald", user.getName()); - } - }) - .transform(constant("Bye World")); + from("jetty://http://localhost:{{port}}/test?handlers=myAuthHandler").process(new Processor() { + public void process(Exchange exchange) throws Exception { + HttpServletRequest req = exchange.getIn().getBody(HttpServletRequest.class); + assertNotNull(req); + Principal user = req.getUserPrincipal(); + assertNotNull(user); + assertEquals("donald", user.getName()); + } + }).transform(constant("Bye World")); } }; } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java index 6b162b8..b72cb5b 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpBindingRefTest.java @@ -35,10 +35,10 @@ public class HttpBindingRefTest extends BaseJettyTest { @BindToRegistry("default") private DefaultHttpBinding binding = new DefaultHttpBinding(); - + @BindToRegistry("myownbinder") private MyHttpBinding bindingHttp = new MyHttpBinding(); - + @Test public void testDefaultHttpBinding() throws Exception { Object out = template.requestBody("http://localhost:{{port}}/myapp/myservice", "Hello World"); @@ -74,8 +74,9 @@ public class HttpBindingRefTest extends BaseJettyTest { @Override public void doWriteExceptionResponse(Throwable exception, HttpServletResponse response) throws IOException { - // we override the doWriteExceptionResponse as we only want to alter the binding how exceptions is - // written back to the client. + // we override the doWriteExceptionResponse as we only want to alter + // the binding how exceptions is + // written back to the client. // we just return HTTP 200 so the client thinks its okay response.setStatus(200); @@ -86,4 +87,3 @@ public class HttpBindingRefTest extends BaseJettyTest { // END SNIPPET: e1 } - diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java index c97483a..9d49121 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpFilterCamelHeadersTest.java @@ -27,9 +27,9 @@ import org.junit.Test; public class HttpFilterCamelHeadersTest extends BaseJettyTest { - @BindToRegistry("foo") - private MyFooBean bean = new MyFooBean(); - + @BindToRegistry("foo") + private MyFooBean bean = new MyFooBean(); + @Test public void testFilterCamelHeaders() throws Exception { Exchange out = template.send("http://localhost:{{port}}/test/filter", new Processor() { diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java index bedf757..e1719db 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpGZipEncodingTest.java @@ -31,43 +31,40 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.junit.Ignore; import org.junit.Test; -@Ignore("TODO: investigate for Camel 3.0. The test actally works fine, but the " - + "test needs to be verified as http4 supports gzip by default, so some tests may " +@Ignore("TODO: investigate for Camel 3.0. The test actally works fine, but the " + "test needs to be verified as http4 supports gzip by default, so some tests may " + "have to be changed to stay meaningful.") public class HttpGZipEncodingTest extends BaseJettyTest { - + private int port1; private int port2; @Test public void testHttpProducerWithGzip() throws Exception { String response = template.requestBodyAndHeader("http://localhost:" + port1 + "/gzip?httpClientConfigurer=#configurer", - new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); + new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); assertEquals("The response is wrong", "<b>Hello World</b>", response); } - + @Test public void testGzipProxy() throws Exception { - String response = - template.requestBodyAndHeader("http://localhost:" + port2 + "/route?httpClientConfigurer=#configurer", - new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); + String response = template.requestBodyAndHeader("http://localhost:" + port2 + "/route?httpClientConfigurer=#configurer", + new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); assertEquals("The response is wrong", "<b>Hello World</b>", response); } - + @Test public void testGzipProducerWithGzipData() throws Exception { - String response = template.requestBodyAndHeader("direct:gzip", - new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", String.class); + String response = template.requestBodyAndHeader("direct:gzip", new ByteArrayInputStream("<Hello>World</Hello>".getBytes()), Exchange.CONTENT_ENCODING, "gzip", + String.class); assertEquals("The response is wrong", "<b>Hello World</b>", response); } - + @Test public void testGzipGet() throws Exception { - String response = template.requestBodyAndHeader("http://localhost:" + port1 + "/gzip", - null, "Accept-Encoding", "gzip", String.class); + String response = template.requestBodyAndHeader("http://localhost:" + port1 + "/gzip", null, "Accept-Encoding", "gzip", String.class); assertEquals("The response is wrong", "<b>Hello World for gzip</b>", response); } - + protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() { @@ -82,31 +79,29 @@ public class HttpGZipEncodingTest extends BaseJettyTest { clientBuilder.disableContentCompression(); } }); - - from("direct:gzip") - .marshal().gzipDeflater() - .setProperty(Exchange.SKIP_GZIP_ENCODING, ExpressionBuilder.constantExpression(Boolean.TRUE)) - .to("http://localhost:" + port1 + "/gzip?httpClientConfigurer=#configurer").unmarshal().gzipDeflater(); - + + from("direct:gzip").marshal().gzipDeflater().setProperty(Exchange.SKIP_GZIP_ENCODING, ExpressionBuilder.constantExpression(Boolean.TRUE)) + .to("http://localhost:" + port1 + "/gzip?httpClientConfigurer=#configurer").unmarshal().gzipDeflater(); + from("jetty:http://localhost:" + port1 + "/gzip").process(new Processor() { public void process(Exchange exchange) throws Exception { // check the request method HttpServletRequest request = exchange.getIn().getHeader(Exchange.HTTP_SERVLET_REQUEST, HttpServletRequest.class); if ("POST".equals(request.getMethod())) { - String requestBody = exchange.getIn().getBody(String.class); + String requestBody = exchange.getIn().getBody(String.class); assertEquals("Get a wrong request string", "<Hello>World</Hello>", requestBody); } exchange.getOut().setHeader(Exchange.CONTENT_ENCODING, "gzip"); // check the Accept Encoding header - String header = exchange.getIn().getHeader("Accept-Encoding", String.class); - if (header != null && header.indexOf("gzip") > -1) { + String header = exchange.getIn().getHeader("Accept-Encoding", String.class); + if (header != null && header.indexOf("gzip") > -1) { exchange.getOut().setBody("<b>Hello World for gzip</b>"); - } else { + } else { exchange.getOut().setBody("<b>Hello World</b>"); } } }); - + from("jetty:http://localhost:" + port2 + "/route?bridgeEndpoint=true&httpClientConfigurer=#configurer") .to("http://localhost:" + port1 + "/gzip?bridgeEndpoint=true&httpClientConfigurer=#configurer"); } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.java index 1a0ec13..8f66818 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpUrlRewriteTest.java @@ -27,7 +27,7 @@ public class HttpUrlRewriteTest extends BaseJettyTest { private int port1; private int port2; - + @BindToRegistry("myRewrite") private MyUrlRewrite urlRew = new MyUrlRewrite(); @@ -51,11 +51,9 @@ public class HttpUrlRewriteTest extends BaseJettyTest { from("jetty:http://localhost:" + port1 + "?matchOnUriPrefix=true") .to("http://localhost:" + port2 + "?throwExceptionOnFailure=false&bridgeEndpoint=true&urlRewrite=#myRewrite"); - from("jetty://http://localhost:" + port2 + "/bar") - .transform().simple("${header.phrase} ${body}") - .to("mock:result"); + from("jetty://http://localhost:" + port2 + "/bar").transform().simple("${header.phrase} ${body}").to("mock:result"); } }; - } + } } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java index c0b2a54..ca5eb17 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/HttpsRouteSslContextParametersInUriTest.java @@ -28,7 +28,7 @@ import org.apache.camel.support.jsse.KeyStoreParameters; import org.apache.camel.support.jsse.SSLContextParameters; public class HttpsRouteSslContextParametersInUriTest extends HttpsRouteTest { - + @BindToRegistry("sslContextParameters") public SSLContextParameters loadSSLParams() throws Exception { KeyStoreParameters ksp = new KeyStoreParameters(); diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java index fa4cffd..1590ee3 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/MultiPartFormWithCustomFilterTest.java @@ -43,17 +43,17 @@ import org.junit.Test; public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { - @BindToRegistry("myMultipartFilter") - private MyMultipartFilter multipartFilter = new MyMultipartFilter(); - + @BindToRegistry("myMultipartFilter") + private MyMultipartFilter multipartFilter = new MyMultipartFilter(); + private static class MyMultipartFilter extends MultiPartFilter { @Override - public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // set a marker attribute to show that this filter class was used ((HttpServletResponse)response).addHeader("MyMultipartFilter", "true"); - + super.doFilter(request, response, chain); - } + } } @Test @@ -61,10 +61,7 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { HttpClient httpclient = new HttpClient(); File file = new File("src/test/resources/log4j2.properties"); PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test"); - Part[] parts = { - new StringPart("comment", "A binary file of some kind"), - new FilePart(file.getName(), file) - }; + Part[] parts = {new StringPart("comment", "A binary file of some kind"), new FilePart(file.getName(), file)}; MultipartRequestEntity reqEntity = new MultipartRequestEntity(parts, httppost.getParams()); httppost.setRequestEntity(reqEntity); @@ -77,7 +74,7 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { assertEquals("Get a wrong result", "A binary file of some kind", result); assertNotNull("Did not use custom multipart filter", httppost.getResponseHeader("MyMultipartFilter")); } - + @Test public void testSendMultiPartFormOverrideEnableMultpartFilterFalse() throws Exception { HttpClient httpclient = new HttpClient(); @@ -85,10 +82,7 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { File file = new File("src/test/resources/log4j2.properties"); PostMethod httppost = new PostMethod("http://localhost:" + getPort() + "/test2"); - Part[] parts = { - new StringPart("comment", "A binary file of some kind"), - new FilePart(file.getName(), file) - }; + Part[] parts = {new StringPart("comment", "A binary file of some kind"), new FilePart(file.getName(), file)}; MultipartRequestEntity reqEntity = new MultipartRequestEntity(parts, httppost.getParams()); httppost.setRequestEntity(reqEntity); @@ -98,16 +92,18 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { assertEquals("Get a wrong response status", 200, status); assertNotNull("Did not use custom multipart filter", httppost.getResponseHeader("MyMultipartFilter")); } - + protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { public void configure() throws Exception { // START SNIPPET: e1 - // Set the jetty temp directory which store the file for multi part form - // camel-jetty will clean up the file after it handled the request. + // Set the jetty temp directory which store the file for multi + // part form + // camel-jetty will clean up the file after it handled the + // request. // The option works rightly from Camel 2.4.0 getContext().getGlobalOptions().put("CamelJettyTempDir", "target"); - + from("jetty://http://localhost:{{port}}/test?multipartFilterRef=myMultipartFilter").process(new Processor() { public void process(Exchange exchange) throws Exception { AttachmentMessage in = exchange.getMessage(AttachmentMessage.class); @@ -116,22 +112,27 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { DataHandler data = in.getAttachment("log4j2.properties"); assertNotNull("Should get the DataHandle log4j2.properties", data); - // This assert is wrong, but the correct content-type (application/octet-stream) - // will not be returned until Jetty makes it available - currently the content-type - // returned is just the default for FileDataHandler (for the implentation being used) - //assertEquals("Get a wrong content type", "text/plain", data.getContentType()); + // This assert is wrong, but the correct content-type + // (application/octet-stream) + // will not be returned until Jetty makes it available - + // currently the content-type + // returned is just the default for FileDataHandler (for + // the implentation being used) + // assertEquals("Get a wrong content type", + // "text/plain", data.getContentType()); assertEquals("Got the wrong name", "log4j2.properties", data.getName()); - assertTrue("We should get the data from the DataHandle", data.getDataSource() - .getInputStream().available() > 0); + assertTrue("We should get the data from the DataHandle", data.getDataSource().getInputStream().available() > 0); - // The other form date can be get from the message header + // The other form date can be get from the message + // header exchange.getOut().setBody(in.getHeader("comment")); } }); // END SNIPPET: e1 - // Test to ensure that setting a multipartFilterRef overrides the enableMultipartFilter=false parameter + // Test to ensure that setting a multipartFilterRef overrides + // the enableMultipartFilter=false parameter from("jetty://http://localhost:{{port}}/test2?multipartFilterRef=myMultipartFilter&enableMultipartFilter=false").process(new Processor() { public void process(Exchange exchange) throws Exception { AttachmentMessage in = exchange.getMessage(AttachmentMessage.class); @@ -139,7 +140,8 @@ public class MultiPartFormWithCustomFilterTest extends BaseJettyTest { DataHandler data = in.getAttachment("log4j2.properties"); assertNotNull("Should get the DataHandle log4j2.properties", data); - // The other form date can be get from the message header + // The other form date can be get from the message + // header exchange.getOut().setBody(in.getHeader("comment")); } }); diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyDefaultValueTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyDefaultValueTest.java index 08a53a0..733a6c8 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyDefaultValueTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyDefaultValueTest.java @@ -28,7 +28,7 @@ import org.apache.camel.util.ObjectHelper; import org.junit.Test; public class RestJettyDefaultValueTest extends BaseJettyTest { - + @BindToRegistry("mybinding") private JettyRestHttpBinding binding = new JettyRestHttpBinding(); @@ -50,24 +50,21 @@ public class RestJettyDefaultValueTest extends BaseJettyTest { restConfiguration().component("jetty").host("localhost").port(getPort()).endpointProperty("httpBindingRef", "#mybinding"); // use the rest DSL to define the rest services - rest("/users/") - .get("{id}/basic").param().name("verbose").type(RestParamType.query).defaultValue("false").endParam() - .route() - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - String id = exchange.getIn().getHeader("id", String.class); + rest("/users/").get("{id}/basic").param().name("verbose").type(RestParamType.query).defaultValue("false").endParam().route().process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); - Object verbose = exchange.getIn().getHeader("verbose"); - ObjectHelper.notNull(verbose, "verbose"); + Object verbose = exchange.getIn().getHeader("verbose"); + ObjectHelper.notNull(verbose, "verbose"); - if ("true".equals(verbose)) { - exchange.getOut().setBody(id + ";Donald Duck;1113 Quack Street Duckburg"); - } - if ("false".equals(verbose)) { - exchange.getOut().setBody(id + ";Donald Duck"); - } - } - }); + if ("true".equals(verbose)) { + exchange.getOut().setBody(id + ";Donald Duck;1113 Quack Street Duckburg"); + } + if ("false".equals(verbose)) { + exchange.getOut().setBody(id + ";Donald Duck"); + } + } + }); } }; } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetCustomHttpBindingTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetCustomHttpBindingTest.java index e5a6f03..3b5ce04 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetCustomHttpBindingTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetCustomHttpBindingTest.java @@ -26,7 +26,7 @@ import org.apache.camel.impl.JndiRegistry; import org.junit.Test; public class RestJettyGetCustomHttpBindingTest extends BaseJettyTest { - + @BindToRegistry("mybinding") private JettyRestHttpBinding binding = new MyCustomHttpBinding("I was here;"); @@ -45,16 +45,12 @@ public class RestJettyGetCustomHttpBindingTest extends BaseJettyTest { restConfiguration().component("jetty").host("localhost").port(getPort()).endpointProperty("httpBindingRef", "#mybinding"); // use the rest DSL to define the rest services - rest("/users/") - .get("{id}/basic") - .route() - .to("mock:input") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - String id = exchange.getIn().getHeader("id", String.class); - exchange.getOut().setBody(id + ";Donald Duck"); - } - }); + rest("/users/").get("{id}/basic").route().to("mock:input").process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Donald Duck"); + } + }); } }; } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetToDTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetToDTest.java index d224b7a..a05f20d 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetToDTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetToDTest.java @@ -45,18 +45,14 @@ public class RestJettyGetToDTest extends BaseJettyTest { restConfiguration().component("jetty").host("localhost").port(getPort()).endpointProperty("httpBindingRef", "#mybinding"); // use the rest DSL to define the rest services - rest("/users/") - .get("{id}/basic") - .toD("seda:${header.id}"); - - from("seda:123") - .to("mock:input") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - String id = exchange.getIn().getHeader("id", String.class); - exchange.getOut().setBody(id + ";Donald Duck"); - } - }); + rest("/users/").get("{id}/basic").toD("seda:${header.id}"); + + from("seda:123").to("mock:input").process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Donald Duck"); + } + }); } }; } diff --git a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetWildcardsTest.java b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetWildcardsTest.java index 6188c3f..b00370e 100644 --- a/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetWildcardsTest.java +++ b/components/camel-jetty/src/test/java/org/apache/camel/component/jetty/rest/RestJettyGetWildcardsTest.java @@ -26,7 +26,7 @@ import org.apache.camel.impl.JndiRegistry; import org.junit.Test; public class RestJettyGetWildcardsTest extends BaseJettyTest { - + @BindToRegistry("mybinding") private JettyRestHttpBinding binding = new JettyRestHttpBinding(); @@ -51,25 +51,17 @@ public class RestJettyGetWildcardsTest extends BaseJettyTest { restConfiguration().component("jetty").host("localhost").port(getPort()).endpointProperty("httpBindingRef", "#mybinding"); // use the rest DSL to define the rest services - rest("/users/") - .get("{id}/basic") - .route() - .to("mock:input") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - String id = exchange.getIn().getHeader("id", String.class); - exchange.getOut().setBody(id + ";Donald Duck"); - } - }).endRest() - .get("{id}/{query}") - .route() - .to("mock:query") - .process(new Processor() { - public void process(Exchange exchange) throws Exception { - String id = exchange.getIn().getHeader("id", String.class); - exchange.getOut().setBody(id + ";Goofy"); - } - }).endRest(); + rest("/users/").get("{id}/basic").route().to("mock:input").process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Donald Duck"); + } + }).endRest().get("{id}/{query}").route().to("mock:query").process(new Processor() { + public void process(Exchange exchange) throws Exception { + String id = exchange.getIn().getHeader("id", String.class); + exchange.getOut().setBody(id + ";Goofy"); + } + }).endRest(); } }; }