I/O Socket error (Java) - java

I have a problem using a socket:
socket = new Socket(hostname, port);
os = socket.getOutputStream();
oos = new ObjectOutputStream(os);
is = socket.getInputStream();
ois = new ObjectInputStream(is); // THIS ALWAYS RAISES EXCEPTION
I have checked "is" is not null (with println):
java.net.SocketInputStream#403a7c5e
The IOexception message is: null
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2297)
at java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:2766)
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:797)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:297)
at com.my.Comunication.sendData(Netw.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.sun.xml.ws.api.server.InstanceResolver$1.invoke(InstanceResolver.java:246)
at com.sun.xml.ws.server.InvokerTube$2.invoke(InvokerTube.java:146)
at com.sun.xml.ws.server.sei.EndpointMethodHandler.invoke(EndpointMethodHandler.java:257)
at com.sun.xml.ws.server.sei.SEIInvokerTube.processRequest(SEIInvokerTube.java:95)
at com.sun.xml.ws.api.pipe.Fiber.__doRun(Fiber.java:629)
at com.sun.xml.ws.api.pipe.Fiber._doRun(Fiber.java:588)
at com.sun.xml.ws.api.pipe.Fiber.doRun(Fiber.java:573)
at com.sun.xml.ws.api.pipe.Fiber.runSync(Fiber.java:470)
at com.sun.xml.ws.server.WSEndpointImpl$2.process(WSEndpointImpl.java:295)
at com.sun.xml.ws.transport.http.HttpAdapter$HttpToolkit.handle(HttpAdapter.java:515)
at com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:285)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:143)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:155)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:189)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:76)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:636)
Does anybody know what is going on? Thanks.
EDIT: The object is an ObjectInputStream

My first guess is that the input stream you're getting is not a valid object stream. An ObjectInputStream is recognized by a particular stream header.
The important thing though is not only to understand this exception, but to learn how to analyze exceptions and failures. I suggest the following:
Examine your program's output (log files or console). See if it shows the exact type of exception and the full stack trace.
Use a debugger. Put a breakpoint at the problematic line, stop there with a debugger, and then step into the code until you get to the exception.
EDIT:
The stack trace shows that the ObjectInputStream tries to read a short value from the input stream, but the stream doesn't have any more data in it. Sounds like the server isn't sending the data you're expecting. (Or it simply isn't sending any data at all.)
In order to analyze the data you're receiving from the socket, you can temporarily change the code so that it reads from the input stream and dumps the contents (e.g. to System.out). Or you can use a network sniffer (such as Wireshark) that will show you all the network traffic between your machine and the server.

To expand on Eli's answer a bit, the input stream is not only not a valid ObjectInputStream produced by an ObjectOutputStream at the peer, it is also empty. The peer has closed the connection without instantiating an ObjectOutputStream on it at all, or doing any I/O whatsoever.

Related

Communication to DB error in production [duplicate]

This question already has answers here:
Is it safe to use a static java.sql.Connection instance in a multithreaded system?
(2 answers)
Closed 6 years ago.
I did some web app to deploy in production. But after several hours (looks like 8 hour), I can't communicate with DB.
Here is my Connect.java
package util;
import java.sql.Connection;
import java.sql.DriverManager;
import javax.xml.ws.Response;
public class Connect {
public static Connection connection = null;
public static Connection getConnection() {
if (connection != null) {
return connection;
} else {
String driver = "com.mysql.jdbc.Driver";
String url = "jdbc:mysql://localhost/DBPRK?autoReconnect=true&useUnicode=true&characterEncoding=utf8";
String username = "prk";
String password = "prk";
try {
Class.forName(driver);
connection = DriverManager.getConnection(url, username, password);
} catch (Exception e) {
System.out.println("ERROR");
}
return connection;
}
}
}
and Here is error message that i got from tomcat log:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Software caused connection abort: socket write error
STACKTRACE:
java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:113)
at java.net.SocketOutputStream.write(SocketOutputStream.java:159)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2616)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2547)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1512)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1183)
at controller.GetAllClients.processRequest(GetAllClients.java:39)
at controller.GetAllClients.doGet(GetAllClients.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
** END NESTED EXCEPTION **
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2634)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2547)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1512)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1622)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2370)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1183)
at controller.GetAllClients.processRequest(GetAllClients.java:39)
at controller.GetAllClients.doGet(GetAllClients.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:745)
Btw I use pure jsp with no framework.
Any help is very appreciate.
This problem may occur in following cases:
When we are trying to get too many DB connections.
When a DB connection is idle for a long time.
So, in your program try to close connection after usage, and get a new connection.
Buddy, add port number (3306) in your connection in the String Url
This is showing exception in your code at following line:
at controller.GetAllClients.processRequest(GetAllClients.java:39)
at controller.GetAllClients.doGet(GetAllClients.java:73)
The reason that might be causing this exception is that probably you are not closing connections once obtained and used.
In any computer system, there are a limited number of sockets available for connections and this strongly depends on your hardware specification and driver you are using for connection.
A connection to a database is something that has high cost in terms of resources and performance. This must be taken care every time when you think of connecting to a database.
Now assume a situation, where you have 5 bikes and 7 riders, all riders need a bike, so you can allocate 1 bike to each rider but only upto 5 riders, then what about rest 2 ?. So now only option is to wait for any two riders who complete their ride and return the bike so that you can allocate it to other twos... But in your case, first 5 took away the bike (got connection to database), completed their ride (executed their queries to database) but didn't return bike (are not closing the connection).
Likewise, in your case it is being allotted but not being released after usage, which in turn occupies all available socket and no socket is available to provide connection.
I assume you are catching the "connection" (returned by getConnection() method) in "con" variable.
Now,
con.close();
just only this needs to be written there.
And one more thing, currently all sockets are occupied you need to restart the database server (MySQL etc.) and project server (Tomcat etc.). And add above 1 line code everywhere after database usage is over.

Exception when trying to get large attachments

I'm using saaj to get attachments with my java servlet (hosted with apache and tomcat).
When trying to call message.getAttachments(); (where message is SOAPMessage object):
If the attachment is small (few KB) - it works
If the attachment is big (few MB) - it throws the following exception:
java.lang.RuntimeException: org.jvnet.mimepull.MIMEParsingException: java.io.IOException: The system cannot find the path specified
at com.sun.xml.messaging.saaj.soap.MessageImpl.getAttachments(MessageImpl.java:826)
at MyCode.MyServlet.doPost(MyServlet.java:215)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:283)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:767)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:697)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:889)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Unknown Source)
Caused by: org.jvnet.mimepull.MIMEParsingException: java.io.IOException: The system cannot find the path specified
at org.jvnet.mimepull.MemoryData.createNext(MemoryData.java:93)
at org.jvnet.mimepull.Chunk.createNext(Chunk.java:59)
at org.jvnet.mimepull.DataHead.addBody(DataHead.java:82)
at org.jvnet.mimepull.MIMEPart.addBody(MIMEPart.java:192)
at org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:235)
at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:176)
at org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:101)
at com.sun.xml.messaging.saaj.packaging.mime.internet.MimePullMultipart.parseAll(MimePullMultipart.java:118)
at com.sun.xml.messaging.saaj.packaging.mime.internet.MimePullMultipart.parse(MimePullMultipart.java:129)
at com.sun.xml.messaging.saaj.packaging.mime.internet.MimeMultipart.getCount(MimeMultipart.java:199)
at com.sun.xml.messaging.saaj.soap.MessageImpl.initializeAllAttachments(MessageImpl.java:1384)
at com.sun.xml.messaging.saaj.soap.MessageImpl.getAttachments(MessageImpl.java:824)
... 22 more
Caused by: java.io.IOException: The system cannot find the path specified
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(Unknown Source)
at java.io.File.createTempFile(Unknown Source)
at org.jvnet.mimepull.MemoryData.createNext(MemoryData.java:87)
... 33 more
How can I solve this issue?
Thanks!
The sourcecode of MimePull, which produces the Exception, says this:
if (!config.isOnlyMemory() && dataHead.inMemory >= config.memoryThreshold) {
try {
String prefix = config.getTempFilePrefix();
String suffix = config.getTempFileSuffix();
File dir = config.getTempDir();
File tempFile = (dir == null)
? File.createTempFile(prefix, suffix) // here your code crashes
: File.createTempFile(prefix, suffix, dir);
LOGGER.fine("Created temp file = "+tempFile);
dataHead.dataFile = new DataFile(tempFile);
} catch(IOException ioe) {
throw new MIMEParsingException(ioe);
}
It tries to open a temp file, because the memory size threshold is passed.
It is called
at MyCode.MyServlet.doPost(MyServlet.java:215)
It looks like you are using SAAJ to receive the messages and have enabled the MimePull plugin (using -Dsaaj.use.mimepull=true flag). It should allow receiving larger files, as the MimePull implementation uses temporary files as a fallback.
Now the bad news seems to be, that you can't configure the MimePull reader through your SAAJ configuration.
The good news may be that you are able to tweak the logic of File.createTempFile(...) through the system property java.io.tmpdir.
Try starting with -Djava.io.tmpdir=/path/to/tmpdir.
Else maybe try to consume the message directly with MimePull I never did this myself, so don't ask me about it. ;-)
EDIT:
Or switch off MimePull completely by setting -Dsaaj.use.mimepull=false if you do not expect your attachments to soak up all your memory.
We solved the problem by just changing the Jersey-Libs version from 1.13 to 1.19. Seems that 1.13 is buggy.

IllegalStateException: null in HttpServlet.service

I'm simply trying to send back an error to the client when a request fails. Here's what my code looks like:
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
"Email and username are required fields.");
This code throws the following error:
java.lang.IllegalStateException: null
at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:407) ~[catalina-6.0.26.jar:6.0.26]
at com.****.****.****.*********Servlet.service(********Servlet.java:68) ~[********Servlet.class:na]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717) ~[javaee-api-5.1.2.jar:5.1.2]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[catalina-6.0.26.jar:6.0.26]
at org.red5.logging.LoggerContextFilter.doFilter(LoggerContextFilter.java:78) ~[red5.jar:na]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) ~[catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:465) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:555) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [catalina-6.0.26.jar:6.0.26]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298) [catalina-6.0.26.jar:6.0.26]
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852) [tomcat-coyote-6.0.26.jar:6.0.26]
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588) [tomcat-coyote-6.0.26.jar:6.0.26]
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489) [tomcat-coyote-6.0.26.jar:6.0.26]
Why is this being thrown here? I'm not doing anything before this call that has anything at all to do with the response object, I'm not even touching it until this error is sent in an if clause. Why am I getting this error?
The only reason for HttpServletResponse (implemented by ResponseFacade) to throw an IllegalStateException is that the response was already committed before. It must have been touched by someone before already.
If your ResponseFacade does not override response.sendError() or it leads to forwarding to the error page, it is happening because the response is getting committed before forwarding to the error page.
To resolve this issue,
make sure you are not flushing the response
If the response is committing automatically because the max buffer size has reached, try increasing the buffer size.

Exception in beginTransaction

I am using hibernate in my web application,when I am getting exception while:
Transaction tx=session.beginTransaction();
It gives exception once in a while, I am reloading SessionFactory while catching the exception and then it runs fine.
It is working when I am reloading the SessionFactory again.
This is my code snippet:
session = HibernateFactory.openSession(0);//Passing 0 uses the existing sessionFactory
if(session.isConnected() && session.isOpen() && session!=null)
{
try{
tx = session.beginTransaction();
logger.info("Transaction is begin successfully--Transaction is--"+tx);
}catch(Exception e){
logger.info("Could not start the transaction--Transaction is--"+tx);
session = HibernateFactory.openSession(1);//passing 1 is creating new //--SessionFactory
tx = session.beginTransaction();//now this runs fine
logger.info("Inside catch--Obtained session--"+session+"and transaction--"+tx);
e.printStackTrace();
logger.error("e.getCause(): "+e.getCause());
logger.error("e.getClass(): "+e.getClass());
// throw new HibernateException(e.getMessage());
}
}
This is the stackTrace of the exception I am getting.
org.hibernate.exception.JDBCConnectionException: Cannot open connection
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:426)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:119)
at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:57)
at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1326)
at com.arosys.hibernateDao.AbstractDao.startOperation(AbstractDao.java:184)
at com.arosys.hibernateDao.AbstractDao.findAll(AbstractDao.java:150)
at com.arosys.beansDao.JobHierarchyDao.findAll(JobHierarchyDao.java:20)
at org.ArosysLogin.server.GWTJobImpl.getJobHierarchy(GWTJobImpl.java:416)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:861)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1584)
at java.lang.Thread.run(Thread.java:662)
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
Just guessing since there isn't enough information (type and message of the exception):
Connection fails due to flaky database/network connection
do you commit your transactions? I'm not sure, but Hibernate might complain if you try to start a transaction twice.
UPDATE based on the call stack.
This seems to be a problem with the database. check out the various results for googling "com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure"
This one might help: https://serverfault.com/questions/89955/unable-to-connect-to-mysql-through-jdbc-connector-through-tomcat-or-externally
Are you sure your connections get closed after usage? I can imagine the database denying access after so many connections are opened. Checking the logs of your database might help as well.
Set ValidateConnectionOnBorrow to true
and add a validation query for SQLForValidateConnection
Set autoReconnect to true for jdbc URL
either by Server connection pool configuration or connection pool configuration.
I assume(from the stack trace) that you are using MySQL,Hibernate with either JBoss or Tomcat.
Let me know in case you face any problem, I faced the same long ago.

Axis 2 generated code in "Expanded Mode"

I'm having some problems understanding how to send a request to a web service that I have deployed. I have followed the following tutorial:
http://wso2.org/library/1719
Which I have successfully applied, and it worked well. The tutorial was straightforward, and I have easily generated a web service client. All I did was creating "request" objects from the exposed web service method, set its arguments, and then using the web service stub, I have passed the request object to the exposed web service method, and got a response.
Now, I have received a WSDL file from which I'm supposed to build a web service client as well. The problem is that the generated files from the WSDL differ greatly from that of the tutorial I followed. I learned later on that when generating clients using ADB, there is a mode called "Expanded Mode" that generates " a class for each of the outer elements and the named complex types " (http://axis.apache.org/axis2/java/core/docs/adb/adb-howto.html#gen_modes). The problem is that I'm unable to understand how to create a request object and get a response from the web service from the generated classes. My best shot was as follows:
GetMfrInventoryProductItemsListE wrapper = new GetMfrInventoryProductItemsListE();
GetMfrInventoryProductItemsList request = new GetMfrInventoryProductItemsList();
request.setArg0(deviceId);
request.setArg1(macAddresses);
request.setArg2(mfrKey);
wrapper.setGetMfrInventoryProductItemsList(request);
GetMfrInventoryProductItemsListResponseE wrapperResponse = wmService.getMfrInventoryProductItemsList(wrapper);
GetMfrInventoryProductItemsListResponse response = wrapperResponse.getGetMfrInventoryProductItemsListResponse();
return response.get_return();
In the above code getGetMfrInventoryProductItemsList is the name of my exposed web service method, and wmService is my stub.
The result was the following stack Trace :
org.apache.axis2.AxisFault: Read timed out
at org.apache.axis2.AxisFault.makeFault(AxisFault.java:430)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:197)
at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.writeMessageWithCommons(CommonsHTTPTransportSender.java:404)
at org.apache.axis2.transport.http.CommonsHTTPTransportSender.invoke(CommonsHTTPTransportSender.java:231)
at org.apache.axis2.engine.AxisEngine.send(AxisEngine.java:443)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:406)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at wavemark.wmservice.soap.WMServiceStub.getMfrInventoryProductItemsList(WMServiceStub.java:3275)
at wavemark.linkserver.supplierconnect.controller.WsStub.getMfrInventoryProductItemsList(WsStub.java:107)
at wavemark.linkserver.supplierconnect.controller.WsManager.getProductItems(WsManager.java:384)
at wavemark.linkserver.supplierconnect.webservices.SupplierConnect.getProductItems(SupplierConnect.java:396)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.axis2.rpc.receivers.RPCUtil.invokeServiceClass(RPCUtil.java:212)
at org.apache.axis2.rpc.receivers.RPCMessageReceiver.invokeBusinessLogic(RPCMessageReceiver.java:117)
at org.apache.axis2.receivers.AbstractInOutMessageReceiver.invokeBusinessLogic(AbstractInOutMessageReceiver.java:40)
at org.apache.axis2.receivers.AbstractMessageReceiver.receive(AbstractMessageReceiver.java:110)
at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:181)
at org.apache.axis2.transport.http.HTTPTransportUtils.processHTTPPostRequest(HTTPTransportUtils.java:172)
at org.apache.axis2.transport.http.AxisServlet.doPost(AxisServlet.java:146)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:241)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:580)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
at java.io.BufferedInputStream.read(BufferedInputStream.java:235)
at org.apache.commons.httpclient.HttpParser.readRawLine(HttpParser.java:78)
at org.apache.commons.httpclient.HttpParser.readLine(HttpParser.java:106)
at org.apache.commons.httpclient.HttpConnection.readLine(HttpConnection.java:1116)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.readLine(MultiThreadedHttpConnectionManager.java:1413)
at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(HttpMethodBase.java:1973)
at org.apache.commons.httpclient.HttpMethodBase.readResponse(HttpMethodBase.java:1735)
at org.apache.commons.httpclient.HttpMethodBase.execute(HttpMethodBase.java:1098)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:398)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at org.apache.axis2.transport.http.AbstractHTTPSender.executeMethod(AbstractHTTPSender.java:621)
at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:193)
... 42 more
After trying to debug the problem, I have found out that this is the line that is throwing the exception:
GetMfrInventoryProductItemsListResponseE wrapperResponse = wmService.getMfrInventoryProductItemsList(wrapper);
I just want you guys to tell me if the way I'm using the request/response objects is correct.Your help is much appreciated.
Finally, I figured out how to solve the problem. Apparently the web service call that I was making, was taking a lot of time that it was timing out as the stack trace shows. So I added the following to my code to the section where I was instantiating my client stub:
wmService = new WMServiceStub();
Options options = new Options();
EndpointReference epr = new EndpointReference(url);
options.setTo(epr);
options.setProperty(HTTPConstants.SO_TIMEOUT, new Integer(300000));
wmService._getServiceClient().setOptions(options);
This results in increasing the Axis 2 web services' socket timeout to 5 minutes, which should be more than enough to most web service calls. I hope that this will be helpful for some developers out there.

Categories