Skip to content

Commit

Permalink
Merged revisions 736562 via svnmerge from
Browse files Browse the repository at this point in the history
https://svn.apache.org/repos/asf/camel/trunk

........
  r736562 | wtam | 2009-01-21 23:58:43 -0500 (Wed, 21 Jan 2009) | 1 line
  
  [CAMEL-1284] Restlet binding does not properly insert/extract Restlet message.
........


git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-1.x@736894 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
William Tam committed Jan 23, 2009
1 parent 640db92 commit bcb4022
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 8 deletions.
7 changes: 7 additions & 0 deletions components/camel-restlet/pom.xml
Expand Up @@ -74,6 +74,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
Expand Down
Expand Up @@ -42,7 +42,6 @@
*/
public class DefaultRestletBinding implements RestletBinding, HeaderFilterStrategyAware {
private static final Log LOG = LogFactory.getLog(DefaultRestletBinding.class);
private static final String CAMEL_REQUEST = "camel.request";
private HeaderFilterStrategy headerFilterStrategy;

/**
Expand All @@ -68,13 +67,13 @@ public void populateExchangeFromRestletRequest(Request request,

}
}

// extract our header and body

Form form = new Form(request.getEntity());
if (form != null) {
for (Map.Entry<String, String> entry : form.getValuesMap().entrySet()) {
if (CAMEL_REQUEST.equals(entry.getKey())) {
exchange.getIn().setBody(entry.getValue());
// extract body added to the form as the key which has null value
if (entry.getValue() == null) {
exchange.getIn().setBody(entry.getKey());
if (LOG.isDebugEnabled()) {
LOG.debug("Populate exchange from Restlet request body: " + entry.getValue());
}
Expand All @@ -91,6 +90,7 @@ public void populateExchangeFromRestletRequest(Request request,
}
}
}

}

/**
Expand All @@ -104,7 +104,8 @@ public void populateRestletRequestFromExchange(Request request,
request.setReferrerRef("camel-restlet");
String body = exchange.getIn().getBody(String.class);
Form form = new Form();
form.add(CAMEL_REQUEST, body);
// add the body as the key in the form with null value
form.add(body, null);

if (LOG.isDebugEnabled()) {
LOG.debug("Populate Restlet request from exchange body: " + body);
Expand Down
@@ -0,0 +1,67 @@
/**
* 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.ContextTestSupport;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.EntityEnclosingMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.RequestEntity;
import org.apache.commons.httpclient.methods.StringRequestEntity;

/**
*
* @version $Revision$
*/
public class RestletPostContentTest extends ContextTestSupport {

private static final String MSG_BODY = "Hello World!";

@Override
protected RouteBuilder createRouteBuilder() {

return new RouteBuilder() {
@Override
public void configure() throws Exception {
from("restlet:http://localhost:8080/users/{username}?restletMethod=POST")
.process(new SetUserProcessor());

}

};
}

class SetUserProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
assertEquals(MSG_BODY, exchange.getIn().getBody(String.class));
}

}

public void testPostBody() throws Exception {
HttpMethod method = new PostMethod("http://localhost:8080/users/homer");
RequestEntity requestEntity = new StringRequestEntity(MSG_BODY, null, null);
((EntityEnclosingMethod)method).setRequestEntity(requestEntity);
HttpClient client = new HttpClient();
assertEquals(200, client.executeMethod(method));

}
}
Expand Up @@ -53,6 +53,7 @@ public void testhBasicAuthError() throws IOException {
assertTrue(response.contains("requires user authentication"));
}

@Override
protected ClassPathXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext(
"org/apache/camel/component/restlet/camel-context.xml");
Expand Down
Expand Up @@ -29,9 +29,10 @@
import org.restlet.data.Response;
import org.restlet.data.Status;

public class RestRouteBuilderTest extends ContextTestSupport {
public class RestletRouteBuilderTest extends ContextTestSupport {
private static final String ID = "89531";

@Override
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
Expand All @@ -45,7 +46,7 @@ public void configure() {
from("restlet:http://localhost:8080/orders?restletMethod=post").process(new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getOut().setBody(
"received [" + exchange.getIn().getBody()
"received [" + exchange.getIn().getBody(String.class)
+ "] as an order id = "
+ exchange.getIn().getHeader("id"));
}
Expand Down

0 comments on commit bcb4022

Please sign in to comment.