Manage Timeout with Apache Camel - java

I have the following Route definition:
#Override
public void configure() throws Exception {
from(String.format("direct:%s", this.connector))
.id("Route1")
.threads()
.maxPoolSize(10)
.keepAliveTime(3000)
.timeUnit(TimeUnit.MICROSECONDS)
.poolSize(1)
.rejectedPolicy(ThreadPoolRejectedPolicy.Abort)
.log("Calling WS")
.maxQueueSize(1)
.to("http://10.8.4.9:8080/service");
}
And the request snipet above:
InputStream exchange = (InputStream) template
.requestBodyAndHeaders(url, AppUtil.parse(this.body, input), this.headers);
The endpoint is intentionally unavaliable. So, I expected my request wait for 3 seconds and throws some exception as response. Insted, the following behaviour happens:
2018-08-24 16:55:55,048 DEBUG http-nio-8081-exec-2 httpclient.HttpMethodDirector:443 - Connection timed out: connect
java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
... more stack...
at java.lang.Thread.run(Unknown Source)
2018-08-24 16:56:38,333 INFO http-nio-8081-exec-2 httpclient.HttpMethodDirector:445 - Retrying request
2018-08-24 16:56:38,417 DEBUG http-nio-8081-exec-2 httpclient.HttpConnection:692 - Open connection to 10.8.4.9:8080/service
Camel retries for 3 times and do not respect the timeout.
I've tried to use:
onException(ConnectException.class)
.maximumRedeliveries(0);
No success...
What I missed?

The .keepAliveTime(3000) is not for HTTP endpoints, its an API for the JVM thread pool in Java itself. You can read about this option in the Java API for thread pools, and there is also a bit of javadoc on that method in Camel DSL.
If you need HTTP connection timeout etc, then you need to set specific option on the http endpoint.
https://github.com/apache/camel/blob/master/components/camel-http4/src/main/docs/http4-component.adoc#using-client-timeout---so_timeout

Related

java connection from oracle database to oracle essbase server is breaking after 5 minutes i.e. 300 seconds

Facing one strange issue, we are connecting from oracle database to Oracle Essbase Server using JAPI connection (its http connection and no jdbc).
We are able to execute the program till 300 seconds then we get below error: -
invokeMethod localException11111 ::: java.net.SocketTimeoutException: recv() timed out
Resource temporarily unavailable
java.net.SocketTimeoutException: recv() timed out
Resource temporarily unavailable
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:128)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:740)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:683)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1280)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:379)
at com.essbase.api.session.EssOrbPluginHttp.invokeMethod(EssOrbPluginHttp.java:139)
at com.essbase.api.session.EssOrbPluginHttp.invokeMethod(EssOrbPluginHttp.java:109)
at com.essbase.api.session.EssOrbPlugin.essMainCalc(Unknown Source)
at com.essbase.api.datasource.EssCube.calcWithRunTimeSubVars(Unknown Source)
at com.essbase.api.datasource.EssCube.calculate(Unknown Source)
at com.ing.mass.essconnect.Database.calculate(Database.java:314)
at com.ing.mass.essconnect.Database.calculate(Database.java:300)
at com.ing.mass.services.Cubes.calculateNow(Cubes.java:1704)
at com.ing.mass.services.Cubes.calculate(Cubes.java:1510)
invokeMethod finally :::
TESTING .....com.essbase.api.base.EssException: Cannot connect to Provider Server. java.net.SocketTimeoutException: recv() timed out
Resource temporarily unavailable
at com.essbase.api.session.EssOrbPl uginHttp.invokeMethod(EssOrbPluginHttp.java:244)
at com.essbase.api.session.EssOrbPluginHttp.invokeMethod(EssOrbPluginHttp.java:109)
at com.essbase.api.session.EssOrbPlugin.essMainCalc(Unknown Source)
at com.essbase.api.datasource.EssCube.calcWithRunTimeSubVars(Unknown Source)
at com.essbase.api.datasource.EssCube.calculate(Unknown Source)
at com.ing.mass.essconnect.Database.calculate(Database.java:314)
at com.ing.mass.essconnect.Database.calculate(Database.java:300)
at com.ing.mass.services.Cubes.calculateNow(Cubes.java:1704)
at com.ing.mass.services.Cubes.calculate(Cubes.java:1510)
Calculation completed
Calculation completed 111
Cubes calculateNow method finallly
It has been a week scratching our heads to resolve this issue but no luck so far.
Looking forward to hear back with your expert advise.
thanks in advance
Pankaj
this issue is now resolved -
problem was with new java code which required to add a timeout parameter like this
sun.net.client.defaultReadTimeout (set in miliseconds)

java.net.SocketException: Permission denied: connect. What could be the cause and how to avoid it?

I'm running into a java.net.SocketException (Permission denied: connect) when sending a lot of requests to a server. I've tried the -Djava.net.preferIPv4Stack=true option as mentioned in other threads.
This issue only occurs after a lot of connections have already been made. The following code can be used to reproduce the issue:
public class Example {
public static void main(String[] args) {
if(args.length == 1) {
System.out.println(args[0]);
for(int i = 0; i < Integer.MAX_VALUE; i++) {
requestURL(args[0]);
}
}
}
public static void requestURL(String targetUrl) {
URL url = new URL(targetUrl);
HttpURLConnection httpCon = (HttpURLConnection)url.openConnection();
httpCon.setDoInput(true);
BufferedReader rd = new BufferedReader(new InputStreamReader(httpCon.getInputStream()));
//handle response here
rd.close();
httpCon.disconnect();
}
}
The code will successfully send the requests until the Exception occurs. This has been verified in the server's log files.
Please run the sample code only against a server that you are permitted to, as it generates quite a bit of traffic / load on the server.
So the question now is: How to avoid that Exception? Or any workarounds? And what is the actually issue here?
EDIT
added httpCon.disconnect(). (doesn't solve the problem)
EDIT #2 (StackTrace)
java.net.SocketException: Permission denied: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at sun.net.NetworkClient.doConnect(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.openServer(Unknown Source)
at sun.net.www.http.HttpClient.<init>(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.www.http.HttpClient.New(Unknown Source)
at sun.net.protocol.http.HttpURLConnection.getNewHttpClient(Unknown Source)
at sun.net.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
at sun.net.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
at sun.net.protocol.http.HttpURLConnection.connect(Unknown Source)
at Example.requestUrl(Example.java)
at Example.main(Example.java)
When the issue occurs no further requests are sent to the server (no log entries on the server and no SYN packets (sniffed with tcpdump)).
EDIT #3
I've forgotten to run the application with the -Djava.net.preferIPv4Stack=true argument.
It hasn't thrown an exception yet when using both, the aforementioned argument and the httpCon.disconnect() method.
Try to use httpCon.disconnect() to be sure to realease the socket after you finish to read the response.

Why sleep mode connections are not reused by c3p0?

I develop an web application using Spring MVC + MySQL. To manage JDBC connection I used c3p0 for connection pooling.
If I am using c3p0, What I suppose if, 5 connections are open in pool and all 5 connections are in sleep mode and if I request getConnection() from java then one of them should be returned as Connection. Am I correct?
If Yes Then consider following load testing scenario where I am getting Exception Connections could not be acquired from the underlying database!. Using Jmeter I started load test for 250 users in 15 seconds. I m continuously observing DB connections using SHOE FULL PROCESSLIST for first some minutes all is going well but as all the 250 users thrown to web server connections count is reached to 500 which is our maxPoolSize. So after this we are getting Connections could not be acquired from the underlying database!.
At this point if I execute SHOE FULL PROCESSLIST then I can see all 500 connections are in sleep mode If I am correct in above statement that any open connection that is in sleep mode will be returned by c3p0. Then why I am getting this exception.?
Here is my c3p0 properties
MINPOOLSIZE=10
ACQUIREINCREMENT=1
MAXPOOLSIZE=500
INITIALPOOLSIZE=10
NUMBERHELPERTHREAD=100
MAXIDLETIME=10
MAXSTATEMENT=20
MAXSTATEMENTPERCONNECTION=5
IDLECONNECTIONTESTPERIOD=120
ACQUIRERETRYATTEMPT=10
ACQUIRERETRYDELAY=100
AUTOCOMMITONCLOSE=false
BREAKAFTERACQUIREFAILURE=false
TESTCONNECTIONONCHECKOUT=true
TESTCONNECTIONONCHECKIN=true
Update
I found this warning before Connections could not be acquired from the underlying database! Exception
WARN : 30 Jun 2014 10:40:12.078 com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1839) - com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask#e49561 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (10). Last acquisition attempt exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Too many connections
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1015)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4187)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4119)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:927)
at com.mysql.jdbc.MysqlIO.proceedHandshakeWithPluggableAuthentication(MysqlIO.java:1709)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1252)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2483)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2516)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2301)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:834)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.GeneratedConstructorAccessor18.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:416)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:346)
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:183)
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:172)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:188)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1074)
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1061)
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1798)
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:636)
WARN : 30 Jun 2014 10:40:12.078 com.mchange.v2.resourcepool.BasicResourcePool.forceKillAcquires(BasicResourcePool.java:882) - Having failed to acquire a resource, com.mchange.v2.resourcepool.BasicResourcePool#1035ff9 is interrupting all Threads waiting on a resource to check out. Will try again in response to new client requests.

not able to make connection using javamail api

I am trying to make connection to the mailserver using java mail api, with user loginId password and the host name. But if any one of the id fails to make connection then the following ids also fails to authorize even if they have correct credentials.
Do I've to close the store values after the loop.
sessions = Session.getDefaultInstance(properties);
store = sessions.getStore(emailAccType);
store.connect(emailHost,emailId, emailPwd);
What i need to close in finally block of try/catch.
for the following error.
javax.mail.MessagingException: Connect failed;
nested exception is:
javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:161)
at javax.mail.Service.connect(Service.java:288)
at javax.mail.Service.connect(Service.java:169)
at com.scheduler.utils.QuartzImplementation.<init>(QuartzImplementation.java:77)
at com.scheduler.utils.SchedulerRedirect.execute(SchedulerRedirect.java:31)
at org.quartz.core.JobRunShell.run(JobRunShell.java:202)
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:529)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
at com.sun.net.ssl.internal.ssl.InputRecord.handleUnknownRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.InputRecord.read(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.AppInputStream.read(Unknown Source)
at java.io.BufferedInputStream.fill(Unknown Source)
at java.io.BufferedInputStream.read(Unknown Source)
at java.io.DataInputStream.readLine(Unknown Source)
at com.sun.mail.pop3.Protocol.simpleCommand(Protocol.java:360)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:104)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:214)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:157)
for the first time it's executing but if one fails then this problem arise.
Thanks in advance
Refer the answer to this question
Please ensure you've read the java mail API FAQs completely.

Apache CXF Could not send message

im having a random error of could not send message. sometimes there's no error.
what might be the cause?? thanks.
Mar 06, 2014 6:11:13 AM org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
WARNING: Interceptor for {XXX }SoapApiServiceHttpEndpoint#{XXX}createSession has thrown exception, unwin
ding now
org.apache.cxf.interceptor.Fault: Could not send Message.
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:64)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:262)
at org.apache.cxf.endpoint.ClientImpl.doInvoke(ClientImpl.java:531)
Caused by: java.net.SocketException: SocketException invoking : Connection reset
at sun.reflect.GeneratedConstructorAccessor2332.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
Connection reset means that the client abnormally closed the connection and then cxf cannot read or write any further data to the stream. Take a look at following answers for more information:java.net.SocketException: Connection reset

Categories

Resources