Apache Camel SOAP/CXF 向服务器发出请求(Spring Boot)

发布于 2025-01-18 01:51:50 字数 4049 浏览 0 评论 0原文

我正在尝试在 Apache Camel CXF 的帮助下向专用 WSDL 服务器发出请求。

我有 WSDL URL: http://www.learnwebservices.com/services/tempconverter?wsdl

我已经使用 cxf-codegen-plugin 创建 WSDL 的 Java 类:

 <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.4.2</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                        <configuration>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/tempconverter.wsdl</wsdl>
                                    <packagenames>
                                        <packagename>office.planet.integrations.merlion</packagename>
                                    </packagenames>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

我有以下 Camel 路线:

@Component
public class MerlionRoute
      extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("direct:celsius-to-fahrenheit")
              .process(exchange -> {
                  System.out.println("HELLO!!!!!");
                  CelsiusToFahrenheitRequest c = new CelsiusToFahrenheitRequest();
                  c.setTemperatureInCelsius(Double.valueOf(exchange.getIn().getHeader("num").toString()));
                  exchange.getIn().setBody(c);
              })
              .setHeader(CxfConstants.OPERATION_NAME, constant("CelsiusToFahrenheit"))
              .setHeader(CxfConstants.OPERATION_NAMESPACE, constant("{{endpoint.namespace}}"))
              .to("cxf:bean:cxfConvertTemp")
              .process(exchange -> {
                  System.out.println("WE ARE HERE");
                  MessageContentsList response = (MessageContentsList) exchange.getIn().getBody();
                  CelsiusToFahrenheitResponse r = (CelsiusToFahrenheitResponse) response.get(0);
                  exchange.getIn().setBody("Temp in Farenheit: "+r.getTemperatureInFahrenheit());
                  System.out.println(r.getTemperatureInFahrenheit());
              })
              .end();
    }
}

EndPoint 的 Bean 类:

@Configuration
public class CxfBeans {
    @Value("${endpoint.wsdl}")
    private String SOAP_URL;
    
    @Bean(name = "cxfConvertTemp")
    public CxfEndpoint buildCxfEndpoint() {
        CxfEndpoint cxf = new CxfEndpoint();
        cxf.setAddress(SOAP_URL);
        cxf.setServiceClass(TempConverterEndpoint.class);
        cxf.setWsdlURL(SOAP_URL);
        return cxf;
    }
}

以及 WSDL 端点:

endpoint.wsdl=http://www.learnwebservices.com/services/tempconverter?wsdl
endpoint.namespace=http://learnwebservices.com/services/tempconverter

当我启动该项目时,我的路线开始,但没有任何反应。 我只能看到这一点:

2022-03-31 18:41:44.933  INFO 44313 --- [  restartedMain] o.a.c.w.s.f.ReflectionServiceFactoryBean : Creating Service {http://learnwebservices.com/services/tempconverter}TempConverterEndpointService from WSDL: http://www.learnwebservices.com/services/tempconverter?wsdl

如何从 Camel CXF 内的 WSDL 服务器请求数据?我做错了什么?

I am trying to make requests to dedicated WSDL server with the help of Apache Camel CXF.

I have the WSDL URL:
http://www.learnwebservices.com/services/tempconverter?wsdl

I've made the Java classes of WSDL using the cxf-codegen-plugin:

 <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.4.2</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                        <configuration>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/tempconverter.wsdl</wsdl>
                                    <packagenames>
                                        <packagename>office.planet.integrations.merlion</packagename>
                                    </packagenames>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

I have the following Camel route:

@Component
public class MerlionRoute
      extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("direct:celsius-to-fahrenheit")
              .process(exchange -> {
                  System.out.println("HELLO!!!!!");
                  CelsiusToFahrenheitRequest c = new CelsiusToFahrenheitRequest();
                  c.setTemperatureInCelsius(Double.valueOf(exchange.getIn().getHeader("num").toString()));
                  exchange.getIn().setBody(c);
              })
              .setHeader(CxfConstants.OPERATION_NAME, constant("CelsiusToFahrenheit"))
              .setHeader(CxfConstants.OPERATION_NAMESPACE, constant("{{endpoint.namespace}}"))
              .to("cxf:bean:cxfConvertTemp")
              .process(exchange -> {
                  System.out.println("WE ARE HERE");
                  MessageContentsList response = (MessageContentsList) exchange.getIn().getBody();
                  CelsiusToFahrenheitResponse r = (CelsiusToFahrenheitResponse) response.get(0);
                  exchange.getIn().setBody("Temp in Farenheit: "+r.getTemperatureInFahrenheit());
                  System.out.println(r.getTemperatureInFahrenheit());
              })
              .end();
    }
}

The Bean class of the EndPoint:

@Configuration
public class CxfBeans {
    @Value("${endpoint.wsdl}")
    private String SOAP_URL;
    
    @Bean(name = "cxfConvertTemp")
    public CxfEndpoint buildCxfEndpoint() {
        CxfEndpoint cxf = new CxfEndpoint();
        cxf.setAddress(SOAP_URL);
        cxf.setServiceClass(TempConverterEndpoint.class);
        cxf.setWsdlURL(SOAP_URL);
        return cxf;
    }
}

And the WSDL endpoint:

endpoint.wsdl=http://www.learnwebservices.com/services/tempconverter?wsdl
endpoint.namespace=http://learnwebservices.com/services/tempconverter

When I am launching the project, my route starts, but nothing happens.
Only this I can see:

2022-03-31 18:41:44.933  INFO 44313 --- [  restartedMain] o.a.c.w.s.f.ReflectionServiceFactoryBean : Creating Service {http://learnwebservices.com/services/tempconverter}TempConverterEndpointService from WSDL: http://www.learnwebservices.com/services/tempconverter?wsdl

How shall I request the data from WSDL server within the Camel CXF? What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

表情可笑 2025-01-25 01:51:50

您的路线需要触发。就目前而言,没有什么可以从Endpoint 中称您为“直接:Celsius-to-Fahrenheit”,因此实际上什么也没有发生。

假设您只想将此路线触发一次,则可以将您的从端点定义为“ timer:// celsius-to-to-to-fahrenheit?repotcount = 1”

参见骆驼计时器组件

Your route needs to be triggered. As it stands, nothing calls your from endpoint "direct:celsius-to-fahrenheit", and thus indeed, nothing happens.

Assuming you want this route to be triggered only once, you could define your from endpoint as "timer://celsius-to-fahrenheit?repeatCount=1".

See Camel Timer component.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文