Hi,
by using Jetty Component and the receive of an HttpServletRequest, the
request object losts the parameters submitted by the form by using http
POST method.
I know the parameters are written to message header, but the
HttpServletRequest instance losts the parameters in the parameters map
=> httpServletRequest.getParameterMap(). In my case, the map is empty :(
If i know which parameters are sent, i can grap it from message header
=> all fine!
But what should i do, if i don't know with parameters will be submitted
by the form?
By the way, if i use http GET method in the form, all works fine and the
map contains the parameters sent.
*Any hint to get know which parameters are sent by form, like
httpServletRequest.getParameterNames()?*
Here is my test to attest my state:
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.spring.SpringRouteBuilder;
import org.apache.camel.test.CamelSpringTestSupport;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class JettyTest extends CamelSpringTestSupport {
@Override
protected AbstractXmlApplicationContext createApplicationContext() {
return new
ClassPathXmlApplicationContext("META-INF/spring/test-context.xml");
}
public void testReceivePostData() throws InterruptedException {
final MockEndpoint mockEndpoint =
context.getEndpoint("mock:httpRequestReceive", MockEndpoint.class);
RouteBuilder rb = new SpringRouteBuilder() {
@Override
public void configure() throws Exception {
from("jetty:http://localhost:8888/testreceivepostdata")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws
Exception {
HttpServletRequest request =
exchange.getIn().getBody(HttpServletRequest.class);
Map parameters = request.getParameterMap();
context.createProducerTemplate().sendBody(mockEndpoint, parameters);
}
});
}
};
try {
context.addRoutes(rb);
} catch (Exception e) {
e.printStackTrace();
fail("Failed to add test route.");
}
HttpClient httpClient = new HttpClient();
HttpMethod httpGetMethod = new
GetMethod("http://localhost:8888/testreceivepostdata");
httpGetMethod.setQueryString("parameter1=testParam");
try {
httpClient.executeMethod(httpGetMethod);
} catch (Exception e) {
fail("Failed to execute method.");
}
assertEquals(1, mockEndpoint.getReceivedCounter());
Exchange exchange = mockEndpoint.getExchanges().get(0);
Map parameters = exchange.getIn().getBody(Map.class);
assertNotNull(parameters);
assertFalse("There are no parameters in HttpServletRequest.",
parameters.isEmpty());
HttpMethod httpPostMethod = new
PostMethod("http://localhost:8888/testreceivepostdata");
HttpMethodParams params = new HttpMethodParams();
params.setParameter("parameter1", "testParam");
httpPostMethod.setParams(params);
try {
httpClient.executeMethod(httpPostMethod);
} catch (Exception e) {
fail("Failed to execute method.");
}
assertEquals(2, mockEndpoint.getReceivedCounter());
exchange = mockEndpoint.getExchanges().get(1);
parameters = exchange.getIn().getBody(Map.class);
assertNotNull(parameters);
assertFalse("There are no parameters in HttpServletRequest.",
parameters.isEmpty());
}
}
Any hints are appreciated :) Thank you!
Sebastian
--
sebastian münz
__________________________________________
catify consulting
claus straube, sebastian münz
phone +49-89-38157419-1
mobile +49-171-1992074
web http://www.catify.com
office 6. floor, heßstr. 56, 80798 munich
__________________________________________