Connect to external HTTPS Elasticsearch with Java Client - java

Since I'd want use the Elasticsearch' Java API, I'm trying to connect to external Elasticsearch's REST Server by using the Java TransportClient, the URL I have to call looks like:
https://ssl-secure-host/their-index/their-type/_search
Obviously I first trusted the certification provided by ssl-secure-host by using the keytool and generated the keystore.jks.
I don't have any other information about the elasticsearch's index, nodes, etc, I have only the URL above.
This is the TransportClient I'm writting in order to establish a connection:
ImmutableSettings.Builder settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "elasticsearch")
.put("discovery.zen.ping.multicast.enabled", false)
.put("shield.user", "user:password")
.put("shield.ssl.truststore.path", "/Users/me/path/cert/keystore.jks")
.put("shield.ssl.truststore.password", "changeit")
.put("shield.transport.ssl", true);
TransportClient client = new TransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress("ssl-secure-host", ?????));
Could it be possible to establish a connection in any other way or I have to ask to my provider more information about the host, port, etc?
Or, Do I have to resign myself to do this by implementing a simple REST client to query the Elasticsearch's index other people provide me?
Could it be possible that an Apache HTTP Server exists in the front of elasticsearch nodes?
Thank you very much in advance :)

You can use JEST library. It s an HTTP client for ElasticSearch. So you can use it instead the transport client provided by Elasticsearch
check this link:
https://github.com/searchbox-io/Jest

Related

NiFi API on remote host SocketException

When I run NiFI 1.8 on my local machine (http://localhost:8080/nifi) I am able to interact with the application through the API using Java. I can start and stop processors, and I get a 200 response code everytime.
When I use the same code to interact with a remote NiFI instance (which uses authentication) I get a SocketException, with the message "Unexpected end of file from server"
I tried setting credentials of the HttpURLConnection but it made no difference. Is this an issue with a certificate? If it is I'm not sure how to obtain and set the correct one.
Any clues?
There are multiple ways to authenticate against NiFi. All secure instances can accept client certificates by default, so if you have a user entity configured for some identity nifi_client, you can issue a certificate with that CN and use it when invoking the API from your Java client. Generally this involves putting the key and certificate in a Java Keystore (*.jks) and having a truststore that contains the public certificate of the NiFi server. There are specific instructions for handling certificate authentication in the NiFi Admin Guide, and you can look at the NiFi CLI as an example of an authenticated client.

Cannot login into Salesforce with Java using Proxy Server

I wrote Java code to login to Salesforce and ran this code on a firewalled server. For this, I have to specify the proxy url and proxy port before connecting to Salesforce due to the firewall. However, I'm getting an unknownhostexception error for the proxy url. If I try to login via curl with the proxy settings, I am able to connect. How come there is a problem connecting using Java then? Any help is appreciated.
Apparently the issue was caused by JVM configs. We have to configure JVM to use the proxy settings as follows:
System.setProperty("http.proxyHost", crmProxyURL);
System.setProperty("http.proxyPort", crmProxyPort);
Depending on your HTTP library the System settings might not be enough or not needed. In the Salesforce context it is quite possible that one would try using the Jetty HTTP Client. In this case the System properties are ignored and proxy needs to be handled by the Jetty client:
ProxyConfiguration proxyConfig = httpClient.getProxyConfiguration();
HttpProxy proxy = new HttpProxy("proxyHost", proxyPort);
proxyConfig.getProxies().add(proxy);
The Apache HTTP Client, another popular choice, also uses its own little mechanism:
HttpHost proxy = new HttpHost("proxyHost", proxyPort, "https");
RequestConfig config = RequestConfig.custom().setProxy(proxy).build();
HttpGet request = new HttpGet(someURL);
request.setConfig(config);
Interesting here: one can specify to use http or https as the proxy protocol.
In general I found using one of the http client much easier that the JDK low level functions.

How to test connection to server SSL port via proxy using Apache HttpClient 4.3.4?

I'm trying to validate an SSL connection to an http server through a proxy server. In my case, I have 4 pieces of information which are all supplied by the user, and which I'd like to validate explicitly: target host, target port, proxy host, proxy port. I'd prefer to NOT make an actual HTTP request in order to do this validation, since that requires 2 more pieces of information: a request method, and a path (ie. "GET /"). I'd really like to be able to use the HttpClient library because it supports NTLM proxy auth.
I suppose what I want is to get the response of a CONNECT request sent to the proxy server, as all it requires are the 4 pieces of information I have (plus any proxy creds). However this seems to be an implicit request, the result of which is not available to the library client (unless it returns a 407 status code). Is there some way to trigger the CONNECT request explicitly?
You can use ProxyClient shipped with Apache HttpClient. It does precisely that.

How to connect to proxy server using Java

I want to write a java(SE) program to connect to a proxy server, lets say 123.123.123.123:8080. How am I going to achieve that? What is the protocol between my machine and the proxy server? What is the Java framework's class could be in use?
since java 1.5,you can use java.net.Proxy class to create proxy.
Proxy proxy=new Proxy(Proxy.Type.HTTP, new InetSocketAddress("123.123.123.123", 8080);
URL url = new URL("http://www.example.com");
HttpURLConnection uc = (HttpURLConnection)url.openConnection(proxy);
uc.connect();
reference
The definitive reference for network proxy configuration in Java 5 is this Java Networking and Proxies page.
Yes proxy server is a web server...
Whenever u send a request through your browser to get some resource in the particular web server(say www.google.com),the request is send to the proxy server instead to sending the request directly to the google server..the proxy server process this request,send them to the gooogle server,receives the response and then send the response back to the browser.
Proxy server is basically used to corporate fields to restrict the accesss to specific websites,to keep a track of the internet used by a particular associate,Also it saves some commoonly used webpages in a cache file,so that when another request comes,then instead of connecting to the required server,it get the webpage fron the cache file..Hence it saves the time.Also it scans the incoming data from any server for malware before submitting it to the client(browser).To check if ur company is using proxy server,u can go to the internet explorer setting ->Connections ->LAN Settings

JAX-WS client authentication on proxy server

I'm trying to use JAX-WS api to send some soap messages on a client application. However, I'm behind a firewall and the only option is to use a proxy server to go outside.
I'm trying to find on google any answer about this and so far all fail: To Use System.setProperty for http.proxyHost, http.proxyPort, http.proxyUser, http.proxyPassword. To use Authenticator like is described here.
I'm running out of options, if someone could help me on this would be great.
Also, I have a option to use org.apache.commons.httpclient but then I need to generate manually the XML. So could you suggest any other approach or API for WS?
You can use ws import command when creating web client to configure proxy.
-httpproxy::
use above command to configure proxy.
How to do this depend on your IDE.
http://publib.boulder.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=/com.ibm.websphere.wsfep.multiplatform.doc/info/ae/ae/rwbs_wsimport.html
For Jax-ws webservice client, use the following
//set proxy info to the ClientProxyFeature
ClientProxyFeature cpf = new ClientProxyFeature();
cpf.setProxyHost("proxyhost");
cpf.setProxyPort(8888);
cpf.setProxyUserName("proxyuser");
cpf.setProxyPassword("proxypwd");
//get the port with the Feature
MyPort port = myService.getPort(cpf);

Categories