Atmosphere - Nginx as https->http forwarder - websocket not working - java

I am using Nginx to transform https to http from client to server.
I have an atmosphere configuration working well in websocket without this forwarding.
Now if I switch to https with Nginx in the middle
var request = { url: "https://localhost/writever/chat",
contentType : "application/json",
logLevel : 'debug',
transport : transport ,
enableProtocol : true,
fallbackTransport: 'long-polling'};
Websocket connection fails after a timeout and downgrades to long-polling.
Would you know if it is possible to have websocket working under these conditions?
By the way, latest nginx 1.3 supports websocket proxying - still in dev mode. Does it have an impact on an AtmosphereHandler if such a method is used?

it should not make a difference. But take a look at:
http://goo.gl/04g8F
You might want to add this header and see if that make a difference. I sincerely doubt, but try it.
-- Jeanfrancois

Related

AWS API Gateway WebSocket Error: Unexpected response: HTTP/1.1 101 Switching Protocols

I have implemented Socket.io in the backend with netty SocketIO in java spring boot. And client connects to WebSocket using
ws://{server.ip.address}:5291/socket/?transport=websocket
http://{server.ip.address}:5291/socket/?transport=websocket
These both work as expected.
Now I have configured WebSocket on API gateway with HTTP integration.
And trying to connect using a gateway URL
wss://{app-id}.execute-api.{region}.amazonaws.com/{stage}/?transport=websocket
But it gives error: Execution failed due to configuration error: Unexpected response: HTTP/1.1 101 Switching Protocols
I have tried to diable proxy and enable Add Integration reponse option-> on Integration reposne add the response key '/101/' but nothing woked.
Also Route Response seems disabled.
Can Anyone tell me how to overcome from this issue and where I have to set respose code 101?
Do I need to change anyhting in Backend code for API gateway?

Jersey client log HTTP version used

Testing out connection reuse with http1.1 and http1.0 keep-alive on a service over HTTPS using the jersey client.
I have logging enabled on the jersey client:
Client client = ClientBuilder.newClient(new ClientConfig().register( LoggingFilter.class));
Also have SSL debugging enabled using the property option:
-Djavax.net.debug=ssl
This gives quite a lot of info, but jersey doesn't log the HTTP version used (i.e. if it's actually using HTTP1.0 or HTTP1.1). Is there some way to get this logged out?
Once I changed the javax.net.debug JVM option to 'all' the debug output included the data as well - including what version of HTTP was used in the requests:
-Djavax.net.debug=all
The output was not very pretty, but it worked.

what is the tcp status after jetty responsing to web browser for a connection

as the title said, will jetty close the connection?
netstat cmd report established on my machine.
tcp6 0 0 ::1:3003 ::1:41817 ESTABLISHED
Normal HTTP rules apply.
Determine which HTTP version your connection and request was using. (HTTP/1.1, HTTP/1.0, and with older Jetty versions HTTP/0.9)
Then determine the request persistence mode, based on the version declared in the request portion of the exchange, along with other headers related to that HTTP version in the request and response headers.
From that information you will have the answer on what behavior the connection closure follows for that specific connection.
If this is still confusing, capture the request headers and response headers and update/edit your question to include the headers that were actually used.

HTTP/2 Response Header in Java

Is there already a way to get the HTTP/2 response header in Java? I've tried to search in some libraries like URLConnection, Undertow or even Jetty, but without success.
P.S.: I'm using JDK 1.7 on my Java Project.
Other thing, the response header of the HTTP/2 is like this?
GET / HTTP/1.1
Host: server.example.com
Connection: Upgrade, HTTP2-Settings
Upgrade: h2c
HTTP2-Settings: <base64url encoding of HTTP/2 SETTINGS payload>
Is there any website who use this version already?
My main goal is to know if a website use the HTTP/2 version or not, is there a way to know this without need to read the response header in a Java Project?
Thanks.
HTTP/2 websites typically use TLS, because browsers only support HTTP/2 over TLS.
The method you are trying to use is the HTTP/1.1 upgrade to HTTP/2 which very few sites - if any at all - support.
Your snippet of code represent a request, not a response.
If the upgrade is successful, the HTTP/2 server sends back a 101 response in HTTP/1.1 format and the response to the GET request in HTTP/2 format. This is specified in RFC 7540, section 3.2.
In order to achieve what you want, i.e. to know if a website supports HTTP/2, you have to try to connect using HTTP/2 + TLS. If the connection succeeds, you know HTTP/2 is supported. If it fails, it's not supported.
For Jetty (disclaimer, I'm the HTTP/2 module maintainer), you have to use JDK 8, and the code will look like this:
// Setup.
HTTP2Client http2Client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory();
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
httpClient.start();
// Does webtide.com support HTTP/2 ?
ContentResponse response = httpClient.GET("https://webtide.com/");
// No errors, yes it supports HTTP/2 !
If you get a response without errors, you are on HTTP/2, otherwise the server does not support HTTP/2.
Remember that for that code to work, you have to use JDK 8 and the proper ALPN boot jar in the bootclasspath, as specified here.

Proxy Error 502 : The proxy server received an invalid response from an upstream server

We are building a mass mailing sending application in Java. Mail is being send by third party SMTP. After sending 400-500 mails tomcat6 service get stopped. Below is the error.
Proxy Error
The proxy server received an invalid response from an upstream server. The proxy server could not handle the request GET
/lin/Campaignn.jsp.
Reason: Error reading from remote server
Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.
Apache Server at msizzler.com Port 80
But when we are sending from localhost I did not received any error. It send all the mails.
Please help me to sort it out this problem.
The HTTP 502 "Bad Gateway" response is generated when Apache web server does not receive a valid HTTP response from the upstream server, which in this case is your Tomcat web application.
Some reasons why this might happen:
Tomcat may have crashed
The web application did not respond in time and the request from Apache timed out
The Tomcat threads are timing out
A network device is blocking the request, perhaps as some sort of connection timeout or DoS attack prevention system
If the problem is related to timeout settings, you may be able to resolve it by investigating the following:
ProxyTimeout directive of Apache's mod_proxy
Connector config of Apache Tomcat
Your network device's manual
Add this into your httpd.conf file
Timeout 2400
ProxyTimeout 2400
ProxyBadHeader Ignore
The java application takes too long to respond(maybe due start-up/jvm being cold) thus you get the proxy error.
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /lin/Campaignn.jsp.
As Albert Maclang said amending the http timeout configuration may fix the issue.
I suspect the java application throws a 500+ error thus the apache gateway error too. You should look in the logs.
I had this issue once. It turned out to be database query issue. After re-create tables and index it has been fixed.
Although it says proxy error, when you look at server log, it shows execute query timeout. This is what I had before and how I solved it.
I had this problem too.
I was using apache as a reverse proxy for tomcat, my problem was associated with the return time of the response for "apache" proxy
I solved it like this:
open the "etc/apache/apache2.conf" and the ssl mod conf file "etc/apache/sites-available/000-default-le-ssl.conf" and add the following lines:
Timeout 28800
KeepAlive On
maybe this will help you

Categories

Resources