【问题标题】:How can I bridge HTTP and SMPP with Camel?如何使用 Camel 桥接 HTTP 和 SMPP?
【发布时间】:2013-05-20 05:30:38
【问题描述】:

以下代码尝试设置 Camel 路由以接收 HTTP POST 并通过 SMPP 将它们作为 SMS 消息发送:

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class SMSA {
    public static void main(String[] args) throws Exception {
        CamelContext context = new DefaultCamelContext();
        RouteBuilder builder = new RouteBuilder() {
            @Override
            public void configure() throws Exception {
                errorHandler(loggingErrorHandler());

                from("jetty:http://localhost:9993").
                    setHeader("CamelSmppDestAddr", header("deliveryAddress")).
                    to("smpp://smppclient1@localhost:2775?password=password&sourceAddr=1234")
                ;
            }
        };
        builder.addRoutesToCamelContext(context);
        context.start();
    }
}

一开始好像可以(发短信),但是消息都是空的。

我使用以下命令进行测试:

curl -X POST -d "Hello World!" --header "Content-Type:text/plain" "http://localhost:9993?deliveryAddress=1818"

如果我添加自定义处理器并调用

exchange.getIn().getBody(String.class)

(如http://camel.apache.org/jetty.html 上的示例),然后我可以看到发布的消息。

【问题讨论】:

    标签: java http apache-camel smpp


    【解决方案1】:

    我自己解决了 - 我的解决方法是将路线更改为:

    from("jetty:http://localhost:9993").
        setHeader("CamelSmppDestAddr", header("deliveryAddress")).
        setHeader("CamelSmppAlphabet", constant(4)).
        to("smpp://smppclient1@localhost:2775?password=password&sourceAddr=1234")
    ;
    

    查看 Camel 2.9.0 和 2.11.0 之间的某些代码,行为似乎已更改为默认情况下需要一个 byte[],除非明确定义了字母表。由于我发布了文本/纯正文,因此它不起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-14
      • 1970-01-01
      • 1970-01-01
      • 2014-02-21
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多