Using web proxy with Java 8 JAX-RS RESTEasy clients - eclipse

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);

Related

How to make Apache HTTP client use system settings by default

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?

How to find port number of a Spring Boot app?

How do I find the port number of my SpringBoot app so I can call it? I already tried setting -Dserver.port=8080 and--server.port=8080 in VM arguments and in src/main/resources/application.properties.
If I try to go to localhost:8080 Chrome says refused to connect. I simply want to be able to connect to my App don't know why Spring Boot made finding which port is being used so challenging.
I'm using Eclipse and the app appears to be running properly from the logs.
This simply printed 0:
#Value("${local.server.port}")
int port;
I've tried these answers none work:
Spring Boot - How to get the running port
Spring boot - how to get running port and ip address How to configure port for a Spring Boot application How to configure port for a Spring Boot application
localhost:<your port> may not respond at all. Make sure you're hitting an endpoint you know is availible like localhost:8080/info. Make sure your app has completly started, it could take serveral minutes.
As #BrianC mentioned make sure your app is actually a web server.
in your springboot main method use below code to detect port of your application
Environment environment =app.run(args).getEnvironment();
System.out.println(environment.getProprty("server.port");
this will tell you actual port where your aplication running .
Value can be found using Spring’s Environment as it represents the environment in which the current application is running.
It can also be used to find other properties in applications like profiles.
#Autowired Environment environment;
String port = environment. getProperty("local.server.port");

How to Read message from Jboss JMS Queue using IIB ESB Toolkit

I am working on a small project in which I want to consume the messages from the Jboss JMS Queue using IIB Tool kit. Apologize me that I am a learner in IIB.
The scenario is as below.
The Linux server is where the JBOSS is running and the messages are available in a particular JMS queue. I got IBM Toolkit installed on my laptop/machine and created an application and a flow. I placed the JMSInput from the pallet and got confused on where to configure the connection properties like IP Address, port number, Jboss user, password etc...
The idea is to consume the messages that are available in Linux server using IIB. Request some expert help on how to configure and achieve this requirement.
The jnp based Initial Context Factory seems like not supported in JBOSS 7 anymore. I would use the one described in Remote JNDI Lookup.
I never did an IIB integration with a JMS provider in JBoss, but I did it with a standalone ActiveMQ. There I created a JMSProviders configurable service, where I could configure IP address and port in the jndiBindingsLocation property like this:
mqsicreateconfigurableservice <BROKER> -c JMSProviders -o ActiveMQ \
-n initialContextFactory,jarsURL,jndiBindingsLocation,connectionFactoryName \
-v org.apache.activemq.jndi.ActiveMQInitialContextFactory,c:\Users\daniel\apache-activemq-5.11.1\lib,tcp://localhost:61616,ConnectionFactory
See Securing JMS connections and JNDI lookups how to enter user id and password.

Deploy application to wildfly on a certain port

By default, applications in wildfly are deployed to localhost:8080/app. How to deploy application on dedicated port, i.e. open it on localhost:8282 without application name ending?
I need to change the port for certain application, not the default port.
I have not tried this, but AFAICT it should be possible to:
run a single Wildfly instance listening on multiple HTTP ports. This is, in theory at least, possible (ref: https://developer.jboss.org/thread/233414?start=0&tstart=0)
Configure undertow subsystem as a reverse proxy, and proxy your app to the other port/location (ref: http://www.mastertheboss.com/jboss-server/wildfly-8/configuring-a-reverse-proxy-with-undertow). That said, I have never used undertow for a reverse proxy and as such cannot speak for whether this really works.
Once you have done this, you have effectively just turned your Wildfly instance into an overly complex application server and reverse proxy in one. Ultimately however, the app in question would still be running on both ports, but you redirect the traffic using the proxy the way you would like.
The same proxy configuration in an Apache (ref: https://httpd.apache.org/docs/current/mod/mod_proxy.html#forwardreverse or https://www.leaseweb.com/labs/2014/12/tutorial-apache-2-4-transparent-reverse-proxy/) or NGINX (ref: https://www.nginx.com/resources/admin-guide/reverse-proxy/) would be IMHO less complex and better tested in countless production scenarios.

Swing Client - EJB2 lookup over HTTP in JBoss 5.1

I have a swing client which connects to my ejb2 application deployed in JBoss 5.1. There is a particular requirement from Customer to make it available on internet.
The deployment architecture is as follows,
swing_client --> extranet_ip |firewall | --> iis7_machine --> jboss5.1_machine.
jndi properties in client is as follows
Context.PROVIDER_URL=http://extranet_ip:9180/invoker/JNDIFactory
Context.INITIAL_CONTEXT_FACTORY=org.jboss.naming.HttpNamingContextFactory
This configuration works fine when the client is inside intranet. But it does not work in internet (extranet).
When I tried initially I got the error 'Connection refused'
After seeing some posts in various forums, I changed the file server\deploy\http-invoker.sar\META-INF\jboss-service.xml, to reflect the extranet_ip in invokerURL.
Aftet this I am getting the following error.
org.jboss.remoting.CannotConnectException: Can not get connection to server. Problem establishing socket connection for InvokerLocator [socket://10.200.1.193:4546/?dataType=invocation&enableTcpNoDelay=true&marshaller=org.jboss.invocation.unified.marshall.InvocationMarshaller&unmarshaller=org.jboss.invocation.unified.marshall.InvocationUnMarshaller]
Where 10.200.1.193 is the intranet IP address of JBoss Server machine.
I tried changing the trasport parameter in remoting-jboss-beans.xml to http, but at that time client is not working in both intranet and extranet.
Please anybody suggest a way forward for this issue. Or is there any other way to implement RMI over Http in JBoss?
Update: As a solution, I had to change my deployment architecture as follows.
swing_client --> extranet_ip |firewall | --> jboss5.1_machine
where the JBoss Application Server will be directly exposed through firewall. Then update clientConnectAddress in the remoting-jboss-beans.xml to the extranet IP. Also open the ports 8080 & 4446 in the firewall for this address.
This way the swing client is working if I use the jnid properties as follows.
Context.PROVIDER_URL : http://extranet_ip:8080/invoker/JNDIFactory
Context.INITIAL_CONTEXT_FACTORY : org.jboss.naming.HttpNamingContextFactory
But still looking for a solution where there is no need to open any non-standard ports and no need to expose the Application Server directly.
After a long struggle I found a solution for my issue. The solution was to change EJB container's invoker type to http in standardjboss.xml. When the invoker is http, it will use the settings in http-invoker.sar for remote binding.