3 Replies Latest reply on Jul 1, 2014 1:54 PM by jorgemoralespou_2

    simple http proxy service

    jorgemoralespou_2

      I have been doing a simple Http proxy service (REST and HTTP bindings) and I have struggle with some problems. I think this use case should be very straightforward, as it is a typical use case of "Man in the middle" type of services.

      I will summarize my findings, and hope that some SwitchYard masters will throw some light here if I'm wrong.

       

       

      • To get original request information, you need to access the Context as the request info is copied there.
              HttpRequestInfo requestInfo = msgContext.getPropertyValue(HttpComposition.HTTP_REQUEST_INFO);
              LOGGER.info("********************************************************************************");
              LOGGER.info("method      = {}", requestInfo.getMethod());
              LOGGER.info("pathInfo    = {}", requestInfo.getPathInfo());
              LOGGER.info("queryString = {}", requestInfo.getQueryString());
              LOGGER.info("content     = {}", content);
              LOGGER.info("********************************************************************************");
      

       

      • To set destination HTTP method, uri or query can be set using the Invoker's context (You can not use a plain reference, but rather a ReferenceInvoker):
              Context context = referenceInvoker.newInvocation().getMessage().getContext();
      
              context.setProperty(org.apache.camel.Exchange.HTTP_METHOD, requestInfo.getMethod());
              context.setProperty(org.apache.camel.Exchange.HTTP_URI, REFERENCE_BASE_URL + requestInfo.getPathInfo());
              context.setProperty(org.apache.camel.Exchange.HTTP_QUERY, requestInfo.getQueryString());
      

       

      • Error codes should be set in custom MessageComposer (although it doesn't work very well in some scenarios).
                              exchange.getContext()
                                              .setProperty(HttpContextMapper.HTTP_RESPONSE_STATUS, 404)
                                              .addLabels(new String[] { EndpointLabel.HTTP.label() });
      

       

      • HTTP Headers must be set in the composer to be regex copied:
      <http:contextMapper includes="http.*"/>
      

       

      I think there should be a simple proxy service for HTTP, Rest and SOAP services as quickstarts as this is fairly easy to do with some other products, and it is a very used type of service.

       

      Please, comment on what I have wrong, and I will try to create this quickstarts for the project.