[英]Soap Request with Apache Camel
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.我在网站上托管了一个 wsdl 文件(我无法共享),我想通过 apache-camel 框架调用 soap 请求。 I created a maven project, and used the component apache-cxf to compile the.wsdl file and i got all the.java files.
我创建了一个 maven 项目,并使用组件 apache-cxf 编译了 .wsdl 文件,我得到了所有的 .java 文件。 Now i defined a CamelContext and a RouteBuilder to send request, but i am not sure if i understand the flow.
现在我定义了一个 CamelContext 和一个 RouteBuilder 来发送请求,但我不确定我是否理解流程。
This is my CamelContext:这是我的 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:这是我的 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:我的 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.我不明白的是,.wsdl 托管在一个站点上,但所有教程都用作 cxf-endpoint 本地主机。 Can someone help me?
有人能帮我吗? Thank you.
谢谢你。
Are you using spring?您使用的是 spring 吗? Or just a java app?
或者只是一个 java 应用程序? Are you familiar with beans?
你熟悉豆子吗?
@Value() - shall be used for injecting data from application.properties. @Value() - 应用于从 application.properties 注入数据。 Define your String URL like
像这样定义你的字符串 URL
String WSDL_URL = "YOUR_URL".
Or just put address into your bean:或者只是将地址放入您的 bean 中:
@Configuration
public class CxfBeans {
@Bean(name = "cxfConvertTemp")
public CxfEndpoint buildCxfEndpoint() {
CxfEndpoint cxf = new CxfEndpoint();
cxf.setAddress("YOUR URL STRING");
cxf.setServiceClass(TempConverterEndpoint.class);
cxf.setWsdlURL("YOUR URL STRING");
return cxf;
}
}
Also make your route annotated with @Component.还要使您的路由带有 @Component 注释。
@Componet
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");
}
}
You can use defined bean instead:您可以改用定义的 bean:
@Configuration
public class CxfBeans {
@Value("${endpoint.wsdl}") //url will be defined in application.properties - your wsdl url address (not localhost)
private String SOAP_URL;
@Bean(name = "cxfConvertTemp")
public CxfEndpoint buildCxfEndpoint() {
CxfEndpoint cxf = new CxfEndpoint();
cxf.setAddress(SOAP_URL);
//service class of your wsdl
cxf.setServiceClass(TempConverterEndpoint.class);
return cxf;
}
}
and after use it in the route:在路线中使用它之后:
.to("cxf:bean:cxfConvertTemp")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.