I am getting this exception
org.springframework.web.client.ResourceAccessException
I/O error on POST request for \"http://host.docker.internal:8073/user-management/users/login\": Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect",
My code looks like this
#Resource(name="restTemp")
private RestTemplate restTemplate;
String url = "user-management/users/login";
//String fullUrl = "https://localhost:8073/user-management/users/login";
InstanceInfo instance = eurekaClient.getNextServerFromEureka("user-management", false);
LoginRequest user = restTemplate.postForObject(instance.getHomePageUrl()+url, loginRequest, LoginRequest.class);
Also I dont understand why instance.getHomePageUrl() generates a internal docker url . what could be the reason behind this docker desktop is running.
I need help in resolving this exception.According to what I could find this exception occurs when we are trying to access a third party url
Just try increasing the context timeout for request sent by RestTemplate
Related
I have set up my Elastic Cloud Service through Google Cloud and have set up an Elastic Search Instance.
I can upload my data to Elastic search and query my data just fine. However, when I try to connect to the Elastic Search Instance through my Java Client, I keep getting a 'java.io.IOException' and a 'java.net.UnknownHostException' exceptions.
24-Jun-2020 18:55:52.657 SEVERE [http-nio-8181-exec-8] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [dispatcher] in context with path [] threw exception
java.io.IOException: <Elastic Search endpoint>
at org.elasticsearch.client.RestClient.extractAndWrapCause(RestClient.java:828)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:248)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:235)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1611)
Caused by: java.net.UnknownHostException: <Elastic Search Endpoint>
at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:797)
at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1505)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1364)
at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1298)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:664)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager$InternalAddressResolver.resolveRemoteAddress(PoolingNHttpClientConnectionManager.java:635)
at org.apache.http.nio.pool.AbstractNIOConnPool.processPendingRequest(AbstractNIOConnPool.java:474)
at org.apache.http.nio.pool.AbstractNIOConnPool.lease(AbstractNIOConnPool.java:280)
at org.apache.http.impl.nio.conn.PoolingNHttpClientConnectionManager.requestConnection(PoolingNHttpClientConnectionManager.java:295)
at org.apache.http.impl.nio.client.AbstractClientExchangeHandler.requestConnection(AbstractClientExchangeHandler.java:377)
at org.apache.http.impl.nio.client.DefaultClientExchangeHandlerImpl.start(DefaultClientExchangeHandlerImpl.java:129)
at org.apache.http.impl.nio.client.InternalHttpAsyncClient.execute(InternalHttpAsyncClient.java:141)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:244)
... 49 more
And my Java Code:
String ELASTIC_SEARCH_USER_NAME = "elastic";
String ELASTIC_SEARCH_PASSWORD = <Password>;
String ELASTIC_SEARCH_ENDPOINT_URL = "https://92d5f385db294fb4b7ff335201d0a854.asia-northeast1.gcp.cloud.es.io";
Integer ELASTIC_SEARCH_PORT = 9243;
final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(ELASTIC_SEARCH_USER_NAME, ELASTIC_SEARCH_PASSWORD));
RestClientBuilder builder = RestClient.builder(new HttpHost(ELASTIC_SEARCH_ENDPOINT_URL, ELASTIC_SEARCH_PORT, "https"))
.setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
#Override
public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
});
RestHighLevelClient highLevelClient = new RestHighLevelClient(builder);
Strangely, I have tried pinging my endpoint url in the command line but my cmd is unable to ping the url.
Is there something I need to set up in my Elastic Stack Console for my Java Client to request queries?
Thank you!
Are you sure, that your Elasticsearch is running on port 9243? This is in GCP but for AWS managed ES, there is no need to give the port number and only url is sufficient, make a change to below part of code and see if it works as it works in AWS ES where we don't have to mention the port.
RestClientBuilder builder = RestClient.builder(new HttpHost(ELASTIC_SEARCH_ENDPOINT_URL,, "https"))
Asking the guys over at elastic.co forums, they suggested that I drop the "https://" portion from the ELASTIC_SEARCH_ENDPOINT_URL.
String ELASTIC_SEARCH_ENDPOINT_URL = "https://92d5f385db294fb4b7ff335201d0a854.asia-northeast1.gcp.cloud.es.io";
to
String ELASTIC_SEARCH_ENDPOINT_URL = "92d5f385db294fb4b7ff335201d0a854.asia-northeast1.gcp.cloud.es.io";
and keeping the rest of the code, it worked!
The forum post I made if anyone wants to take a look
I have to use Websocket connection in my project with angular 2
I have trouble with creating Websocket connection with error
'WebSocket connection to 'ws://localhost:8081/.../.../..' failed: HTTP Authentication failed; no valid credentials available'
Here's my code
var socket = new WebSocket('ws:localhost:8081/../../..');
I have been stack for a few days. Please anyone who know about this help me.
Best Regards
You can the websocket wrapper from the rxjs library.
Import it like this:
import {webSocket, WebSocketSubject} from 'rxjs/webSocket';
And then create one like this:
private webSocket: WebSocketSubject = webSocket(environment.chatUrl);
Then you can subscribe to it to get inbound messages:
this.subscription = this.webSocket.subscribe(
msg => {
// do something with the message
},
err => {
// handle the error
console.log('error!', err);
},
() => {
// handle getting disconnected
console.log('websocket closed');
}
);
And send out a message:
this.webSocket.next(message);
And don't forget to unsubscribe from the websocket when you're finished.
this is happened due to following reason
your http url and websocket url is not matched at authentication time
your http url is
http://localhost:port/something..
and your websocket url is
var webs = new WebSocket("ws://192.168...:port/something..");
or vice versa
to fix this issue keep both url same
I'm trying to connect to a URL in an AsynTask but am having trouble.
Document doc = Jsoup.connect("https://www.gasbuddy.com/home?search=33444&fuel=1").get();
gives me an error in my log saying:
Error Connecting: failed to connect to www.gasbuddy.com/104.17.148.191 (port 443) after 30000ms
After doing some research, I believe I need to connect to the baseURL. However, I'm not sure how to do this. I've tried:
URL absoluteUrl = new URL(new URL("https://www.gasbuddy.com/home?search=33444&fuel=1"), "script.js");
Document doc = Jsoup.connect(String.valueOf(absoluteUrl)).get();
But I get the same error in my my logs.
Edit: I get the same error on any website I try connecting too ("https://www.yahoo.com/", "https://www.google.com/", etc) I'm on a a public Starbucks Wifi at the moment, not sure if that matters.
I am accessing a https Webservice through a jar, the service gets created and port also get instantiated but when trying to call the remote method of the Web Service ,it throws the following error.
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: A remote host did not respond within the timeout period.
Please note that i am overriding the hostnameverifier to verify all host names as the certificate added to the keystore had a different CN from the URL of the Web Service that i am accessing through my jar.
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
new javax.net.ssl.HostnameVerifier(){
public boolean verify(String hostname,
javax.net.ssl.SSLSession sslSession)
{
mylog.setLog("Hostname Verification successfully overriden.");
return true;
}
});
The tool that i am using is CXF .Following is the full stacktrace.
com.sun.xml.internal.ws.client.ClientTransportException: HTTP transport error: java.net.ConnectException: A remote host did not respond within the timeout period.
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:133)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:154)
at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:95)
at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:117)
at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:599)
at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:558)
at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:543)
at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:440)
at com.sun.xml.internal.ws.client.Stub.process(Stub.java:223)
at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:136)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:110)
at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:90)
at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:119)
at com.sun.proxy.$Proxy25.transferFileService(Unknown Source)
at com.mywsclient.cxf.transfer.FileTransfer.transferToWebService(FileTransfer.java:183)
at com.mywsclient.cxf.transfer.FileTransfer.run(FileTransfer.java:236)
at java.lang.Thread.run(Thread.java:738)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:908)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:931)
at java.lang.Thread.run(Thread.java:738)
Caused by: java.net.ConnectException: A remote host did not respond within the timeout period.
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:381)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:243)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:230)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:377)
at java.net.Socket.connect(Socket.java:539)
at java.net.Socket.connect(Socket.java:488)
at sun.net.NetworkClient.doConnect(NetworkClient.java:175)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:424)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:538)
at com.ibm.net.ssl.www2.protocol.https.c.<init>(c.java:64)
at com.ibm.net.ssl.www2.protocol.https.c.a(c.java:65)
at com.ibm.net.ssl.www2.protocol.https.d.getNewHttpClient(d.java:15)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:978)
at com.ibm.net.ssl.www2.protocol.https.d.connect(d.java:32)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1043)
at com.ibm.net.ssl.www2.protocol.https.b.getOutputStream(b.java:79)
at com.sun.xml.internal.ws.transport.http.client.HttpClientTransport.getOutput(HttpClientTransport.java:121)
... 19 more
Finally Resolved the issue, the endpoint that was getting used was different than the url where the wsdl was located.Managed to override the same with the URL that had the wsdl and it worked.(Point to note,i was using a dynamic URL to locate wsdl).Below is the code to set endpoint .
BindingProvider bp = (BindingProvider) port;
Map<String, Object>req_context_map=bp.getRequestContext();
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, my_url);
Cheers.
I want to ask you a question about this exception. I need more information but i dont find anything. Actually this test i am receiving this exception:
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect
The url also exists and retrieve me data if i put that url in a browser. The exception raises in the line of the ClientResponse. Please give more info. Actually im using a proxy to establish connection with the server , but my data are OK, in my project.properties. Any idea why happens this??. Im communicating with a remote server , no in localhost.
Client client = Client.create();
WebResource webResource = client
.resource("http://someurl");
String input= "{'test'}";
ClientResponse response = webResource.type("application/json")
.post(ClientResponse.class, input);