Dynamically assign web service endpoint urls - java

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.

Related

How to do URL-rewriting in Websphere when Angular application is hosted in subdirectory

We're using Websphere to host a series of applications for us:
We have an API that's hosted at the root, written in Java
We have an Angular application hosted at /admin
We have another Angular application hosted at /marketing
My concern is about deep-linking. If a user is at /marketing/products/1, and they refresh their browser or share the link, I need the server to send that route to the correct Angular application so it can be generated correctly.
In a simpler setup, where the Angular application is living at the root, I would use the Java application's web.xml file to redirect traffic to "/". But in my current scenario, I need traffic for the marketing site to go to "/marketing", not just to "/". Just like a deep-link from the admin site would need to go to "/admin".
Furthermore, the base URLs for these Angular applications are subject to change, and we also plan to add additional Angular sites to this same server. So I'm really looking for a solution that can work dynamically and have the server redirect to the first "slug" in the URL rather than matching specific directories.
Any ideas? (And please excuse and correct any misconceptions I've demonstrated above -- I currently know very little about WebSphere)
I can see a couple possible ways forward.
You could still use the error-page directive in web.xml, but specify the URL of a servlet in your application that could do the inspection manually and issue a redirect as appropriate. How the list of context roots is provided to your app will differ based on how it's packaged, but it could be done using files, environment variables, or JNDI entries in server.xml.
If the URLs could be changed, the Angular apps could be changed to use HashLocationStrategy in their routers which would sidestep the error page. It doesn't seem likely that that's the case but I'll put it here to get it out of the way.
You could consider splitting each Angular app into its own .war file and configuring the context root in the webApplication element in server.xml. Then redirecting to / in web.xml would work since that / is relative to the context-root.
We ended up combining those separate Angular applications into 1 so that WebSphere could direct everything to "/" and Angular routing could handle everything from there.

best way to keep endpoints required by a service

Suppose i have a service that make multiple api calls to multiple micro services
Currently i am fetching all required endpoints from database and setting them as system property.
But i want to remove this db call and at the same time externalize the same.
Can you please suggest me best ways to externalize these endpoints?
In micro-service based architecture, ideally what you need is service registry and server side service discovery pattern to tackle multiple service calls.
If you are sure that your api calls are never gonna change, then keeping it in .properties file make sense, but again if they change you have to re-deploy your service.
You need to get the API end points from a Directory which will have the latest API end points. This has to be a global DB or Directory. Try using JNDI.

How to deploy a Vuejs application

My application has two separate parts, back-end in Java (Spring boot) and front-end in Vuejs.
I can simply deploy the JAR for my back-end code where I need to, and that's it for deployment.
But when it comes to deploying the Vuejs app, I can do something similar and just put the compiled Vuejs application in the proper path in a Java Spring boot application and that will be all for the front-end too.
It just doesn't seem right to me to put that application in Spring boot when it doesn't really have to do anything with it really other than for deployment (Maybe I know nothing like Jon Snow).
Also, when its put under a Spring boot application, manual URL editing doesn't work.
This app doesn't do anything on its own, it fetches all its data from the back-end app.
So what are my options here, can someone please guide me in the right direction?
Do I just setup a nodejs server and deploy the Vuejs app in that? I am not sure how that works, or whether should I even be doing that for a production application. And if so, where do I start with setting up nodejs?
It makes sense to deploy it together with spring, and it's very common practice, at least from my experience with Angular (which I suppose would be very similar to VueJS).
You don't need to have 2 servers running. You just let Spring server your HTML/js/CSS files, which helps you avoid any problems with CORS.
I am not really sure what 'URL manual editing', do you mean by navigating the web page by editing the URL? I don't see much use cases there tbh and I would guess that is only a matter of few settings.
In gradle - I would set up a build task (not sure if task is correct word, 2 build.gradle files, each for FE/BE, the BE would depend on FE), the FE would be run when BE is run, it creates static HTML/js (in my case from angular, but it should be similar for Vue) and BE task adds the output to the classpath of the java application so that Spring can register the HTML and serve it to you.
You could use Docker to create a Dockerized version of your Vue.js app and then you can deploy this onto a cloud service provider such as AWS (e.g. EC2).
Check out this link for a basic guide https://v2.vuejs.org/v2/cookbook/dockerize-vuejs-app.html
My approach is to deploy front-end and back-end separately.
You can use web-server to proxy requests to Vuejs or Spring boot.
For example, if you use Nginx, you can use this configuration to pass requests
# pass root request to index file
location / {
root /front_files/;
index /index.html;
}
# pass requests to static files
location ~ ^/(js|styles) {
root /front_files/;
}
# pass requests to back-end
location /api/ {
proxy_pass http://127.0.0.1:8080/;
}

Issue with replacing SOAP End point at run time

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.

Communication between rest services hosted on different tomcat servers

I have a scenario where i am hosting different java Rest Services on different Tomcat instances (different machines). These projects running on the tomcats do not have any UI. For simplicity's sake, lets assume that the user will directly enter some URL in the browser (or curl) to avail these services. Now I need this service to be able to talk to (call functions) the services available in the other tomcat instance.
For eg. If TomcatInstance1 gets the call, and all this does is act as a 'router' to the different services, i want it to be able to place the Rest call for the other 'service' available on, say, TomcatInstance2. Is this possible?. If so, how to achieve that? (Tried searching for similar questions on SO, couldnt find any). Are there any online reference for the same?
PS: Hosting the services in the same Tomcat Instance is against the requirement that I'm having.
That is completely possible. You can use (for example) Jersey-client (http://jersey.java.net/) to make the queries to the other RESTful web services in the other Tomcat instances. Only need to define the correct URIs of the end points and query them according the the API exposed and call it (like you were a client from a browser, or curl).
See here a nice example of using Jersey-client to do that: http://www.mkyong.com/webservices/jax-rs/restful-java-client-with-jersey-client/
I would suggest Spring Restful api ( http://static.springsource.org/spring/docs/3.0.0.M3/reference/html/ch18s02.html , http://www.mkyong.com/spring-mvc/spring-3-rest-hello-world-example/ ).
As #emgsilva mentioned the only thing you need to do is to point correct uris between each other.
The beauty of spring restful api is it is simple to use and you don't deal with any serialization - deserialization.

Categories

Resources