Issue with replacing SOAP End point at run time - java

We are trying to consume SOAP service (in Java application) which has different end points in prod and pre-prod environments. We generated the client code using wsimport and trying to override the endpoint using binding provider.
Binding provider works fine in pre prod environment ( auto generated code was from pre prod environment wsdl) But when we try to do the testing in production environment , binding provider is not able to override the endpoint.
In production environment it throws " Connection failed when it tries to connect to pre prod".
We learned that binding provider needs access for pre prod wsdl and prod wsdl to override the endpoint. Due to security group restrictions we cant access proprod wsdl from prod.
We also tried to read the end point by calling the service from prod wsdl at run time but port information in wsdl is hardcoded to some IP address and can't be changed and fixing prod wsdl is beyond our control.
Is there any other way to override the endpoint at run time?

You can either use UDDI like solution and keep versioning for your SOAP endpoints or you can use gateway service. This single service will direct the call internally to different services at runtime.
I prefer UDDI because it allows lots of flexibility.
refer: https://docs.oracle.com/cd/E17904_01/admin.1111/e15867/uddi.htm#OSBAG392

Main cause for the problem was stubs were having hardcoded QA endpoints. I modified the client stub code, Removed the hardcoded end-points from proxy generated code and Binding provider started working fine.All other solutions were time consuming and environment level changes were required for using gateway services.

Related

Framework for Integration Test in a Microservice [duplicate]

I am exploring Karate API double (mocking) for the integration test. For the below scenarios, I'm not getting the expected mocking response. Your help will be appreciated.
My Setup :
1. Karate Mock Server up with pathMatches rules on port 8001: http://localhost:8001 ( working, validated against "/cat" and some test calls)
2. My own Application is up from docker on port 8080. From Docker exposed 8001 port as well.
Mocking Case:
1. My application REST call exposed to all users http://localhost:8080/service/v1/findUser. This exposed API, underlying calling other REST call http://dev-STG/userservice/v1/findUser which actually giving JSON response. So, I want to mock underlying API call and validate my API behavior accordingly.
Steps tried:
1. Now, in my application config, m replacing actual underlying API call to Karate mock server(http://localhost:8001/userservice/v1/findUser). Then did build & up my application docker.
In Karate, I defined test e.g "testIntgrtn.feature" which calling my application API "http://localhost:8080/service/v1/findUser" and Karate mock server up and set with pathmatch "/userservice/v1/findUser".
After executing "testIntgrtn.feature" karate not mocking for an underlying call(http://localhost:8001/userservice/v1/findUser).
Now, in "testIntgrtn.feature" file I changed my-application URL to underlying REST URL i.e (http://localhost:8001/userservice/v1/findUser) then mocking will work like charm.
I'm not understanding why underlying API call not getting mocked here? Did I miss something here?
Also, in Karate can we monitor all REST calls (like cypress mocking).
Thanks for this wonderful framework. Which is intuitive for writing automation cases.
Karate cannot automatically intercept calls.
The recommended approach is when you boot the application running at localhost:8080 you change the configuration so that instead of calling http://dev-stg/userservice/v1/findUser it calls something like http://localhost:8001/v1/findUser. This is what most teams do, and is easy because you should anyway be defining external URL-s as application.properties (or equivalent) as a best-practice.
It is very easy to over-ride an application property in Spring Boot for example, you can do this via the command-line: https://stackoverflow.com/a/37053004/143475
If you want, you can dynamically provision a port for the mock. So your unit test can first start a mock, get the port, and then start the server. You can find details in the Karate documentation.
All this said, if you are able to change the (system) HTTP proxy before the app at localhost:8080 starts, you may be able to do this without modifying the configuration. (But it is tricky, so I recommend the approach explained above.) So in this case, Karate can actually "intercept" the outgoing HTTP calls that the app at localhost:8080 makes.
See the second-last row (5a) in the table here: https://github.com/intuit/karate/tree/master/karate-netty#consumer-provider-example

WSDL generation behind load balancer

I have the following issue with my JAX-WS Ri webservice:
Let's say an external user wants to connect to the webservice with an url. During the request (which passes through a load-balancer and has SSL-offloading), the service is accessed on a OC4J container, which generates a WSDL that returns to the client. However, the returning WSDL contains URLs that contain the name of the internal machine instead of the external url. This results in a scenario where other programs cannot link to our WSDL, as they cannot fully download it (see drawing for clarification).
How can I make the WSDL accessible for external users? (i.e. trick the service into generating url's using the externalurl.com reference, rather than its machine name?)
For what it's worth: In Tomcat you can specify proxyName and proxyPort for a Connector. How can this be achieved in OC4J?
You can provide an oracle-webservices.xml file along with your application to override the default binding settings of the OC4J container.
You can find more information here.

Programmatically changing haproxy configuration file

Is there any java program or api to change the content of the configuration file of the haproxy? for example to append/remove few configuration dynamically.
Run a thalassa server on the same machine as HAProxy and call its http api from your Java program. It defines restful POST and DELETE interfaces for registrations, which are dynamically configured backends.
append documentation
remove documentation
Inspired by the Answer of allonhadaya I tried out thalassa.
Pearson Eduction who are the main contributes build a complete stack around:
https://github.com/PearsonEducation
So in your example you would probably use three of their components
Thalassa (Service Directory Service)
Thalassa Http Client
Thalassa Aqueduct
The Service Directory is the central service manager. With the application itself (if it is a node application there are predefined compontens) or with the Thalassa HTTP Client you register your service (application) at the service directory. In your case with your existing java application, using the HTTP standalone client might be a good way to start.
Thalassa Aqueduct ist the bridge to the HA-Proxy. It connects the Service Directory with the HA-Proxy configuration. At the moment it has (only) some REST Methods to also configure the HA-Proxy Frontends and Backends. But a quite OK Webinterface to see how many connections are handled and balanced right now.

Using Java SE Endpoint with Embedded Tomcat

I have a JAX-WS web service exposed through the simple Endpoint interface (example)
If I understand the API correctly, as an alternative to directly calling Endpoint.publish (which uses the Sun's HTTP Server), we can:
Create the Endpoint --> Endpoint e = Endpoint.create(impl);
Publish the Endpoint ---> e.publish(context);
Can I use this e.publish(..) API to publish to an embedded tomcat server? (example)
The javadoc of the Publish method is pretty confusing to me.
Although it is more than two years old, this answer to a related question still applies. If you want to deploy to tomcat, no matter whether it is running in embedded mode or normal, you need to package a war and place it in the webapps directory.
To be usable with the publish() method in the way described in your question, tomcat would have to provide a Sun HTTP Server Service Provider Implementation, which it does not. An alternative to Sun's HTTP Server is for example Jetty.

Dynamically assign web service endpoint urls

Our business process invokes an external web service, we may need to change the web service URLs for different environments.
For Example:
For DEV server we will have one web service end point URL where as for PROD there will be a different one. So in this case we should be able to set the endpoint urls dynamically depending on the environment so that we do not need to change our EAR file for each environment.
How do we assign an end point URL dynamically to a web service in WebSphere Server?
Please help me because i am beginer for WebService.
If you are using Spring (or can use Spring) then I would suggest using PropertyPlaceholderConfigurer. Also please take a look at this post
for setting up different deployment environment settings.
Call javax.xml.ws.Service.setHandlerResolver. Pass an implementation that returns an implementation of LogicalHandler. In handleMessage, check MESSAGE_OUTBOUND_PROPERTY to update ENDPOINT_ADDRESS_PROPERTY.

Categories

Resources