Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facing an error while Invoking a SOAP service method from Camel-K #3973

Closed
gtata007 opened this issue Jan 12, 2023 · 7 comments
Closed

Facing an error while Invoking a SOAP service method from Camel-K #3973

gtata007 opened this issue Jan 12, 2023 · 7 comments
Labels
kind/question Further information is requested

Comments

@gtata007
Copy link

gtata007 commented Jan 12, 2023

Hello Everyone,

I am trying a POC to invoke a sample SOAP service from Camel-K. My requirement is very simple I have a simple XML Payload which i need to pass to the SOAP operation. Is there any way to achieve this without having wsdl2java jax-ws client classes generation?
The sample code looks as below.

Camel-k Version : Camel K Client 1.10.2

Service : http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?wsdl

// camel-k: language=java

import javax.xml.stream.events.Namespace;
import org.apache.camel.support.builder.Namespaces;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.Processor;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.component.cxf.common.message.CxfConstants;

public class TestWeb extends RouteBuilder {
  @Override
  public void configure() throws Exception {
    String WS_URI="cxf://http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?dataFormat=PAYLOAD";
    Namespaces web = new Namespaces("web", "http://www.oorsprong.org/websamples.countryinfo");
      from("timer:java?period=100000")
        .routeId("java")
        .setBody()
          `.simple("<web:CountryCurrency xmlns:web=\"http://www.oorsprong.org/websamples.countryinfo\"><web:sCountryISOCode>IN</web:sCountryISOCode></web:CountryCurrency>")`
        .setHeader(CxfConstants.OPERATION_NAMESPACE, constant("http://www.oorsprong.org/websamples.countryinfo"))
        .setHeader(CxfConstants.OPERATION_NAME, constant("CountryCurrency"))
        .to("cxf://http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso?dataFormat=PAYLOAD")
        .to("log:info");
  }
}

Run command:
kamel run -d camel:cxf-soap TestWeb.java --dev -t logging.level=DEBUG

Appreciate any valuable thoughts or suggestions on this.

Regards,
Guru Tata

@squakez squakez added the kind/question Further information is requested label Jan 12, 2023
@squakez
Copy link
Contributor

squakez commented Jan 12, 2023

Hello, I think you may have a look at the following resources in order to test your route. I also suggest to have a working version in Camel/Camel Quarkus before trying to run in Camel K (ie, via Camel JBang) to simplify the troubleshooting in a local environment.

Please refer to Camel Quarkus CXF component documentation, Camel CXF component documentation and the following Camel Quarkus CXF unit test that may give you hints on how to develop the route correctly (ie, it seems you're missing serviceClass parameter).

@gtata007
Copy link
Author

gtata007 commented Jan 15, 2023

Thank you @squakez, I am trying to use Camel JBang and it is really helpful to debug the issues locally with the camel version.
Here, I have encountered a few issues.

  1. While I am trying to run the Camel version with 1.10.2 by using the below command it is not working. Any suggestions on this?
    jbang run TestWeb.java -Dcamel.jbang.version=3.18.2 camel@apache/camel ---

I found the solution for the first question - Please ignore
Solution: This is working at CMD prompt : "jbang -Dcamel.jbang.version=3.18.2 camel@apache/camel run TestWeb.java"

  1. Do you have any examples or references of calling a SOAP web service and passing the request Payload? for example using the dataFormat as PAYLOAD option, can we directly hit the SOAP web service? Could you share a sample if any?

  2. While running my application on jbang, the maven repository it is pointing to is not having the required CXF jars. So, I explicitly added the repository compile time as below to download the CXF jars. Will this work while building the same program on OpenShift with CamelK?
    camel run TestWeb.java --deps=camel-cxf:3.17.0 --repos=https://repo.maven.apache.org/maven2 --dev --console

Regards,
Guru Tata

@squakez
Copy link
Contributor

squakez commented Jan 16, 2023

2. Do you have any examples or references of calling a SOAP web service and passing the request Payload? for example using the dataFormat as PAYLOAD option, can we directly hit the SOAP web service? Could you share a sample if any?

Sorry, I don't have any example. You may check in the Camel Quarkus test or Camel examples maybe.

3. While running my application on jbang, the maven repository it is pointing to is not having the required CXF jars. So, I explicitly added the repository compile time as below to download the CXF jars. Will this work while building the same program on OpenShift with CamelK?
   **camel run TestWeb.java --deps=camel-cxf:3.17.0 --repos=https://repo.maven.apache.org/maven2 --dev --console**

Yes, in that case it will use the apache maven repo. If it's not in the maven repo you normally use, you can adjust the configuration to use any additional repo as you're doing.

@gtata007
Copy link
Author

Hi @squakez ,

Thank you for all your suggestions on this CXF SOAP invocation. Here I am attaching the sample code from GitHub. and the command i use to run is as below.

https://github.com/gtata007/camel-k-soap/tree/develop

camel run TestWeb.java --deps=camel-cxf:3.14.0

While I am trying to build/run the application with the camel command, it started throwing an error. Because it is unable to reference the java package/classes from the repository in my route builder java code. What are the possible ways to build this application by referring to the class files?

Below is the error stack trace for reference.

org.joor.ReflectException: Compilation error:
/TestWeb.java:5: error: package org.oorsprong.websamples_countryinfo does not exist
import org.oorsprong.websamples_countryinfo.CountryInfoService;
^

    at org.apache.camel.dsl.java.joor.MultiCompile.compileUnit(MultiCompile.java:144)
    at org.apache.camel.dsl.java.joor.JavaRoutesBuilderLoader.doLoadRoutesBuilders(JavaRoutesBuilderLoader.java:122)
    at org.apache.camel.dsl.support.ExtendedRouteBuilderLoaderSupport.loadRoutesBuilders(ExtendedRouteBuilderLoaderSupport.java:48)
    at org.apache.camel.impl.engine.DefaultRoutesLoader.findRoutesBuilders(DefaultRoutesLoader.java:119)
    at org.apache.camel.main.DefaultRoutesCollector.collectRoutesFromDirectory(DefaultRoutesCollector.java:148)
    at org.apache.camel.main.RoutesConfigurer.configureRoutes(RoutesConfigurer.java:187)
    at org.apache.camel.main.BaseMainSupport.configureRoutes(BaseMainSupport.java:652)
    at org.apache.camel.main.MainSupport.initCamelContext(MainSupport.java:404)
    at org.apache.camel.main.KameletMain.doInit(KameletMain.java:265)
    at org.apache.camel.support.service.BaseService.init(BaseService.java:83)
    at org.apache.camel.support.service.BaseService.start(BaseService.java:111)
    at org.apache.camel.dsl.jbang.core.commands.Run.run(Run.java:560)
    at org.apache.camel.dsl.jbang.core.commands.Run.call(Run.java:208)
    at org.apache.camel.dsl.jbang.core.commands.Run.call(Run.java:75)
    at picocli.CommandLine.executeUserObject(CommandLine.java:2041)
    at picocli.CommandLine.access$1500(CommandLine.java:148)
    at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2461)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2453)
    at picocli.CommandLine$RunLast.handle(CommandLine.java:2415)
    at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2273)
    at picocli.CommandLine$RunLast.execute(CommandLine.java:2417)
    at picocli.CommandLine.execute(CommandLine.java:2170)
    at org.apache.camel.dsl.jbang.core.commands.CamelJBangMain.run(CamelJBangMain.java:129)
    at main.CamelJBang.main(CamelJBang.java:36)

Can you please throw some light on this issue?

Regards,
Guru

@squakez
Copy link
Contributor

squakez commented Jan 24, 2023

This looks to be a generic Camel JBang question. I invite you to post the question to the chat or users/dev camel mailing list to have a wider audience and receive help.

@gtata007
Copy link
Author

Hi @squakez ,
I found another way of doing this SOAP invocation. I directly invoked the HTTP Methods. Below is the piece of code it worked for me and it is returning the response.

TestWeb.java

// camel-k: language=java

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.Processor;
import org.apache.camel.Exchange;

import org.apache.camel.Message;
// import org.apache.camel.component.cxf.common.message.CxfConstants;

public class TestWeb extends RouteBuilder {
@OverRide
public void configure() throws Exception {

  from("timer:java?period=100000")
    .routeId("java")
    .setHeader("SOAPAction", constant("CountryCurrency")) // SOAPAction to invoke the method.
    .setHeader(Exchange.HTTP_METHOD, constant("POST")) // HTTP Method
    .setHeader(Exchange.CONTENT_TYPE, constant("text/xml")) // Content Type
    .setBody()
    .simple("<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:web=\"http://www.oorsprong.org/websamples.countryinfo\"> <soapenv:Header/><soapenv:Body><web:CountryCurrency><web:sCountryISOCode>IN</web:sCountryISOCode></web:CountryCurrency> </soapenv:Body></soapenv:Envelope>")


    .to("http://webservices.oorsprong.org/websamples.countryinfo/CountryInfoService.wso")
    .log("response: ${body}");

}
}

Regards,
Guru

@squakez
Copy link
Contributor

squakez commented Jan 26, 2023

Glad it worked and thanks to provide the example for any future reference!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants