Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!

Robert Garrido

Ranch Hand
+ Follow
since Dec 11, 2008
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Robert Garrido

Thanks! It's better now...
10 years ago
Hi all,

I have a file download servlet running on Tomcat, the code is




However once in a while I get an error that prevents files from being downloaded:


DownloadException: java.net.SocketException: Broken pipe
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:366)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:347)
at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:392)
at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:381)
at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:113)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:750)
at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:432)
at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:347)
at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:773)
at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:118)
at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:583)
at org.apache.coyote.Response.doWrite(Response.java:560)
at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:361)
... 23 more

Tomcat connector looks like this:





How can I prevent such an error? Thanks!!!
10 years ago
Hi all,

I installed rrdtool in a Centos 5.5 server , the rrdtool is accessed by a Java program through a socket:

SocketAddress sa = new InetSocketAddress(config.getRrdServiceHost(), config.getRrdServicePort());
Socket socket = new Socket();
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String command = StringUtils.join(new String[]{
"create", rrdFileRel,
"--start", Long.toString(timestamp - config.getStartTimeOffset()),
"--step", "300",
"DS:ds0:" + type + ":900:U:U",
"RRA:AVERAGE:0.5:1:8640",

And the reply is read like this:
out.println(command);
out.flush();
response = in.readLine();

The snippet above works most of the time, but for some reason after some dozens of graphics are generated the RRDTOOL closes unexpectedly the sockets it get invoked through, I already took a TCP-dump and it can observed hot the RRDTOOL is invoked successfully many times but unexpectedly closes the connection:

create file:mycounter13180/stats.mycom.rrd --start 1286986228 --step 300 DS:ds0:ABSOLUTE:900:U:U ...
Reply:
OK u:0.00 s:0.01 r:0.01

But the last invocation fails:
create file:anothercounter13180/stats.mycom.rrd --start 1286986228 --step 300 DS:ds0:ABSOLUTE:900:U:U ...
Reply:
none

Thus, the socket suddenly gets closed.
ERROR 2010-10-13 12:10:39,126 [ ] [stat-runner-1] com.colibria.imps.statistics.service.StatisticsService.run - Failed to read stat from imps nodes
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at sun.nio.cs.StreamDecoder.readBytes(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)


If there's a way to prevent this error from my Java program please let me know.

Thanks in advanced.
solution:

-Djava.rmi.server.hostname=
11 years ago
Hi all,

I know that JMX connections issues are kind of common, however my problem is a bit more complex.

My JMX client gets binded to the remote JMX server, I can see this trace taken with tcpdump:
10.0.0.1 10.0.0.2 RMI JRMI, Version: 2, StreamProtocol

When the client invokes a object, it looks like this:
10.0.0.1 10.0.0.2 RMI JRMI, Call

The remote server responses:
10.0.0.1 10.0.0.2 RMI JRMI, ReturnData
Java Serialization
PV^PV-E?@@I
3H|^N.
npTQwSI*'jsr.javax.management.remote.rmi.RMIServerImpl_Stubpxrjava.rmi.server.RemoteStubepxrjava.rmi.server.RemoteObjectaa3pxpw2
UnicastRef127.0.0.1nW _SI*'x

So, we can see that the communication is established, but the JMX client throws this exception:
java.net.ConnectException: Connection refused
java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:
java.net.ConnectException: Connection refused
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)


So, it seems the server answers, but IMO seems like the stub it returns is wrong, it has 127.0.0.1, Why is not responding the remote server address?
or
Maybe the server responses with the right stub, an stub that the client should allocate locally, but then the client cannot invoke the local stub in 127.0.0.1.

The client runs with this vm options (a Tomcat hosted webapp):
-server
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=13197


These are the server's vmoptions (another Tomcat hosted webapp):
-server
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=13199


Any ideas?
Thanks in advanced.





11 years ago
Hi,

I have an app in a cluster, this cluster has a master node which seizes an internal IP defined in all /etc/hosts file among the members of this cluster, when using the API:

new Socket(remoteHost, port, InetAddress.getByName(masterHostName), mastertPort);

"InetAddress.getByName(masterHostName)" fails and throws the exception:


java.net.SocketException: Invalid argument or cannot assign requested address
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:525)
at java.net.Socket.connect(Socket.java:475)
at java.net.Socket.<init>(Socket.java:372)
at java.net.Socket.<init>(Socket.java:246)



Does anybody why it fails?

Thanks in advanced.
Thanks a lot, that made the trick. However the connection() method is deprecated. Is there another way to get the connection/metadata?

Paul Sturrock wrote:You would need to interogate the database meta data and use a SQL query directly as appropriate.



Any sample about how to do this? I only have the Session to get that metadata.

Cheers
Yes, I do that for every single query. I actually escape the parameters values when they are binded to the org.hibernate.SQLQuery.

My second post was to clarify whay it works different in Oracle and MySql.

However the first question still remains: How can I infer the dialect so I use different escaping in Oracle than MySql.

Thanks!
By the way, I currently do this:

sqlQuery.setParameter(e.getKey(), e.getValue() != null ? e.getValue().replaceAll("_", "\\\\_") : null);
Can you give me an example of what you mean? Please let me know how it would work for the given example.

Thanks
Because I don't want to have special characters like underscore to be read as wildcards but literal characters, ex:

I have this data:

index word
1 stop
2 stap
3 st_p

If I put in my hibernate query "select * from data where word like '%st_p%' "

I only want to get the "st_p" result and not the three of them.

Currently I'm using MySQL, so the query that gets the right result looks like "select * from data where work like '%st\\\\_p%' "

In Oracle it would be "select * from data where work like '%st\\_p%' "

That's why I want to escape especial characters according to dialect.

Thanks!


Hi all,

I need to get the dialect being used in order to make some special characters escape, I need to use different escape technique depending upon the dialect.

For example, for mysql I need to escape underscore like this:

query.replaceAll("_", "\\\\_")

for Oracle and HSQL I need to do like this:

query.replaceAll("_", "\\_")

That's why I need to infer the dialect from the org.hibernate.Session, but I just can't see how to do it with the available JavaDocs.

Thanks a lot!
Hi,

I use the characters directly from the keyboard, and the browser displays question marks and bokes as you said.

Thanks!
12 years ago
JSP