Couchbase N1QL query Connection failed - java

I'm customizing couchbase sql importer open source code in maven project.
this is my code.
CouchbaseEnvironment env = DefaultCouchbaseEnvironment.builder()
.socketConnectTimeout((int) TimeUnit.SECONDS.toMillis(45))
.connectTimeout(TimeUnit.SECONDS.toMillis(60))
.build();
cluster = CouchbaseCluster.create(env,"couchbase-dev.thisisdmg.com:8091");
bucket = cluster.openBucket(bucketName);
com.couchbase.client.java.query.Statement statement = select("*").from(i("sales_agent")).where("meta(t).id = 'appointments_appointment:1'").limit(50).offset(0);
JsonObject placeholderValues = JsonObject.create().put("age", 22);
for (N1qlQueryRow row : bucket.query(N1qlQuery.parameterized(statement, placeholderValues))) {
System.out.println(row);
}
When I send the query to server, I'm getting bellow error.
Mar 28, 2017 4:40:28 PM com.couchbase.client.core.endpoint.AbstractEndpoint$2 onSuccess
WARNING: [null][QueryEndpoint]: Could not connect to remote socket.
Mar 28, 2017 4:40:28 PM com.couchbase.client.core.endpoint.AbstractEndpoint$2 onSuccess
WARNING: [null][QueryEndpoint]: Could not connect to endpoint, retrying with delay 4096 MILLISECONDS:
com.couchbase.client.deps.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: couchbase-dev.thisisdmg.com/5.9.216.200:8093
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
at com.couchbase.client.deps.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:257)
at com.couchbase.client.deps.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:291)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:631)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:566)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:480)
at com.couchbase.client.deps.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:442)
at com.couchbase.client.deps.io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:131)
at com.couchbase.client.deps.io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
at java.lang.Thread.run(Thread.java:745)
Please help me, how can I fix this problem.

Related

Application does not stop after AWSIotMqttClient disconnected

I'm working with AWSIotMqttClient to subscribe and publish to topics. After I received all messages I want to stop my application. But it works infinitely long. Here a simple code which works infinitely, even without subscribes:
SampleUtil.KeyStorePasswordPair keyStorePasswordPair =
SampleUtil.getKeyStorePasswordPair("certificate.pem", "privateKey.pem");
AWSIotMqttClient client = new AWSIotMqttClient(
"mqtt-broker.address",
"deviceID",
keyStorePasswordPair.keyStore,
keyStorePasswordPair.keyPassword);
client.connect();
client.disconnect();
Here is my logs:
> Task :Application.main()
Cert file:certificate.pem Private key: privateKey.pem
????. 20, 2019 11:56:45 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionSuccess
INFO: Connection successfully established
????. 20, 2019 11:56:45 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionSuccess
INFO: Client connection active: 5dcd561596c30e0001e4b5d5
????. 20, 2019 11:56:53 AM com.amazonaws.services.iot.client.core.AwsIotConnection onConnectionClosed
INFO: Connection permanently closed
????. 20, 2019 11:56:53 AM com.amazonaws.services.iot.client.core.AbstractAwsIotClient onConnectionClosed
INFO: Client connection closed: 5dcd561596c30e0001e4b5d5
I can stop my application with System.exit(0) but it is undesirable for me. I expect that after all code is passed, the application will stop.
Found here . Updating aws-iot-device-sdk to 1.3.4 version
implementation 'com.amazonaws:aws-iot-device-sdk-java:1.3.4'
implementation 'com.amazonaws:aws-iot-device-sdk-java-samples:1.3.4'
resolved the problem.

How to fix SocketException while connecting to Telegram Bot API in Java App

I'm working on my Telegram bot. I know, in my countries Telegram is locked, so I decide to connect to Telegram Bot API through proxy. When I try to run this code:
import org.telegram.telegrambots.ApiContextInitializer;
import org.telegram.telegrambots.bots.DefaultBotOptions;
import org.telegram.telegrambots.meta.ApiContext;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
public class SharperBotApp {
private static final String PROXY_HOST = "89.200.150.35";
private static final int PROXY_PORT = 37499;//TODO
public static void main(String[] args) {
ApiContextInitializer.init();
TelegramBotsApi botsApi = new TelegramBotsApi();
DefaultBotOptions botOptions = ApiContext.getInstance(DefaultBotOptions.class);
botOptions.setProxyHost(PROXY_HOST);
botOptions.setProxyPort(PROXY_PORT);
botOptions.setProxyType(DefaultBotOptions.ProxyType.SOCKS4);
try {
botsApi.registerBot(new SharperBot(botOptions));
} catch (TelegramApiRequestException e) {
e.printStackTrace();
}
}
}
I'm getting this stack trace:
Jun 12, 2019 11:56:51 AM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://api.telegram.org:443
Jun 12, 2019 11:56:51 AM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.telegram.org:443: Malformed reply from SOCKS server
Jun 12, 2019 11:56:51 AM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://api.telegram.org:443
Jun 12, 2019 11:56:52 AM org.apache.http.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://api.telegram.org:443: Malformed reply from SOCKS server
Jun 12, 2019 11:56:52 AM org.apache.http.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://api.telegram.org:443
org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: Error removing old webhook
at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:79)
at org.telegram.telegrambots.bots.TelegramLongPollingBot.clearWebhook(TelegramLongPollingBot.java:25)
at org.telegram.telegrambots.meta.TelegramBotsApi.registerBot(TelegramBotsApi.java:120)
at bot.SharperBotApp.main(SharperBotApp.java:24)
Caused by: org.telegram.telegrambots.meta.exceptions.TelegramApiException: Unable to execute deleteWebhook method
at org.telegram.telegrambots.bots.DefaultAbsSender.sendApiMethod(DefaultAbsSender.java:719)
at org.telegram.telegrambots.meta.bots.AbsSender.execute(AbsSender.java:47)
at org.telegram.telegrambots.util.WebhookUtils.clearWebhook(WebhookUtils.java:74)
... 3 more
Caused by: java.net.SocketException: Malformed reply from SOCKS server
at java.net.SocksSocketImpl.readSocksReply(SocksSocketImpl.java:129)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:459)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339)
at org.telegram.telegrambots.facilities.proxysocketfactorys.SocksSSLConnectionSocketFactory.connectSocket(SocksSSLConnectionSocketFactory.java:41)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)
at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
at org.telegram.telegrambots.bots.DefaultAbsSender.sendHttpPostRequest(DefaultAbsSender.java:765)
at org.telegram.telegrambots.bots.DefaultAbsSender.sendMethodRequest(DefaultAbsSender.java:761)
at org.telegram.telegrambots.bots.DefaultAbsSender.sendApiMethod(DefaultAbsSender.java:716)
... 5 more
Process finished with exit code 0
I googled it and found that people advise to use proxy... But I've already done it! So I decided to use VPN. I installed windscribe on my laptop but then also got this exception. What should I try to do? Maybe, I'm doing something wrong? (There is Debian 9 installed on my laptop).
All you need is just to use tor proxy:
public class MyApplication {
public static void main(String[] args) {
System.getProperties().put("proxySet", true);
System.getProperties().put("socksProxyHost", 127.0.0.1);
System.getProperties().put("socksProxyPort", 9050);
}
}
But previously you should install tor service:
sudo apt-get install tor

ERROR: HikariPool-1 - Connection is not available, request timed out after 10000ms

I am developing an API... and after requested several endpoints the server show me this message...
WARN: SQL Error: 0, SQLState: null Jun 24, 2016 9:51:45 PM
org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions ERROR:
HikariPool-1 - Connection is not available, request timed out after 10000ms. Jun
24, 2016 9:51:45 PM com.healthymama.utils.DEVLoggingFilter log INFO: 967 *
Server responded with a response on thread grizzly-http-server-2
The project is made with hibernate, mysql and Hikari... Could you help me? Thanks!
Here the configuration:
url = String.format("jdbc:mysql://%s:%s/%s?autoReconnect=true", host, port, bundle.getString("db.database"));
configuration
.setProperty("hibernate.order_updates", "true")
.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect")
.setProperty("hibernate.hbm2ddl.auto", "update")
.setProperty("hibernate.connection.provider_class", "com.zaxxer.hikari.hibernate.HikariConnectionProvider")
.setProperty("hibernate.hikari.dataSourceClassName", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource")
.setProperty("hibernate.hikari.dataSource.url", url)
.setProperty("hibernate.hikari.dataSource.user", username)
.setProperty("hibernate.hikari.dataSource.password", password)
.setProperty("hibernate.hikari.dataSource.cachePrepStmts", "true")
.setProperty("hibernate.hikari.dataSource.prepStmtCacheSize", "250")
.setProperty("hibernate.hikari.dataSource.prepStmtCacheSqlLimit", "2048")
.setProperty("hibernate.hikari.minimumIdle", "5")
.setProperty("hibernate.hikari.minimumIdle", "5")
.setProperty("hibernate.hikari.maximumPoolSize", "10")
.setProperty("hibernate.hikari.idleTimeout", "30000")
.setProperty("hibernate.hikari.connectionTestQuery", "SELECT 1")
.setProperty("hibernate.hikari.connectionTimeout", "10000");

Connection immediately is aborted when trying to connect to remote cluster-node

I am trying to connect to an Elasticsearch cluster form a Java application by using the TransportClient.
I have successfully tested connected to a cluster running locally.
Now we have set up a remote cluster in the EC2-Cloud. Accessing it via REST intefaces work, also Kibana works.
I can run my application on the Elasticsearch Node directly successfully.
However when I try to connect remotely from another host, the log indicates that the connection succeeds, but then immediately fails with "An established connection was aborted by the software in your host machine".
I have verified that both server and client run the same version of Elasticsearch. Also the firewall configuration should allow communication on port 9300 as this is also needed for the cluster-nodes to communicate between each other.
Okt 21, 2015 6:50:24 PM com.example.elasticsearch.visit.nativescript.ElasticsearchTest main
INFO: Setting adress to myhost.com:9300
Okt 21, 2015 6:50:24 PM org.elasticsearch.client.transport.TransportClientNodesService addTransportAddresses
FINE: [Master Man] adding address [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]]
Okt 21, 2015 6:50:24 PM org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler doSample
FINEST: [Master Man] connecting to listed node (light) [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]]
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport connectToNode
FINE: [Master Man] connected to node [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]]
Okt 21, 2015 6:50:24 PM org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker addWithoutBreaking
FINEST: [Master Man] [REQUEST] Adjusted breaker by [16440] bytes, now [16440]
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.TransportService$Adapter traceRequestSent
FINEST: [Master Man] [0][cluster:monitor/nodes/info] sent to [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]] (timeout: [5s])
Okt 21, 2015 6:50:24 PM org.elasticsearch.common.breaker.ChildMemoryCircuitBreaker addWithoutBreaking
FINEST: [Master Man] [REQUEST] Adjusted breaker by [-16440] bytes, now [0]
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport exceptionCaught
FINEST: [Master Man] close connection exception caught on transport layer [[id: 0xd938d867, /x.x.x.x:60058 => myhost.com/1.1.1.1:9300]], disconnecting from relevant node
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:64)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337)
at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89)
at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108)
at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport disconnectFromNode
FINE: [Master Man] disconnecting from [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]], channel closed event
Okt 21, 2015 6:50:24 PM org.elasticsearch.transport.netty.NettyTransport disconnectFromNode
FINEST: [Master Man] disconnected from [[#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]]], channel closed event
Okt 21, 2015 6:50:24 PM org.elasticsearch.client.transport.TransportClientNodesService$SimpleNodeSampler doSample
INFO: [Master Man] failed to get node info for [#transport#-1][LNZ123675N02][inet[myhost.com/1.1.1.1:9300]], disconnecting...
org.elasticsearch.transport.NodeDisconnectedException: [][inet[myhost.com/1.1.1.1:9300]][cluster:monitor/nodes/info] disconnected
Okt 21, 2015 6:50:24 PM com.example.elasticsearch.visit.nativescript.ElasticsearchTest main
INFO: Having: []
Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.support.AbstractClient.bulk(AbstractClient.java:167)
at org.elasticsearch.client.transport.TransportClient.bulk(TransportClient.java:370)
at org.elasticsearch.action.bulk.BulkRequestBuilder.doExecute(BulkRequestBuilder.java:166)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at com.example.elasticsearch.visit.nativescript.ElasticsearchTest.main(ElasticsearchTest.java:68)
My simple test looks like this:
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", "cluster-name")
.build();
logger.info("Creating client");
try (final TransportClient client = new TransportClient(settings)) {
logger.info("Setting adress to " + host + ":" + port);
client.addTransportAddress(new InetSocketTransportAddress(host, port));
logger.info("Having: " + client.connectedNodes());
BulkRequestBuilder bulkRequest = client.prepareBulk();
String json= "{ id: \"12345678\", value: \"value\" }";
bulkRequest.add(client.prepareIndex(INDEX, TYPE, "12345678").
setSource(json));
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
logger.info("Could not write bulk: " + bulkResponse.buildFailureMessage());
} else {
logger.info("Wrote");
}
}
I also tried to verify some common things like cluster-name not set and others.
Also when I use a completely different port, I get a timeout as expected, not this error-message. So the port is definitely behaving different.
Where would I start to look? Can this still be a firewall issue where connections are dropped only after a short while instead of being rejected immediately?
With more testing I actually found out that a company-firewall was interfering in a strange way. When I run the same client-code on a machine outside the company-netowrk, it works fine.

How to solve "java.net.SocketException: Connection reset" when using tigase.jaxmpp.j2se.Jaxmpp 3.0.0

I have written a JAXMPPClient.java program which uses tigase.jaxmpp.j2se.Jaxmpp 3.0.0
I have the following .jar files in my build path
jaxmpp-core-3.0.0
jaxmpp-j2se-3.0.0
and folder jaxmpp-all-3.0.0 containing many .jar files. The JAXMPPClient.java is as follows
Jaxmpp conn = new Jaxmpp();
conn.getConnectionConfiguration().setConnectionType(
ConnectionType.socket);
conn.getConnectionConfiguration().setDomain(IP_ADDRESS_OF_XMPP_SERVER);
conn.getConnectionConfiguration().setPort(PORT_NUMBER_OF_XMPP_SERVER);
conn.getConnectionConfiguration().setUserJID(FROM_USERID + "#" +
IP_ADDRESS_OF_XMPP_SERVER);
conn.getConnectionConfiguration().setUserPassword(FROM_PASSWORD);
String s = tigase.jaxmpp.j2se.connectors.socket.
SocketConnector.HOSTNAME_VERIFIER_DISABLED_KEY
conn.getSessionObject().setProperty(s, Boolean.TRUE);
try {
System.out.println("Before login");
conn.login();
System.out.println("After login");
} catch (final JaxmppException e) {
e.printStackTrace();
}
I am getting
Before login
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.Jaxmpp createConnector
INFO: Using SocketConnector
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.connectors.socket.SocketConnector start
INFO: Resolving SRV recrd of domain '123.45.678.910'
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.connectors.socket.SocketConnector start
INFO: Opening connection to /123.45.678.910:5222
Sep 29, 2015 5:17:12 PM tigase.jaxmpp.j2se.connectors.socket.Worker run
WARNING: Exception in worker
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:209)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at tigase.jaxmpp.j2se.connectors.socket.TextStreamReader.read(TextStreamReader.java:49)
at tigase.jaxmpp.j2se.connectors.socket.Worker.run(Worker.java:99)
After login
The IP Address, Port number, From JabberID and Password are correct and are working fine from iOS and Android Apps. Also I am able to successfully ping the Tigase server IP address.
From where is the java.net.SocketException being thrown ? How can I fix this problem ?

Categories

Resources