Soap API call through a load balancer - java

I have a java app/client which calls a soap web service using Java Sockets. Now I need to add a load balancer in between the client and server which redirects the request to multiple Tomcat instances where the API is running. How can you establish socket connection from the client without specifying the server port address since the routing happens through the load balancer(F5)? Can this be accomplished through F5 configuration somehow?
For instance the soap url looks like this:
http://abc:1234/myapp/mysoap?wsdl
It needs to be converted to
http://abc/myapp/mysoap?wsdl

Related

How to manage gRPC server channel within a spring-boot

I have a setup which has a spring-boot application and gRPC server. gRPC server has written in NodeJS and deployed in a separate server. In my spring-boot app, there is an endpoint which accepts a request object and delegate it to the gRPC server.
Question:
1) In this scenario, do I need to create rGPC channel for each incoming http request? (which sounds not efficient)
2) or do I have one channel created at the initialization of the spring-boot application?
In the 2) solution, how do I manage when the gRPC server is down and need to fetch the new URI from the eureka server?
Here is the gRPC channel creation in spring-boot.
2) is the way to go. To address the server down case, you can check the channel state (io.grpc.ManagedChannel.getState(boolean)) before forwarding the incoming http request to the gRPC server and if it's not READY then call your initCommunicationChannel() after suitably refactoring it so it can be called multiple times.
Alternatively you can implement a Name resolver plugin (https://github.com/grpc/grpc/blob/master/doc/naming.md) which simply calls eurekaClient.getApplication("logger-app").getInstances() to return resolved addresses which are then used by a client side load balancing policy (https://github.com/grpc/grpc/blob/master/doc/load-balancing.md).

Web cilent and server communication throught firewall

I want to create a web application, which is divided into two part one is client and another is server.
Client:
Client part is on the shared server.
Client is the GWT Application which only use to display data (containing only ui elements and ui events).
Client application is used by server to view and present it's own data.
Server:
The server is the simple java web service (restlet).
The server is reside behind the firewall.
The server contains actual data.
There are N number of servers.
Server does not contains any view if server wants ro view data it will use the gwt client application.
Every server uses same gwt application to view it's own data.
Note :
Client does not contains any address of the server. server will send the request to view it's data.
There is no firewall inbound exception on server firewall to access server data from out side client
I need to communicate client and server through firewall, Is there any architecture or design pattern to implement this type of application?
I don't think that the firewall can bring new restrictions to a GWT application compared with other types of applications (clients).
In case you have the GWT client on one server which makes calls to a different server you might have some issues due to same origin restriction.
This can be resolved in several ways:
- your GWT application has a server-side part which calls the other servers. And your GWT client makes normal RPC / JSON calls to the GWT server side (on the same server).
- in case you want to make directly the call on the different server from your GWT client you can use JSONP or the restygwt library.

Jetty - proxy server with dynamic registration

We have a number of Jetty http(s) servers, all behind different firewalls. The http servers are at customer sites (not under our control). Opening ports in the firewalls at these sites is not an option. Right now, these servers only serve JSON documents in response to REST requests.
We have web clients that need to interact with a given http server based on URL parameter or header value.
This seems like a straightforward proxy server situation - except for the firewall.
The approach that I'm currently trying is this:
Have a centralized proxy server (also Jetty based) that listens for inbound registration requests from the remote http servers. The registration request will take the form of a Websocket connection, which will be kept alive as long at the remote HTTP server is available. On registration, the Proxy Server will capture the websocket connection and map it to a resource identifier.
The web client will connect the proxy server, and include the resource identifier in the URL or header.
The proxy server will determine the appropriate Websocket to use, then pass the request on to the HTTP server. So the request and response will travel over the Websocket. Once the response is received, it will be returned to the web client.
So this is all well and good in theory - what I'm trying to figure out is:
a) is there a better way to achieve this?
b) What's the best way to set up Jetty to do the proxying on the HTTP Server end of the pipe?
I suppose that I could use Jetty's HttpClient, but what I really want to do is just pull the HTTP bytes from the websocket and pipe them directly into the Jetty connector. It doesn't seem to make sense to parse everything out. I suppose that I could open a regular socket connection on localhost, grab the bytes from the websocket, and do it that way - but it seems silly to route through the OS like that (I'm already operating inside the HTTP Server's Jetty environment).
It sure seems like this is the sort of problem that may have already been solved... Maybe by using a custom jetty Connection that works on WebSockets instead of TCP/IP sockets?
Update: as I've been playing with this, it seems like another tricky problem is how to handle request/response behavior (and ideally support muxing over the websocket channel). One potential resource that I've found is the WAMP sub-protocol for websockets: http://wamp.ws/
In case anyone else is looking for an answer to this one - RESTEasy has a mocking framework that can be used to invoke the REST functionality without running through a full servlet container: http://docs.jboss.org/resteasy/docs/2.0.0.GA/userguide/html_single/index.html#RESTEasy_Server-side_Mock_Framework
This, combined with WAMP, appears to do what I'm looking for.

wsimport with SOCKS proxy

We are developing a JAXWS client for a 3rd party WCF web service. The JAXWS client is going to be part of large web based application that would be deployed on tomcat.
Not all servers in our env are allowed to communicate over the internet so out network team had configured a SOCKS proxy with authentication.
I know that I can pass -DsocksProxyHost as a command line parameter but I cannot do that since that applies for the entire web app. I've gone through this javadoc-link
on how to setup connection based proxy settings.But the problem is , since I'm using the wsimport generated Service which abstracts the URL connection functionality, I'm not able to use the URConnection conn = url.openConnection(proxy); approach.
Any ideas/thoughts?

How does the control get transferred from Web Server to Servlet Container

Quoting Java Servlet API Spec : "A client (e.g., a Web browser) accesses a Web server and makes an HTTP request.This request is received by the Web server and handed off to the servlet container."
Can anyone elaborate on how exactly this control is passed( from Web server to Servlet Container)?Does it use HTTP connectors of some kind like Apache Coyote?
The implementation detail depends on server-to-server. Http Connector architecture is what used by Apache Tomcat internally.
Web server is nothing but a Java application which opens socket on a port and keeps listening on that port over HTTP protocol + Some other facilities. These some other facilities consist of things like components lifecycle management etc.
Basic task of a web server is to listen for requests on a port number over http protocol and then respond to that. So in most common server available today they keep polling on port 80 over http protocol. When you send some http request on port 80 to the host where the program is listening then program listening responds to that. Now on receiving the request the server program (which is listening on port 80 here) will get a new thread from its thread pool and in that thread will call a servlet's service method (a servlet instance will be created if its the first request see here for more details).
ADDITION:
Web Server is a machine that has a HTTPD service running. When you send the request to server the server intercepts that.Web server is responsible for receiving request and generating response. Now the server gets the input stream on the socket where it was listening. From here it delegates the input to servlet container by wrapping it in a new thread (so that things get processed asynchronously and web server can process other http requests when the previous request is served in a separate thread by servlet). A Servlet Container is a part of a Web Server. A Servlet Container is a separate module; it may run within the web server as a single standalone program (tomcat is one example of it). Now servlet container instantiate a new servlet if not already there and calls its service method in a new child thread. Servlet container wraps the http request in HTTPRequest object and pass it in one of the parameters to service method.
If you're in the case of a apache + tomcat architecture for example, there is a protocol for the connectors (AJP). Have a look at mod_jk and mod_proxy.
When both components (web server and container) are in the same software (tomcat can manage direct http requests), I don't know of the inside implementation. (It was never useful for me, in fact. At the contrary, AJP connectors are commonly used)

Categories