How to make Apache HTTP client use system settings by default - httpclient

I have a machine running third party code that uses Apache HttpClient. This machine can only access the external world via https proxy. I know HttpClient allows using system properties like this
HttpClientBuilder.create().useSystemProperties().build();
But I don't have access to the source code to do this. I want to set the proxy host and port as environment variables to make the program pick it up, like it does with "-Dhttp.proxyPort" for Java HttpClient. What are my options?

Related

Play Framework as reverse proxy with ScalaWS

I am trying to document a server and replicate its setup done by another person. Server is running Play Framework which also acts as a reverse proxy to MediaWiki running on Apache on the same server on a port that is not open externally on the server.
The Play Framework routes requests to the Media Wiki Server using ScalaWS. When I check the request it creates a request by using the server domain with the Apache port and the media wiki file.
In the real server it is working fine but in the test deployment it fails to reach mediawiki. It works if in the test deployment I open the Apache port externally.
So Somehow the request to the local server running internally on the machine needs to be accessed without routing the request externally. How can this be done? If anyone can give some quick tips or things I can check or even explain how this may be working, that would really help save me some time.
The /etc/hosts file had the wrong domain defined. Fixing that fixed the problem.

How can I create a network proxy programming?

Excuse me. I speak poor English.
I am trying to create a network proxy programming with sock5 protocol. But I have no way to learn it, I can't figure out how a proxy programming works especially the followings:
What is the difference and association between socks5 and the Shadowsocks ?
Can I set a the network proxy configure in macOs instead of using swift or oc ?
such as enabling this check button(socks5 proxy) and filling the specific configure using a language instead of swift or oc:
configure
Once I set the option on macOs in the Question 2,what kind of data will the programming get if it listening the network?
e.g. will the macOs automatically forward the all new TCP connections to 127.0.0.1:1086 and automatically make the connections confirm to the socks5 request standard?
If so, why the final processing programming (transmit the datas to the real remote proxy-server) can make a successful connection? Instead of a forever loop(a.programming create a socket to remote proxy-server -> b. macOs automatically forward it to 127.0.0.1:1086 and make the connection confirm to the socks5 request standard -> a.)
Is it called as a proxy-client? or local proxy-server? what is the job of it. Why do I set a proxy address as a local one instead of a direct remote server?
Why when I setting a fake socks5 option in macOs network proxy options, a UDP programming can still work successfully?
If you can UNDERSTAND CHINESE:
Chinese language
The follow answers are based on my own experience and opinion.
1、socks5 is an Internet protocol that exchanges network packets between a client and server through a proxy server. Sockes
while Shadowsocks is a software use this protocol.
2 、Yes,you can. Install a Shaowsocks don't need any
Programming language, actually it like installing a EXE file on Windows or pkg on MacOS, it's just a software.
3、Socks5 is an Internet protocol like a language between two computer.
The software's message run on you computer will be "translated" by Shadowsocks.
Those translated message will be sent to the remote service (also run a Shadowsocks) then the service can send message to those "blocked" Webs' services.
4、The remote service can be called an proxy service.The local don't do anything except be "translated" by Shadowsocks. Look this picture.
5、The QQ don't use the port 1080, Shadowsocks need a fixed port to "translate" message.

How to configure the application URL with RAP/RWT

We can get an application URL with the code:
RWT.getRequest().getRequestURL();
Do we have any way to configure this URL (host, port) in VM arguments or properties or any other ways (not in Java code)?
Both hostname and port aren't part of a RAP application's configuration.
The hostname is determined by the network configuration of the machine running the application and other factors like proxy servers in between client and server.
The servlet container (Tomcat, Jetty, and the like) that a RAP application runs on controls which port it uses. Hence the servlet container's configuration needs to be changed in order to change the port.

Using web proxy with Java 8 JAX-RS RESTEasy clients

I can't seem to get JAX-RS clients to use a web proxy on Java 8. I'm using RESTEasy 3.0.10.Final, and running from inside Eclipse 4.4.2 on Windows 7 Professional 64-bit.
I set up a FreeProxy server on localhost running at 192.168.1.123:3128. I turn logs on and telnet to 192.168.1.123 3128 and issue a manual GET. The request shows up in the logs.
I then fire up my Java application, setting http.proxyHost=192.168.1.123 and http.proxyPort=3128 in the system properties. (I've even tried it using -D when starting the JVM.) (Note that I wouldn't expect the localhost problem to come into play, as I'm connecting to an actual IP address, not to localhost.)
I create a JAX-RS client using ClientBuilder.newBuilder().build() and perform a GET to a resource. Nothing shows up in the FreeProxy logs.
What do I have to do in order to get JAX-RS clients to use a proxy?
The ResteasyClientBuilder provides a method to define the defaultProxy:
ResteasyClient client = new ResteasyClientBuilder().defaultProxy("localhost", 8080, "http").build();
It seems to be possible to make RESTeasy use Java's proxy properties (e.g. -Dhttp.proxyHost) by using a different engine instead of HttpClient. java.net.HttpURLConnection supports proxy properties out of the box:
ResteasyClient client = new ResteasyClientBuilder().httpEngine(new URLConnectionEngine()).build();
For RESTEasy 4, here is what I've done for that:
ResteasyClient client = ((ResteasyClientBuilder) ClientBuilder.newBuilder())
.defaultProxy(proxyHost, proxyPort)
.build();
return client
.target(ENDPOINT_URL)
.proxy(EndpointResource.class);

GWT dev mode not accepting requests forwarded through router

Our application uses the PayPal api, in order to test it PayPal needs to be able to post data to a serlvet on our servers. This is no problem in production however when running in GWT-Dev mode I cannot seem to get GWT to work through my home router. GWT is running on port 8888 and I have added the needed firewall rules to get this to work.
Does GWT somehow stop requests from working from outside the local area network? I tried -bindAddress 192.167.x.x but it did not work.
For security reasons the jetty server used in gwt dev mode only binds to localhost.
If you want to bind it to all intefaces use the parameter -bindAddress 0.0.0.0
To make sure the servlets are reachable try to connect from a different host on your network (e.g. with Telnet).