Server Independent WebSocket Implementation - java

I am trying to find a solution for a Server Independent WebSocket implementation, Tomcat inbuilt WebSocket API is good but it's not running in Weblogic and other servers .
I found a solution with Tyrus API , but all examples of Tyrus is done with grizzly web server , where it starts a separate server with a new port to accept ws:// request , but it has another option which is ServerContainer, where it will work with any Servlet Container web server and will use the existing Server port only, but unfortunately no example i found .. I am looking forward to any other options also ...

Related

How to retrieve port number from a tomcat server sitting behind a load-balancer

Situation:
My client has a Java web application deployed on a JBoss server, it is accessed both via HTTPS and HTTP
The JBoss server is sitting behind a load-balancer that handles the SSL, in other words this load-balancer terminates SSL and sends requests to JBoss as plain HTTP
Problem I need to solve:
The web application deployed on JBoss needs to know what port the load-balancer is using for HTTPS, so that it can direct users to certain HTTPS urls correctly. This cannot be hard-coded because the application will be deployed on multiple clients, each of them have different configurations for the load-balancer.
My approach (which didn't work):
I am defining the port from a jspx page, via ${pageContext.request.serverPort}, but this always returns the port for HTTP because JBoss always gets the request via HTTP.
Thanks in advance. I've looked at this question but was not helpful.
There isn't really a way to determine the port if tomcat is sitting behind a load balancer. As suggested in the comments, exposing the port configuration to your clients would be the best for now.

HTTP Client-Server resquest response

I am trying to write a simple client-server application in Java using HTTP request/response. I would like the client to be a desktop program which sends (posts) a request to a server. The server is a web page which will be hosted on Apache Tomcat server. The server must be able to read the information and display it on the browser and must be able to respond to the client with a status code 200. I am using eclipse and Apache tomcat server. I have so far tried various resources, but all I could find is a client which could request response from an already existing web server. Could someone please give me an example or some insight on how to make the client request the our own server which runs on the local machine.
Good question, though in your case, I won't recommend you implement a simple HTTP request/response approach as you will end up implementing a timer, heartbeat or Comet. You might wanna try javax or jetty WebSocket API. All you need is to create three parts:
a websocket.server
a websocket.client (desktop application)
a javascript websocket client (browser agent)
Your server and both clients will become full-duplex via onMessage and send events.
Here's an example which I believe is a bit relevant one.
https://dzone.com/articles/sample-java-web-socket-client

Configuring Tomcat to communicate through proxy in Localhost - Fiddler

Tomcat is running in my localhost on standard 8080 port. When tomcat calls a service (soap/rest) running in the same server, I would like to capture it through fiddler.
Basically, any request that tomcat sends out, should be captured through Fiddler. Currently, it sends out request to another service running the same machine and that service in turn calls Amazon AWS, which I would like to capture as well.
Can anyone help? Note that this is opposite of traditional web request through proxy to the server.
I am open to any other alternatives as well.
Please have a look at How to capture SOAP messages from a Tomcat Java app to an external server? for information on setting the proxy for Tomcat.
The correct JVM parameters should look like: -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8888 -DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888

WebSocket connection interrupted when Apache HTTPD in front of Tomcat

I try to use Tomcat implementation of WebSockets on local machine.
When I use only tomcat everything works fine, but when I start use bundle Apache + mod_jk + Tomcat browser show me 'The connection to ws://example.com/test/echoMessage was interrupted while the page was loading' after couple of seconds of work. WebSocket connection is closed after this.
Can anyone tell me how to fix it?
I have: Apache HTTPD 2.2.18, mod_jk 1.2.37, Tomcat 7.0.28
Here is server side code that I use: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/WEB-INF/classes/websocket/ and client side: http://svn.apache.org/viewvc/tomcat/trunk/webapps/examples/websocket/
Browsers: Firefox 12, Chrome 19
I would research whether Apache mod_proxy is able to transparently forward traffic at the TCP level at all. Since that is likely needed for WebSocket to pass through. IOW: is mod_proxy able to transparently reverse proxy WebSocket traffic?
But why would you want to bring Apache in the line anyway? It doesn't add any value, only more parts which can break. That is for WebSocket of course ..

Java EE getting servlet container port

I want to programmatically get the servlet containers port that my Java EE application is deployed on. I assumed there would be something in the JMX beans but I can't seem to find anything.
And before anyone says grab the port from the HttpRequest or HttpResponse it should be noted that this process is running behind the servlet and has no interaction with the Requests or Responses.
One possible "hack" would be to parse the server.xml at runtime and identify the port that is configured.
But looks like there is a way to do it using JMX / MBeans as well.
I happened to have a strong need to extract the tomcat port from request. So that I can compare and tell if the servlet request is from tomcat port http://localhost:8080 or from apache port http://localhost/
By doing this, I can make sure the request only be processed by strictly using tomcat port and rejecting by apache port. This may help setup security configuration that the request would not allow outside world access via apache. tomcat port only available within local network.
The method is to create a tomcat valve (assuming you know what it is) implements org.apache.catalina.valves.ValveBase.
This interface provides org.apache.catalina.connector.Request as an argument.
Per request:
using request.getConnector().getPort() which returns 8080. Then say.
if ( request.getServerPort() != request.getConnector().getPort() ) {
response.getWriter().print("<span>access denied</span>");
} else {
getNext().invoke(request, response);
}

Categories

Resources