tags:

views:

74

answers:

2

I am developing a server simulator for one of my client application. I am using GlassFish server. I have to simulate a http connection terminate condition in my server application.

Is there a way by which I can explicitly terminate a connection from server side such that client does not receive any response header. Currently I have tried many options like closing the response outputStream. But in every case a http 200 OK message is delivered to the client application. I would like to consume the http-request and do not want to return anything to the client.

I am using a simple conrtroller servlet and had overridden doGet() and doPost() functions.

A: 

Interesting question. Only one reliable way comes to mind: call System#exit(). This will however terminate the entire server. Not sure if this is what you've in mind.

I tried Thread#interrupt() as well in Tomcat, but the HTTP request thread was apparently (however, very reasonable) not implemented accordingly to listen on that after returning from the servlet method and it returned 200.

I tried the deprecated Thread#stop(), but this only returns a 500 with java.lang.ThreadDeath as root cause.

BalusC
I also tried it. I tried Filters as well to stop the response and not pass on the response to the next dochain() method but it still gives 200 response. My whole existing application uses Glassfish, so I m a bit reluctant to go for Jetty but now seems it is the only solution left.
Gagandip
+1  A: 

You're going to have difficulty persuading an appserver to do this, they're designed to be robust.

I suggest taking a look at Jetty, which is an embeddable and highly configurable HTTP/servlet framework which you can use as alternative to the appserver's built-in support. There's a good chance you'll be able to configure it with a customized connection handler, and hopefully perform your specific connection terminations.

skaffman
Yes, Jetty with a custom connection handler is likely the way to go.
BalusC
Thanks for your suggestion Skaffman and BalcusC.
Gagandip