Calling a web service from Java code - Mendix Forum

Calling a web service from Java code

0

My current situation is as follows:

I have a Web Service which sends out a SOAP request to a fixed address. For each of my customers I need to call this service using a different certificate. Since this is not supported in the modeler I had to resort to pure Java actions in this case. Thanks to the mendix support I figured out how to extract the right certificate for the web service call. The next step is of course to call said service using the provided certificate.

There are roughly 2 scenario’s which I can imagine:

  1. The ability to set the certificate and then call the web service (or a microflow) from Java code using said certificate.
  2. Creating a web service in java (JAX-WS) by completely setting it up in java and forcing a certificate.

 

Option 1 has the absolute preference here since the calls themselves are pretty big/complex, but I could live with the second option.

Does anyone know if option 1 is doable?

asked
1 answers
0

Hi Ludo, 

With Option one you can set a certificate in java action, which is not necessary you have to call a web service from Java it self. 

You can follow the steps to call the 

1) You can send a SOAP Request xml, Certificate and password to Java to Sign this request. 

 

2) Read all the Signed request headers vulues and populate Return Object 
3) You can sign only body of request so that even if you change headers from mendix it should work or you can used complete Signed xml request(Return XML as string from JAVA)

        DOMSignContext dsc = new DOMSignContext(this.getGetPrivateKey(), node);
        
        // Create the XMLSignature, but don't sign it yet.
        XMLSignature signature = xmlSigFactory.newXMLSignature(SignedInfo, null);

        Core.getLogger("SignXML").info("Signing Document :");

        DOMSignContext dsc = new DOMSignContext(this.getGetPrivateKey(), node);
        
        // Create the XMLSignature, but don't sign it yet.
        XMLSignature signature = xmlSigFactory.newXMLSignature(si, null);

        Core.getLogger("SignXML").info("Signing Document :");
 

4) Now from mendix you can call the service with certificate which you used to sign(In Java). 

Hope this will help for you. 

Regards

Sagar

 

answered