I am trying to send a json through a web socket. The web socket has to be accessed through a HTTP Proxy.I tried using tyrus but it didn't work for proxy. Can you suggest a better way to do it.
Tyrus client supports traversing proxies, but it is Tyrus specific feature and its configuration is shown in the following code sample:
ClientManager client = ClientManager.createClient();
client.getProperties().put(ClientProperties.PROXY_URI, "http://my.proxy.com:80");
Value is expected to be proxy URI. Protocol part is currently ignored, but must be present.
reference
Client behind proxy
Related
I want to make proxy server to modify my request body, header before forward to real server.
I can just image, how to work in http proxy.
However, I want to know exactly how to work socket proxy, https proxy and http proxy.
I want to read official proxy server specification, but I cannot find it.
Could you explain where can I find the proxy spec?
I am trying to connect to an external endpoint, but traffic to external endpoints has to be forwarded through an http proxy. How do I do this in the paho Java client? I can't find their Authenticator/know what to set to make this work. You can set custom headers but I don't know how to make that work with a proxy.
Looking at the code I'm not sure you can out of the box at the moment.
This issue includes a code to use a Custom SocketFactory to make a connection via a proxy. (This might work if you don't need to authenticate to use your proxy)
And there is an open feature request issue to add it to the core code.
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
I'm experiencing a strange problem that I'm not able to figure out. The proxy when used in my Java code to make non-SSL requests always gives error informing me that I cannot send SSL requests to the specified port (whereas I'm not even trying to send any SSL request), however the same proxy when configured in my Firefox browser works like a charm and I can browse all web sites normally. Note that using the same Java code, I can send requests to 443 port alone. But that's because the proxy detects that the requests are SSL, and that's why it only allows them to pass through 443 port.
I don't have the option to use -Dhttp.proxyHost and -Dhttps.proxyHost options with me because they simply won't work on the Socket objects, I would need a Socks proxy which I don't have access to. So I opted to go with commons-httpclient-3.1.jar, and used ProxyClient object to obtain the socket.
This is the code I'm using to obtain a socket:
// Proxy Client
ProxyClient client = new ProxyClient();
client.getHostConfiguration().setHost("google.com", 80);
client.getHostConfiguration().setProxy("corporate-proxy", 80);
ConnectResponse response = client.connect();
Socket socket = response.getSocket();
if (socket == null) {
System.err.println(response.getConnectMethod().getStatusLine());
}
and this is the exact error message that is printed by my System.err.println() statement:
HTTP/1.1 502 Proxy Error ( The specified Secure Sockets Layer (SSL) port is not allowed. ISA Server is not configured to allow SSL requests from this port. Most Web browsers use port 443 for SSL requests. )
Please don't suggest me to use URLConnection because I don't need the proxy for HTTP requests alone.
I have also tried to explicitly specify the protocol to be http without any luck:
client.getHostConfiguration().setHost("google.com", 80, Protocol.getProtocol("http"));
Any suggestions on how to configure this ProxyClient object, so that the proxy server doesn't see requests to be coming as SSL requests?
Thanks.
UPDATE
I seem to have figured out the reason why the ISA server thought I'm using SSL. Actually the statement client.connect(); creates a socket that is connected, via the HTTP CONNECT method, to a proxy. The Java doc says that, even though HTTP CONNECT proxying is generally used for HTTPS tunneling, the returned socket will not have been wrapped in an SSL socket.
But for ISA, it would still think about this kind of HTTP request as an SSL request. And when it sees that this SSL request is not on 443, instead it is on some other port, it straight away rejects it.
So now the problem instead is that how do I make the client.connect() call to send an HTTP GET or HTTP HEAD instead of HTTP CONNECT..
Sorry, but I think this is a limitation os ISA Server and not a problem of ProxyClient. See the article here to configure ISA Server to allow to connect to other port, beside 443. I think ISA Server donĀ“t recognize you request because it isnt in a HTTP 1.x request.
Assuming you're using the Apache HttpClient, your code is different from a similar sample on the Apache web site. It makes use of some other techniques to make the request, perhaps that's where the difference is. See the samples here, and particularly this one.
I'm currently trying to implement a Http Tunnel between a Java Client(That Includes Netty) to a server, so I would like to know if there's any server that is also based on Netty to support this Tunnel or should I build the server side my self?
I recently came upon this: http://www.jcraft.com/jhttptunnel/. Perhaps helps you...
Now netty includes an example of an HTTP Tunnel. The server must be aware (in some way) of it to work. The documentation of the API for HTTP tunneling (client and server) is available at org.jboss.netty.channel.socket.http