Apache骆驼的肥皂要求
我有一个 wsdl 文件托管在一个网站上(我无法共享),并且我想通过 apache-camel 框架调用肥皂请求。 我创建了一个maven项目,并使用组件apache-cxf来编译.wsdl文件,我得到了所有.java文件。 现在我定义了一个 CamelContext 和一个 RouteBuilder 来发送请求,但我不确定我是否理解流程。
这是我的 CamelContext:
/**
* A Camel Application
*/
public class MainApp {
private static final long DURATION_MILIS = 1000;
/**
* A main() so we can easily run these routing rules in our IDE
*/
public static void main(String... args) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new MyRouteBuilder());
System.out.println("================== STARTING ==================");
camelContext.start();
Thread.sleep(DURATION_MILIS);
System.out.println("================== CLOSING ==================");
camelContext.stop();
}
}
这是我的 RouteBuilder:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.springframework.stereotype.Component;
@Component
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer://start?repeatCount=1")
.setBody(constant("11"))
.bean(NumberToWordsRequestBuilder.class)
.log("OPERATION_NAME: "+CxfConstants.OPERATION_NAME)
.setHeader(CxfConstants.OPERATION_NAME, constant("NumberToWords"))
.log("OPERATION_NAMESPACE: "+CxfConstants.OPERATION_NAMESPACE)
.setHeader(CxfConstants.OPERATION_NAMESPACE, constant("http://www.dataaccess.com/webservicesserver/"))
.to("cxf:bean:cxfConvertTemp")
//or you can use .to("cxf://someAddress[?options]")
// You can retrieve fields from the response using the Simple language
.log("The title is: ${body[0].book.title}")
.to("mock:output");
}
}
我的 CxfEndpoint 类:
import org.apache.camel.component.cxf.CxfEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.apache.test.NumberConversion.NumberConversionSoapType;
@Configuration
public class CxfBeans {
@Bean(name = "cxfConvertTemp")
public CxfEndpoint buildCxfEndpoint() {
CxfEndpoint cxf = new CxfEndpoint();
cxf.setAddress("https://www.dataaccess.com/webservicesserver/NumberConversion.wso");
cxf.setServiceClass(NumberConversionSoapType.class);
cxf.setWsdlURL("https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL");
return cxf;
}
}
我不明白的是,.wsdl 托管在一个站点上,但所有教程都用作 cxf-endpoint localhost。 有人可以帮助我吗?谢谢。
i have a wsdl file hosted on a site (which i can't share), and i want to invoke a soap request through apache-camel framework.
I created a maven project, and used the component apache-cxf to compile the .wsdl file and i got all the .java files.
Now i defined a CamelContext and a RouteBuilder to send request, but i am not sure if i understand the flow.
This is my CamelContext:
/**
* A Camel Application
*/
public class MainApp {
private static final long DURATION_MILIS = 1000;
/**
* A main() so we can easily run these routing rules in our IDE
*/
public static void main(String... args) throws Exception {
CamelContext camelContext = new DefaultCamelContext();
camelContext.addRoutes(new MyRouteBuilder());
System.out.println("================== STARTING ==================");
camelContext.start();
Thread.sleep(DURATION_MILIS);
System.out.println("================== CLOSING ==================");
camelContext.stop();
}
}
This is my RouteBuilder:
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.message.CxfConstants;
import org.springframework.stereotype.Component;
@Component
public class MyRouteBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer://start?repeatCount=1")
.setBody(constant("11"))
.bean(NumberToWordsRequestBuilder.class)
.log("OPERATION_NAME: "+CxfConstants.OPERATION_NAME)
.setHeader(CxfConstants.OPERATION_NAME, constant("NumberToWords"))
.log("OPERATION_NAMESPACE: "+CxfConstants.OPERATION_NAMESPACE)
.setHeader(CxfConstants.OPERATION_NAMESPACE, constant("http://www.dataaccess.com/webservicesserver/"))
.to("cxf:bean:cxfConvertTemp")
//or you can use .to("cxf://someAddress[?options]")
// You can retrieve fields from the response using the Simple language
.log("The title is: ${body[0].book.title}")
.to("mock:output");
}
}
My CxfEndpoint class:
import org.apache.camel.component.cxf.CxfEndpoint;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.apache.test.NumberConversion.NumberConversionSoapType;
@Configuration
public class CxfBeans {
@Bean(name = "cxfConvertTemp")
public CxfEndpoint buildCxfEndpoint() {
CxfEndpoint cxf = new CxfEndpoint();
cxf.setAddress("https://www.dataaccess.com/webservicesserver/NumberConversion.wso");
cxf.setServiceClass(NumberConversionSoapType.class);
cxf.setWsdlURL("https://www.dataaccess.com/webservicesserver/NumberConversion.wso?WSDL");
return cxf;
}
}
What i am not understanding, is that the .wsdl is hosted on a site but all the tutorial use as cxf-endpoint localhost.
Can someone help me? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你用弹簧吗?或者只是一个java应用程序?你熟悉豆子吗?
@Value() - 用于从 application.properties 注入数据。
定义你的字符串 URL
或者只是将地址放入你的 bean 中:
同时使用 @Component 注释你的路由。
Are you using spring? Or just a java app? Are you familiar with beans?
@Value() - shall be used for injecting data from application.properties.
Define your String URL like
Or just put address into your bean:
Also make your route annotated with @Component.
您可以使用定义的 bean 来代替:
在路由中使用它之后:
You can use defined bean instead:
and after use it in the route: