A new method is added to the cxfrs contract in order to show the POST method
package org.apache.camel.example.cxf;import javax.ws.rs.GET;import javax.ws.rs.POST;import javax.ws.rs.Path;import javax.ws.rs.PathParam;import javax.ws.rs.core.Response;@Path("/RsService/")public interface RsService{@GET@Path("/SayHello/{Name}")public Response SayHello (@PathParam("Name") String pName);@POST@Path("/SayByeBye/")public Response SayByeBye ();}
And add logging for the headers in the camel exchange :
package org.apache.camel.example.cxf;import java.util.Map;import java.util.logging.Level;import java.util.logging.Logger;import javax.ws.rs.core.Response;import org.apache.camel.Exchange;import org.apache.camel.Message;import org.apache.camel.Processor;import org.apache.camel.builder.RouteBuilder;public class CamelRoute extends RouteBuilder {private String uri ="cxfrs:/myData?resourceClasses=org.apache.camel.example.cxf.RsService&bindingStyle=SimpleConsumer";static Logger myLogger = Logger.getLogger(CamelRoute.class.getName());@Overridepublic void configure() throws Exception {from(uri).process(new Processor() {public void process(Exchange exchange) throws Exception {Message inMessage = exchange.getIn();Map<String, Object> theHeaders = inMessage.getHeaders();String theResult= "";for ( String NextHeader : theHeaders.keySet()){theResult += NextHeader + ":" + theHeaders.get(NextHeader) + "\r\n";}String theBody = inMessage.getBody(String.class);theResult += "The Body:" + theBody;myLogger.setLevel (Level.INFO );myLogger.log(Level.INFO , theResult );Response r = Response.ok("This is the result\r\n" +theBody).status(200).build();exchange.getOut().setBody(r);}});}}
And the Results: (The get method )
The logging:
The Post method
The logging
אין תגובות:
הוסף רשומת תגובה