【问题标题】:Invoking Camel Rest services gives me 401 using restlet调用 Camel Rest 服务给我 401 使用 restlet
【发布时间】:2023-03-16 21:28:01
【问题描述】:

我正在尝试编写一条路线来调用宁静的服务。它们都没有正文,而是查询参数。当我调用(https)其余服务时,我得到 401(未经授权)。 但如果我使用简单的 non-ssl (http) 并调用它,它可以在其他 api 上正常工作。 这是我的路线和生产者模板。

路线

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);

==========================主类==================== ===========

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. 谁能帮助如何使用camel cxf或restlet配置SSL?
  2. 如何将 Credentials Provider 添加到 CamelContext 或 Spring Context 中?

【问题讨论】:

标签: rest ssl apache-camel restlet


【解决方案1】:

对于延迟表示歉意。我通过从下面的camelContext中检索组件来实现它的代码。

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

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);
            }
        }

问候 拉姆

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多