Attempting to implement a proxy service to route requests dynamically using
DynamicRouter pattern suggested by
http://camel.apache.org/dynamic-router.html. 

I'm unsuccessful though in getting streamcaching to work.  I've enabled
streamcaching on the CamelContext but when the proxysvc forwards the POST
request to my endpoint the body is always empty. 

<camelContext id="camel" streamCache="true"
xmlns="http://camel.apache.org/schema/spring";>
    <routeBuilder ref="CamelRouteBeanId"/>
</camelContext>

Below is my code that perform the slip functionality.

public void configure() throws Exception {

        Processor processor = new MyProcessor();
        
        this.from("servlet:///?matchOnUriPrefix=true")
                .removeHeader(Exchange.HTTP_PATH)
                .dynamicRouter(method(CamelRoute.class, "slip"));
}

public static String slip(String body_p, @Properties Map<String, Object>
propertiesMap_p,
                @Headers Map<String, Object>headersMap_p) {
        
        String serviceEndPoint = null;
        String publicUri = (String)headersMap_p.get(Exchange.HTTP_URI);
        //byte []bodyByteArray = body_p.getBytes();
        if(publicUri != null)
        {                       
                // get the state from the exchange properties and keep track 
how many
times
                // we have been invoked
                int invoked = 0;
                Object current = propertiesMap_p.get("invoked");
                if (current != null) {
                    invoked = Integer.valueOf(current.toString());
                }
                invoked++;
                // and store the state back on the properties
                propertiesMap_p.put("invoked", invoked);
                
                if(invoked == 1)
                {
                        serviceEndPoint = CamelRoute.constructUri();
                }
        }
        
        return serviceEndPoint;        
    }
    
    private static String constructUri()
    {
        String serviceEndPoint = null;                   
        String server = "http://localhost:8080";;
        serviceEndPoint = server 
                +"/sample.restsvc/rest/testresource" 
                +"?bridgeEndpoint=true&throwExceptionOnFailure=false";
        
        return serviceEndPoint;
    }

The Request is forwarded to my http end point but the body is always empty.

Can someone provide information as to whether streamCache works for http end
point?  If i add a processor to route that sets body as string in request
this code works but this work around loads the entire body to memory which
causes issues for large requests.

/Ramon



--
View this message in context: 
http://camel.465427.n5.nabble.com/stream-caching-to-HTTP-end-point-tp5736608.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to