camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r1164973 - in /camel/trunk/components/camel-servlet/src: main/java/org/apache/camel/component/servlet/ test/java/org/apache/camel/component/servlet/
Date Sun, 04 Sep 2011 08:49:26 GMT
Author: ningjiang
Date: Sun Sep  4 08:49:25 2011
New Revision: 1164973

URL: http://svn.apache.org/viewvc?rev=1164973&view=rev
Log:
CAMEL-4410 The URI of the ServletEndpoint exposed to the JMX is not accurate

Added:
    camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java
  (with props)
Modified:
    camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
    camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java

Modified: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java?rev=1164973&r1=1164972&r2=1164973&view=diff
==============================================================================
--- camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
(original)
+++ camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletComponent.java
Sun Sep  4 08:49:25 2011
@@ -37,7 +37,6 @@ import org.apache.commons.httpclient.par
 public class ServletComponent extends HttpComponent {
 
     private String servletName = "CamelServlet";
-    
     private HttpRegistry httpRegistry;
 
     public String getServletName() {
@@ -47,23 +46,20 @@ public class ServletComponent extends Ht
     public void setServletName(String servletName) {
         this.servletName = servletName;
     }
-    
+
     public void setHttpRegistry(HttpRegistry httpRegistry) {
         this.httpRegistry = httpRegistry;
     }
 
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
-        
         if (httpRegistry == null) {
             httpRegistry = DefaultHttpRegistry.getSingletonHttpRegistry();
         }
 
-        uri = uri.startsWith("servlet:") ? remaining : uri;
-
         HttpClientParams params = new HttpClientParams();
         IntrospectionSupport.setProperties(params, parameters, "httpClient.");
-        
+
         // create the configurer to use for this endpoint
         final Set<AuthMethod> authMethods = new LinkedHashSet<AuthMethod>();
         HttpClientConfigurer configurer = createHttpClientConfigurer(parameters, authMethods);
@@ -78,7 +74,6 @@ public class ServletComponent extends Ht
 
         // restructure uri to be based on the parameters left as we dont want to include
the Camel internal options
         URI httpUri = URISupport.createRemainingURI(new URI(UnsafeUriCharactersEncoder.encode(uri)),
CastUtils.cast(parameters));
-        uri = httpUri.toString();
 
         ServletEndpoint endpoint = createServletEndpoint(uri, this, httpUri, params, getHttpConnectionManager(),
configurer);
         endpoint.setServletName(servletName);
@@ -114,10 +109,8 @@ public class ServletComponent extends Ht
     /**
      * Strategy to create the servlet endpoint.
      */
-    protected ServletEndpoint createServletEndpoint(String endpointUri,
-            ServletComponent component, URI httpUri, HttpClientParams params,
-            HttpConnectionManager httpConnectionManager,
-            HttpClientConfigurer clientConfigurer) throws Exception {
+    protected ServletEndpoint createServletEndpoint(String endpointUri, ServletComponent
component, URI httpUri, HttpClientParams params,
+                                                    HttpConnectionManager httpConnectionManager,
HttpClientConfigurer clientConfigurer) throws Exception {
         return new ServletEndpoint(endpointUri, component, httpUri, params, httpConnectionManager,
clientConfigurer);
     }
 
@@ -130,6 +123,5 @@ public class ServletComponent extends Ht
     public void disconnect(HttpConsumer consumer) throws Exception {
         httpRegistry.unregister(consumer);
     }
-    
-    
+
 }
\ No newline at end of file

Modified: camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java?rev=1164973&r1=1164972&r2=1164973&view=diff
==============================================================================
--- camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
(original)
+++ camel/trunk/components/camel-servlet/src/main/java/org/apache/camel/component/servlet/ServletEndpoint.java
Sun Sep  4 08:49:25 2011
@@ -21,7 +21,6 @@ import java.net.URISyntaxException;
 
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
-import org.apache.camel.Producer;
 import org.apache.camel.component.http.HttpClientConfigurer;
 import org.apache.camel.component.http.HttpConsumer;
 import org.apache.camel.component.http.HttpEndpoint;
@@ -36,11 +35,11 @@ public class ServletEndpoint extends Htt
         super();
     }
 
-    public ServletEndpoint(String endPointURI, ServletComponent component, URI httpUri, HttpClientParams
params,
-                           HttpConnectionManager httpConnectionManager, HttpClientConfigurer
clientConfigurer) throws URISyntaxException {
+    public ServletEndpoint(String endPointURI, ServletComponent component, URI httpUri, HttpClientParams
params, HttpConnectionManager httpConnectionManager,
+                           HttpClientConfigurer clientConfigurer) throws URISyntaxException
{
         super(endPointURI, component, httpUri, params, httpConnectionManager, clientConfigurer);
     }
-    
+
     public void setServletName(String name) {
         servletName = name;
     }
@@ -50,13 +49,14 @@ public class ServletEndpoint extends Htt
     }
 
     @Override
-    public Producer createProducer() throws Exception {
-        return super.createProducer();
+    public Consumer createConsumer(Processor processor) throws Exception {
+        return new HttpConsumer(this, processor);
     }
 
     @Override
-    public Consumer createConsumer(Processor processor) throws Exception {
-        return new HttpConsumer(this, processor);
+    public boolean isLenientProperties() {
+        // in contrast to the HttpEndpoint, the ServletEndpoint knows about all it's options
on the passed URI
+        return false;
     }
 
 }

Added: camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java?rev=1164973&view=auto
==============================================================================
--- camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java
(added)
+++ camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java
Sun Sep  4 08:49:25 2011
@@ -0,0 +1,65 @@
+/**
+ * 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.
+ */
+package org.apache.camel.component.servlet;
+
+import java.util.Set;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class ExposedServletEndpointURIToJMXTest extends CamelTestSupport {
+
+    @Override
+    protected boolean useJmx() {
+        return true;
+    }
+
+    @Test
+    public void exposedEndpointURIShouldContainContextAndOptions() throws Exception {
+        //Thread.sleep(1000000);
+        checkServletEndpointURI("\"servlet:///test1\\?matchOnUriPrefix=true\"");
+        checkServletEndpointURI("\"servlet:///test2\\?servletName=test2\"");
+        checkServletEndpointURI("\"servlet:///test3\\?matchOnUriPrefix=true&servletName=test3\"");
+    }
+
+    private void checkServletEndpointURI(String servletEndpointURI) throws Exception {
+        MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
+        ObjectName name = new ObjectName("org.apache.camel:context=*/camel-1,type=endpoints,name="
+ servletEndpointURI);
+        Set<ObjectName> objectNamesSet = mbeanServer.queryNames(name, null);
+        assertEquals("Expect one MBean for the servlet endpoint", 1, objectNamesSet.size());
+
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+
+        return new RouteBuilder() {
+
+            @Override
+            public void configure() throws Exception {
+                from("servlet:///test1?matchOnUriPrefix=true").to("mock:jmx");
+                from("servlet:///test2?servletName=test2").to("mock:jmx");
+                from("servlet:///test3?matchOnUriPrefix=true&servletName=test3").to("mock:jmx");
+            }
+
+        };
+    }
+
+}

Propchange: camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/components/camel-servlet/src/test/java/org/apache/camel/component/servlet/ExposedServletEndpointURIToJMXTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message