【问题标题】:Apache Camel - Simple HTTPS Google Places Call - Difference between Spring DSL and Java DSL for Camel-http component ?Apache Camel - 简单的 HTTPS Google Places Call - Camel-http 组件的 Spring DSL 和 Java DSL 之间的区别?
【发布时间】:2012-03-15 21:39:51
【问题描述】:

我正在尝试将使用 Apache Camel (2.10-SNAPSHOT) 和 Spring (3.0.7.RELEASE) 的 Google Places API 与 Tomcat (7.0.26) 集成为我的网络容器服务器。

当我在 Spring config xml 中声明路由时(见下文),我可以在我的 Tomcat 日志中看到正确的输出响应。

<route id="google-places-route">
        <from uri="direct:start" />
        <to uri="https://maps.googleapis.com/maps/api/place/search/json?location=40.446788,-79.950559&amp;radius=500&amp;types=food&amp;sensor=false&amp;key=my-google-api-key" />
        <to uri="stream:out"/>
        </split>        
</route>

请注意这里使用的骆驼方案是 https 而不是 http。

现在,我正在尝试通过在扩展 RouterBuilder 的 Java 类中定义我的路由来做同样的事情

public class GooglePlacesRoute extends RouteBuilder {

@Override
public void configure() throws Exception {

    from("direct:start").process(new MyCustomProcessor()).to("https://maps.googleapis.com/maps/api/place/search/json?location=40.446788,-79.950559&amp;radius=500&amp;types=food&amp;sensor=false&amp;key=my-google-api-key").to("stream:out");
}

}


类 MyCustomProcessor 实现处理器 {

@Override
public void process(Exchange exchange) throws Exception {

    exchange.setPattern(ExchangePattern.InOut);
        Message inMessage = exchange.getIn();


    inMessage.setHeader(Exchange.HTTP_METHOD, "GET");
    exchange.getIn().setBody("", String.class);

}

}

我的骆驼路线已正确部署并启动。但是,当我调用它时,我没有得到预期的输出。我从 Google 的服务器收到以下响应。

{ "html_attributions" : [], "results" : [], "status" : "REQUEST_DENIED" }

我假设我不需要在我的 Java DSL 中做任何特别的事情来处理 HTTPS(而不是 HTTP)。这个假设正确吗?

我在这里缺少什么?

谢谢。

【问题讨论】:

    标签: spring tomcat7 apache-camel google-places-api


    【解决方案1】:

    尝试在您的请求中使用&amp;amp; 而不是&amp;amp;

    https://maps.googleapis.com/maps/api/place/search/json?location=40.446788,-79.950559&radius=500&types=food&sensor=false&key=my-google-api-key
    

    【讨论】:

      猜你喜欢
      • 2016-05-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      相关资源
      最近更新 更多