1
votes

I am trying write a route to call a restful services. all of them donot have a body but query parameters. when i call(https) the rest service i get 401(unauthorised). but if i use simple non-ssl (http) and invoke it works fine on other apis. here is my Route and producer template.

Route

public static final String MONITOR_URI = "https://lsapi.thomson-pharma.com//ls-api-ws/ws/rs/opportunity-v1/match?drug=bevacizumab&company=Genentech Inc&fmt=json";

public static final String DIRECT_MONITOR = "direct:getDrugInfo";

from(DIRECT_MONITOR).to(MONITOR_URI).convertBodyTo(String.class);

=========================Main Class===============================

public static void main(String[] args) throws Exception {
    CamelContext context = createCamelContext();
    context.start();
    final String text = "paracetamol";
    final String fmt = "json";
    final String authMethod = "Digest";
    final String authUsername = "TR_Internal_024";
    final String authPassword="ZTYA5S1KLF7WCDMN";
    final String query = String.format("text=%s&fmt=%s&authMethod=%s&authUsername=%s&authPassword=%s",text,fmt,authMethod,authUsername,authPassword);
    Map<String,Object> headers = new HashMap<String, Object>(){
        {
            put(Exchange.HTTP_METHOD,"POST");
            put(Exchange.AUTHENTICATION,"Digest");
            put("authUsername","TR_Internal_024");
            put("authPassword","ZTYA5S1KLF7WCDMN");
            put(Exchange.HTTP_QUERY,query);
        }
    };
   ProducerTemplate template = context.createProducerTemplate();

  String request = template.requestBodyAndHeaders(Constants.DIRECT_MONITOR,null,headers,String.class);
  System.out.println("Body is : "+request);
}
  1. Can someone help how to configure SSL using camel cxf or restlet ?
  2. How do i add Credentials Provider to CamelContext or Spring Context ?
1
Can someone help how to configure SSL using camel cxf or restlet. - user3022698
I'm not familiar with the Apache Camel + Restlet integration, but regarding HTTPS, did you have a look at Restlet's own documentation on the topic? restlet.com/technical-resources/restlet-framework/guide/2.3/… - glaforge

1 Answers

0
votes

APologies for the delay. i got it worked by retriving the component from camelContext below is the code.

=========================================================================

HttpComponent http = (HttpComponent) camelContext.getComponent("https");
        HttpClientConfigurer httpClientConfigurer = http.getHttpClientConfigurer();
        if(httpClientConfigurer == null){
            System.out.println("httpClientConfigurer is null");
            if(http.getHttpClientConfigurer() == null ){
                HttpConfiguration httpConfiguration = new HttpConfiguration();
                httpConfiguration.setAuthMethod(AuthMethod.Digest);
                httpConfiguration.setAuthUsername("xxxxx");
                httpConfiguration.setAuthPassword("xxxxxx");
                http.setHttpConfiguration(httpConfiguration);
            }
        }

Regards Ram