使用Java DSL从WSO2转换为骆驼:如何使用URI模式转发

问题描述 投票:0回答:1

我要从堆栈中删除WSO2,我必须在Camel Java DSL中编写在WSO2中实现的端点。

在WSO2中,我们有一个如下端点:

<resource methods="OPTIONS GET" uri-template="/request/{data}" inSequence="requestreset"/>
<http method="GET" uri-template="http://127.0.0.1/index.php?_q=requestreset&amp;data={uri.var.data}"/>

我在Java Camel的Router中的代码是:


public class DefaultRouteBuilder extends RouteBuilder {

    private HashMap<String, String> routeCorresponding = new HashMap();

    @Override
    public void configure() throws Exception {

        routeCorresponding.put("reset/request/{data}", "http://127.0.0.1/index.php?_q=requestreset&data={data}");

        for (Map.Entry<String, String> pair : routeCorresponding.entrySet()) {
            String url = pair.getKey();
            String target = pair.getValue();

            String resultTarget = target.contains("?") ? target + "&bridgeEndpoint=true" : target + "?bridgeEndpoint=true";

            fromF("servlet:"+ url +"?matchOnUriPrefix=true")
                    .log("Request: ${in.header."+ Exchange.HTTP_METHOD +"} to ${in.header."+ Exchange.HTTP_URI +"}")
                    .toF(resultTarget);
        }

    }

}

但是它并不能如我所愿,因为当我向tomcat.myserver.com:8080/camel-example-servlet/reset/request/blablablablabla发出请求时,我得到了一个响应:org.apache.camel.http.common.HttpOperationFailedException: HTTP operation failed invoking http://127.0.0.1/index.php/reset/request/blablablablabla?_q=requestreset&data=%7Bdata%7D with statusCode: 404

而不是http://127.0.0.1/index.php/reset/request/blablablablabla?_q=requestreset&data=%7Bdata%7D,我希望以下请求出现在http://127.0.0.1/index.php?_q=requestreset&data=blablablablabla

是否可以在Camel / Java DSL中实现?基本上,WSO2使用URI模板和围绕字段的大括号实现了什么?

java routing wso2 apache-camel
1个回答
0
投票

您绝对可以实现这一点-但您的{data}块存储为标头,因此您需要refer to it as ${header.data} in your target URI

这是使用${header.data}的示例:

the REST DSL
© www.soinside.com 2019 - 2024. All rights reserved.