Author: richard.opalka(a)jboss.com
Date: 2007-12-06 05:29:09 -0500 (Thu, 06 Dec 2007)
New Revision: 5198
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/transport/RMChannelManagerImpl.java
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wsrm/emulator/EndpointEmulator.java
Log:
finalizing WS-RM resending capability
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/transport/RMChannelManagerImpl.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/transport/RMChannelManagerImpl.java 2007-12-05
19:57:58 UTC (rev 5197)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/transport/RMChannelManagerImpl.java 2007-12-06
10:29:09 UTC (rev 5198)
@@ -21,7 +21,9 @@
*/
package org.jboss.ws.extensions.wsrm.transport;
-import java.io.IOException;
+import static org.jboss.ws.extensions.wsrm.RMConstant.REMOTING_INVOCATION_CONTEXT;
+
+import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -30,17 +32,20 @@
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
+import javax.servlet.http.HttpServletResponse;
+
import org.jboss.logging.Logger;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
import org.jboss.ws.extensions.wsrm.api.RMException;
/**
- * WS-RM channel manager ensures message reliable delivery according to sequence
configuration
+ * WS-RM channel manager ensures message reliable delivery according to sequence
retransmission configuration
*
* @author richard.opalka(a)jboss.com
*
* @since Dec 5, 2007
*/
-public final class RMChannelManagerImpl implements Runnable, RMChannelManager
+public final class RMChannelManagerImpl implements RMChannelManager
{
private static final Logger logger = Logger.getLogger(RMChannelManagerImpl.class);
@@ -74,9 +79,7 @@
private RMChannelManagerImpl()
{
- Thread thread = new Thread(this, "RMChannelManager");
- thread.setDaemon(true);
- thread.start();
+ // forbidden inheritance
}
public static final RMChannelManager getInstance()
@@ -84,23 +87,6 @@
return instance;
}
- public final void run()
- {
- while (true)
- {
- logger.debug("checking persistent store for undelivered messages");
- try
- {
- Thread.sleep(10);
- }
- catch (InterruptedException ie)
- {
- logger.warn(ie.getMessage(), ie);
- }
- }
-
- }
-
public final RMMessage send(RMMessage request) throws Throwable
{
RMChannelResponse result = null;
@@ -122,14 +108,26 @@
if (t != null)
{
logger.warn(result.getFault().getClass().getName(),
result.getFault());
- Thread.sleep(timeToWait * 1000);
}
else
{
endTime = System.currentTimeMillis();
+ if (result.getResponse() != null)
+ {
+ Map<String, Object> remotingCtx =
result.getResponse().getMetadata().getContext(REMOTING_INVOCATION_CONTEXT);
+ if (remotingCtx != null)
+ {
+ if
(Integer.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR).equals(remotingCtx.get(HTTPMetadataConstants.RESPONSE_CODE)))
+ {
+ logger.debug("Response message received in " +
(endTime - startTime) + " miliseconds, but contains internal server code, going to
resend the request message");
+ continue;
+ }
+ }
+ }
logger.debug("Response message received in " + (endTime -
startTime) + " miliseconds");
break;
}
+ Thread.sleep(timeToWait * 1000);
}
}
catch (TimeoutException te)
Modified:
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wsrm/emulator/EndpointEmulator.java
===================================================================
---
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wsrm/emulator/EndpointEmulator.java 2007-12-05
19:57:58 UTC (rev 5197)
+++
stack/native/trunk/src/test/java/org/jboss/test/ws/jaxws/wsrm/emulator/EndpointEmulator.java 2007-12-06
10:29:09 UTC (rev 5198)
@@ -58,7 +58,6 @@
private String configFile;
private ServletContext ctx;
private List<View> views;
- private Map<String, Integer> delayedMessages = new HashMap<String,
Integer>();
@Override
public void init(ServletConfig config) throws ServletException
@@ -93,7 +92,6 @@
protected void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
- delayedMessages = new HashMap<String, Integer>();
handleRequest(HTTP_GET, req, res);
}
@@ -132,36 +130,31 @@
}
}
- try
+ boolean returnServerError = HTTP_POST.equalsIgnoreCase(httpMethod) ?
(generator.nextInt(3) % 3 == 1) : false;
+ if (returnServerError)
{
- boolean sleep = generator.nextBoolean();
- if (sleep)
+ resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ ctx.log("returning HTTP code 500");
+ PrintWriter out = resp.getWriter();
+ out.write("<html><body><h1>Internal Server
Error</h1><p>Generated by endpoint emulator for testing
purposes.</p></body></html>");
+ out.flush();
+ out.close();
+ return;
+ }
+
+ boolean delayResponse = HTTP_POST.equalsIgnoreCase(httpMethod) ?
(generator.nextInt(3) % 3 == 1) : false;
+ if (delayResponse)
+ {
+ try
{
- Integer countOfDelayedMessages = this.delayedMessages.get(view.getId());
- if (countOfDelayedMessages == null)
- {
- countOfDelayedMessages = 0;
- }
- if (countOfDelayedMessages.intValue() < 5)
- {
- Thread.sleep(5 * 1000);
- ctx.log("serving request after " + 5 + " seconds");
- this.delayedMessages.put(view.getId(), countOfDelayedMessages.intValue() +
1);
- }
- else
- {
- ctx.log("serving request immediately");
- }
- }
- else
+ ctx.log("delaying response, will be send in 5 seconds");
+ Thread.sleep(5 * 1000);
+ }
+ catch (InterruptedException ie)
{
- ctx.log("serving request immediately");
+ ctx.log(ie.getMessage(), ie);
}
}
- catch (InterruptedException ie)
- {
- ctx.log(ie.getMessage(), ie);
- }
if (responseTo == null)
{
Show replies by date