Apache骆驼的肥皂要求

发布于 2025-01-18 02:08:42 字数 2768 浏览 3 评论 0原文

我有一个 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 技术交流群。

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

发布评论

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

评论(2

◇流星雨 2025-01-25 02:08:42

你用弹簧吗?或者只是一个java应用程序?你熟悉豆子吗?

@Value() - 用于从 application.properties 注入数据。
定义你的字符串 URL

String WSDL_URL = "YOUR_URL".

或者只是将地址放入你的 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;
    }
}

同时使用 @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");            
    }

}

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

String WSDL_URL = "YOUR_URL".

Or just put address into your 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.

@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");            
    }

}
初见 2025-01-25 02:08:42

您可以使用定义的 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;
    }
    
}

在路由中使用它之后:

 .to("cxf:bean:cxfConvertTemp")

You can use defined bean instead:

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