You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/10/07 14:12:17 UTC
svn commit: r1005428 - in /camel/trunk/components/camel-restlet/src:
main/java/org/apache/camel/component/restlet/
test/java/org/apache/camel/component/restlet/
Author: davsclaus
Date: Thu Oct 7 12:12:17 2010
New Revision: 1005428
URL: http://svn.apache.org/viewvc?rev=1005428&view=rev
Log:
Polished
Added:
camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteAndJSONAsReturnTest.java
camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteTest.java
- copied, changed from r1005417, camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlTest.java
Modified:
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
Modified: camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java?rev=1005428&r1=1005427&r2=1005428&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java (original)
+++ camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletComponent.java Thu Oct 7 12:12:17 2010
@@ -104,7 +104,7 @@ public class RestletComponent extends He
public void connect(RestletConsumer consumer) throws Exception {
RestletEndpoint endpoint = (RestletEndpoint)consumer.getEndpoint();
- addServerIfNeccessary(endpoint);
+ addServerIfNecessary(endpoint);
if (endpoint.getUriPattern() != null && endpoint.getUriPattern().length() > 0) {
attachUriPatternToRestlet(endpoint.getUriPattern(), endpoint, consumer.getRestlet());
@@ -163,7 +163,7 @@ public class RestletComponent extends He
}
}
- private void addServerIfNeccessary(RestletEndpoint endpoint) throws Exception {
+ private void addServerIfNecessary(RestletEndpoint endpoint) throws Exception {
String key = buildKey(endpoint);
Server server;
synchronized (servers) {
Modified: camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java?rev=1005428&r1=1005427&r2=1005428&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java (original)
+++ camel/trunk/components/camel-restlet/src/main/java/org/apache/camel/component/restlet/RestletEndpoint.java Thu Oct 7 12:12:17 2010
@@ -35,7 +35,6 @@ import org.restlet.data.Method;
* @version $Revision$
*/
public class RestletEndpoint extends DefaultEndpoint implements HeaderFilterStrategyAware, Service {
- //private static final Log LOG = LogFactory.getLog(RestletEndpoint.class);
private static final int DEFAULT_PORT = 80;
private static final String DEFAULT_PROTOCOL = "http";
Added: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteAndJSONAsReturnTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteAndJSONAsReturnTest.java?rev=1005428&view=auto
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteAndJSONAsReturnTest.java (added)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteAndJSONAsReturnTest.java Thu Oct 7 12:12:17 2010
@@ -0,0 +1,85 @@
+/**
+ * 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.restlet;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.Test;
+
+/**
+ * @version $Revision: 943352 $
+ */
+public class RestletPostXmlRouteAndJSONAsReturnTest extends RestletTestSupport {
+
+ private static final String REQUEST_MESSAGE =
+ "<mail><body>HelloWorld!</body><subject>test</subject><to>x@y.net</to></mail>";
+ private static final String REQUEST_MESSAGE_WITH_XML_TAG =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + REQUEST_MESSAGE;
+
+ private String url = "restlet:http://localhost:9087/users?restletMethod=POST";
+
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // enable POST support
+ from(url)
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String body = exchange.getIn().getBody(String.class);
+ assertNotNull(body);
+ assertTrue("Get a wrong request message", body.indexOf(REQUEST_MESSAGE) >= 0);
+ exchange.getOut().setBody("{OK}");
+ exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/json");
+ }
+ });
+
+ // route to restlet
+ from("direct:start").to(url);
+ }
+ };
+ }
+
+ @Test
+ public void testPostXml() throws Exception {
+ postRequestMessage(REQUEST_MESSAGE);
+ }
+
+ @Test
+ public void testPostXmlWithXmlTag() throws Exception {
+ postRequestMessage(REQUEST_MESSAGE_WITH_XML_TAG);
+ }
+
+ private void postRequestMessage(final String message) throws Exception {
+ Exchange exchange = template.request("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody(message);
+ exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/json");
+ }
+ });
+
+ assertNotNull(exchange);
+ assertTrue(exchange.hasOut());
+
+ String s = exchange.getOut().getBody(String.class);
+ assertEquals("{OK}", s);
+ }
+
+}
Copied: camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteTest.java (from r1005417, camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteTest.java?p2=camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteTest.java&p1=camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlTest.java&r1=1005417&r2=1005428&rev=1005428&view=diff
==============================================================================
--- camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlTest.java (original)
+++ camel/trunk/components/camel-restlet/src/test/java/org/apache/camel/component/restlet/RestletPostXmlRouteTest.java Thu Oct 7 12:12:17 2010
@@ -19,20 +19,19 @@ package org.apache.camel.component.restl
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.entity.StringEntity;
import org.junit.Test;
/**
* @version $Revision$
*/
-public class RestletPostXmlTest extends RestletTestSupport {
+public class RestletPostXmlRouteTest extends RestletTestSupport {
private static final String REQUEST_MESSAGE =
"<mail><body>HelloWorld!</body><subject>test</subject><to>x@y.net</to></mail>";
private static final String REQUEST_MESSAGE_WITH_XML_TAG =
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + REQUEST_MESSAGE;
+
+ private String url = "restlet:http://localhost:9087/users?restletMethod=POST";
@Override
@@ -41,7 +40,7 @@ public class RestletPostXmlTest extends
@Override
public void configure() throws Exception {
// enable POST support
- from("restlet:http://localhost:9087/users/?restletMethods=post")
+ from(url)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
String body = exchange.getIn().getBody(String.class);
@@ -51,6 +50,9 @@ public class RestletPostXmlTest extends
exchange.getOut().setHeader(Exchange.CONTENT_TYPE, "application/xml");
}
});
+
+ // route to restlet
+ from("direct:start").to(url);
}
};
}
@@ -65,14 +67,18 @@ public class RestletPostXmlTest extends
postRequestMessage(REQUEST_MESSAGE_WITH_XML_TAG);
}
- private void postRequestMessage(String message) throws Exception {
- HttpPost post = new HttpPost("http://localhost:9087/users/");
- post.addHeader(Exchange.CONTENT_TYPE, "application/xml");
- post.setEntity(new StringEntity(message));
-
- HttpResponse response = doExecute(post);
- assertHttpResponse(response, 200, "application/xml");
- String s = context.getTypeConverter().convertTo(String.class, response.getEntity().getContent());
+ private void postRequestMessage(final String message) throws Exception {
+ Exchange exchange = template.request("direct:start", new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getIn().setBody(message);
+ exchange.getIn().setHeader(Exchange.CONTENT_TYPE, "application/xml");
+ }
+ });
+
+ assertNotNull(exchange);
+ assertTrue(exchange.hasOut());
+
+ String s = exchange.getOut().getBody(String.class);
assertEquals("<status>OK</status>", s);
}