Author: richard.opalka(a)jboss.com
Date: 2007-11-21 12:21:30 -0500 (Wed, 21 Nov 2007)
New Revision: 5097
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandler.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandlerFactory.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMCallbackHandler.java
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/core/MessageTrace.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelRequest.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelResponse.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMClientHandler.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMConstant.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMHelper.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsInvocationHandler.java
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsServer.java
Log:
sync prototype with SVN - now all tests are passing through back channel as well
Modified: stack/native/trunk/src/main/java/org/jboss/ws/core/MessageTrace.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/core/MessageTrace.java 2007-11-21
17:19:55 UTC (rev 5096)
+++ stack/native/trunk/src/main/java/org/jboss/ws/core/MessageTrace.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -77,7 +77,7 @@
}
else if (message instanceof byte[])
{
- msgLog.trace(messagePrefix + "\n" + String.valueOf((byte[])message));
+ msgLog.trace(messagePrefix + "\n" + new String((byte[])message));
}
else
{
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelRequest.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelRequest.java 2007-11-21
17:19:55 UTC (rev 5096)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelRequest.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -32,8 +32,14 @@
import org.jboss.logging.Logger;
import org.jboss.remoting.Client;
import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.callback.Callback;
+import org.jboss.remoting.callback.HandleCallbackException;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.ws.core.MessageTrace;
+import org.jboss.ws.extensions.wsrm.backchannel.CallbackHandler;
+import org.jboss.ws.extensions.wsrm.backchannel.CallbackHandlerFactory;
import org.jboss.ws.extensions.wsrm.backchannel.RMBackPortsServer;
+import org.jboss.ws.extensions.wsrm.backchannel.RMCallbackHandler;
import org.jboss.ws.extensions.wsrm.spi.Provider;
import org.jboss.ws.extensions.wsrm.spi.protocol.CreateSequence;
import org.jboss.ws.extensions.wsrm.spi.protocol.Serializable;
@@ -43,7 +49,7 @@
* @see org.jboss.ws.extensions.wsrm.RMChannel
* @author richard.opalka(a)jboss.com
*/
-final class RMChannelRequest implements Callable<RMChannelResponse>
+public final class RMChannelRequest implements Callable<RMChannelResponse>
{
private static final Logger log = Logger.getLogger(RMChannelRequest.class);
private static final String JBOSSWS_SUBSYSTEM = "jbossws";
@@ -55,6 +61,15 @@
this.rmRequest = rmRequest;
}
+
+
+ public void handleCallback(Callback callback)
+ throws HandleCallbackException
+ {
+ System.out.println("Handling callback: " + callback);
+ // TODO: implement this method
+ }
+
public RMChannelResponse call()
{
InvokerLocator locator = null;
@@ -75,14 +90,19 @@
client.setMarshaller(RMMarshaller.getInstance());
URI backPort = RMHelper.getBackPortURI(rmRequest);
+ String messageId = RMHelper.getMessageId(rmRequest);
+
System.out.println("[WS-RM] backport URI is: " + backPort);
+ CallbackHandler callbackHandler = null;
+ // TODO: we should remember WSA:MessageId here too
if (backPort != null)
{
- RMBackPortsServer backPortsServer =
RMBackPortsServer.getInstance(backPort.getScheme(), backPort.getHost(),
backPort.getPort());
- //backPortsServer.registerCallback(backPort.getPath(), this);
+ callbackHandler = CallbackHandlerFactory.getCallbackHandler(backPort);
+ // TODO: callback must unregister itself
+ // TODO: you must call unregister callback as well
}
- boolean oneWay = RMHelper.isOneWayOperation(rmRequest);
+ boolean oneWay = RMHelper.isOneWayOperation(rmRequest) && (backPort ==
null); // TODO: backport support
if (!oneWay)
client.setUnMarshaller(RMUnMarshaller.getInstance());
@@ -109,6 +129,11 @@
// trace the incomming response message
if (rmResponse != null)
MessageTrace.traceMessage("Incoming RM Response Message",
rmResponse.getPayload());
+
+ if (backPort != null) // TODO: backport support
+ {
+ return new RMChannelResponse(callbackHandler, messageId);
+ }
return new RMChannelResponse(rmResponse);
}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelResponse.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelResponse.java 2007-11-21
17:19:55 UTC (rev 5096)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMChannelResponse.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -21,6 +21,8 @@
*/
package org.jboss.ws.extensions.wsrm;
+import org.jboss.ws.extensions.wsrm.backchannel.CallbackHandler;
+
/**
* Represents response that goes from the RM channel
* @see org.jboss.ws.extensions.wsrm.RMChannel
@@ -30,31 +32,40 @@
{
private final Throwable fault;
private final RMMessage result;
+ private final CallbackHandler callback;
+ private final String messageId; // WS-Addressing: MessageID
+ public RMChannelResponse(CallbackHandler callback, String messageId)
+ {
+ this(null, null, callback, messageId);
+ }
+
public RMChannelResponse(Throwable fault)
{
- this(null, fault);
+ this(null, fault, null, null);
}
public RMChannelResponse(RMMessage result)
{
- this(result, null);
+ this(result, null, null, null);
}
- private RMChannelResponse(RMMessage result, Throwable fault)
+ private RMChannelResponse(RMMessage result, Throwable fault, CallbackHandler callback,
String messageId)
{
super();
this.result = result;
this.fault = fault;
+ this.callback = callback;
+ this.messageId = messageId;
}
public Throwable getFault()
{
- return this.fault;
+ return (this.callback != null) ? this.callback.getFault(this.messageId) :
this.fault;
}
public RMMessage getResponse()
{
- return this.result;
+ return (this.callback != null) ? this.callback.getMessage(this.messageId) :
this.result;
}
}
\ No newline at end of file
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMClientHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMClientHandler.java 2007-11-21
17:19:55 UTC (rev 5096)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMClientHandler.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -90,6 +90,7 @@
SOAPAddressingProperties addrProps =
(SOAPAddressingProperties)commonMsgContext.get(JAXWSAConstants.CLIENT_ADDRESSING_PROPERTIES_OUTBOUND);
Map rmRequestContext = (Map)commonMsgContext.get(RMConstant.REQUEST_CONTEXT);
QName operation = (QName)rmRequestContext.get(RMConstant.OPERATION_QNAME);
+ rmRequestContext.put(RMConstant.WSA_MESSAGE_ID,
addrProps.getMessageID().getURI().toString());
if (addrProps != null)
{
SOAPMessage soapMessage = ((SOAPMessageContext)commonMsgContext).getMessage();
Modified: stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMConstant.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMConstant.java 2007-11-21
17:19:55 UTC (rev 5096)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMConstant.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -34,6 +34,7 @@
public static final List<QName> PROTOCOL_OPERATION_QNAMES;
public static final String WSA_ANONYMOUS_URI =
AddressingBuilder.getAddressingBuilder().newAddressingConstants().getAnonymousURI();
+ public static final String WSA_MESSAGE_ID = PREFIX + ".wsaMessageId";
static
{
Modified: stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMHelper.java
===================================================================
--- stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMHelper.java 2007-11-21
17:19:55 UTC (rev 5096)
+++ stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/RMHelper.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -24,6 +24,16 @@
return (ctx != null) && (ctx.containsKey(RMConstant.REQUEST_CONTEXT));
}
+ public static String getMessageId(RMMessage rmRequest)
+ {
+ Map<String, Object> invocationCtx = (Map<String,
Object>)rmRequest.getMetadata().getContext(INVOCATION_CONTEXT);
+ Map<String, Object> wsrmRequestCtx = (Map<String,
Object>)invocationCtx.get(REQUEST_CONTEXT);
+ String retVal = (String)wsrmRequestCtx.get(WSA_MESSAGE_ID);
+ if (retVal == null)
+ throw new RuntimeException();
+ return retVal;
+ }
+
public static URI getBackPortURI(RMMessage rmRequest)
{
Map<String, Object> invocationCtx = (Map<String,
Object>)rmRequest.getMetadata().getContext(INVOCATION_CONTEXT);
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandler.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandler.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.wsrm.backchannel;
+
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.ws.extensions.wsrm.RMMessage;
+
+/**
+ * TODO: Add comment
+ *
+ * @author richard.opalka(a)jboss.com
+ *
+ * @since Nov 21, 2007
+ */
+public interface CallbackHandler
+{
+ String getHandledPath();
+ void handle(InvocationRequest payload);
+ RMMessage getMessage(String messageId);
+ Throwable getFault(String messageId);
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandlerFactory.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandlerFactory.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandlerFactory.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.wsrm.backchannel;
+
+import java.net.URI;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * Callback factory
+ *
+ * @author richard.opalka(a)jboss.com
+ *
+ * @since Nov 21, 2007
+ */
+public final class CallbackHandlerFactory
+{
+ private static RMBackPortsServer server;
+ private static Lock lock = new ReentrantLock();
+
+ private CallbackHandlerFactory()
+ {
+ // no instances
+ }
+
+ public static CallbackHandler getCallbackHandler(URI backPort)
+ {
+ lock.lock();
+ try
+ {
+ if (server == null)
+ {
+ server = RMBackPortsServer.getInstance(backPort.getScheme(),
backPort.getHost(), backPort.getPort());
+ }
+ CallbackHandler callbackHandler = server.getCallback(backPort.getPath());
+ if (callbackHandler == null)
+ {
+ callbackHandler = new RMCallbackHandler(backPort.getPath());
+ server.registerCallback(callbackHandler);
+ }
+
+ return callbackHandler;
+ }
+ finally
+ {
+ lock.unlock();
+ }
+ }
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/CallbackHandlerFactory.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsInvocationHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsInvocationHandler.java 2007-11-21
17:19:55 UTC (rev 5096)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsInvocationHandler.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -21,14 +21,21 @@
*/
package org.jboss.ws.extensions.wsrm.backchannel;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
import javax.management.MBeanServer;
+import org.jboss.logging.Logger;
import org.jboss.remoting.InvocationRequest;
import org.jboss.remoting.ServerInvocationHandler;
import org.jboss.remoting.ServerInvoker;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.transport.coyote.RequestMap;
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+import org.jboss.ws.extensions.wsrm.client_api.RMException;
/**
* TODO: Add comment
@@ -39,46 +46,106 @@
*/
public final class RMBackPortsInvocationHandler implements ServerInvocationHandler
{
+ private static final Logger LOG =
Logger.getLogger(RMBackPortsInvocationHandler.class);
+ private final List<CallbackHandler> callbacks = new
LinkedList<CallbackHandler>();
+ private final Lock lock = new ReentrantLock();
+
public RMBackPortsInvocationHandler()
{
-
}
+
+ public CallbackHandler getCallback(String requestPath)
+ {
+ this.lock.lock();
+ try
+ {
+ for (CallbackHandler handler : this.callbacks)
+ {
+ if (handler.getHandledPath().equals(requestPath))
+ return handler;
+ }
+ }
+ finally
+ {
+ this.lock.unlock();
+ }
- public void addListener(InvokerCallbackHandler arg0)
+ return null;
+ }
+
+ public void registerCallback(CallbackHandler callbackHandler)
{
- // TODO Auto-generated method stub
-
+ this.lock.lock();
+ try
+ {
+ this.callbacks.add(callbackHandler);
+ }
+ finally
+ {
+ this.lock.unlock();
+ }
}
- public Object invoke(InvocationRequest arg0) throws Throwable
+ public void unregisterCallback(CallbackHandler callbackHandler)
{
- RequestMap rm = (RequestMap)arg0.getRequestPayload();
- System.out.println("... locator ..." + arg0.getLocator());
- System.out.println("... subsystem ..." + arg0.getSubsystem());
- System.out.println("... parameter ..." + arg0.getParameter());
- System.out.println("... parameter ..." +
arg0.getParameter().getClass().getName());
- System.out.println("... method ..." +
rm.get(HTTPMetadataConstants.METHODTYPE));
- System.out.println("... path ..." + rm.get(HTTPMetadataConstants.PATH));
- System.out.println("return ..." + arg0.getReturnPayload());
- return null;
+ this.lock.lock();
+ try
+ {
+ this.callbacks.remove(callbackHandler);
+ }
+ finally
+ {
+ this.lock.unlock();
+ }
}
- public void removeListener(InvokerCallbackHandler arg0)
+ public Object invoke(InvocationRequest request) throws Throwable
{
- // TODO Auto-generated method stub
-
+ this.lock.lock();
+ try
+ {
+ RequestMap rm = (RequestMap)request.getRequestPayload();
+ String requestPath = (String)rm.get(HTTPMetadataConstants.PATH);
+ boolean handlerExists = false;
+ for (CallbackHandler handler : this.callbacks)
+ {
+ if (handler.getHandledPath().equals(requestPath))
+ {
+ handlerExists = true;
+ LOG.debug("Handling request path: " + requestPath);
+ handler.handle(request);
+ break;
+ }
+ }
+ if (handlerExists == false)
+ LOG.warn("No callback handler registered for path: " +
requestPath);
+
+ return null;
+ }
+ finally
+ {
+ this.lock.unlock();
+ }
}
+ public void addListener(InvokerCallbackHandler callbackHandler)
+ {
+ // do nothing - we're using custom callback handlers
+ }
+
+ public void removeListener(InvokerCallbackHandler callbackHandler)
+ {
+ // do nothing - we're using custom callback handlers
+ }
+
public void setInvoker(ServerInvoker arg0)
{
- // TODO Auto-generated method stub
-
+ // do nothing
}
public void setMBeanServer(MBeanServer arg0)
{
- // TODO Auto-generated method stub
-
+ // do nothing
}
}
Modified:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsServer.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsServer.java 2007-11-21
17:19:55 UTC (rev 5096)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMBackPortsServer.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -26,6 +26,7 @@
import org.jboss.logging.Logger;
import org.jboss.remoting.InvokerLocator;
+import org.jboss.remoting.callback.InvokerCallbackHandler;
import org.jboss.remoting.transport.Connector;
import org.jboss.ws.extensions.wsrm.client_api.RMException;
@@ -48,10 +49,26 @@
private final String scheme;
private final String host;
private final int port;
+ private RMBackPortsInvocationHandler handler;
private boolean started;
private boolean stopped;
private boolean terminated;
+ public final void registerCallback(CallbackHandler callbackHandler)
+ {
+ this.handler.registerCallback(callbackHandler);
+ }
+
+ public final void unregisterCallback(CallbackHandler callbackHandler)
+ {
+ this.handler.unregisterCallback(callbackHandler);
+ }
+
+ public final CallbackHandler getCallback(String requestPath)
+ {
+ return this.handler.getCallback(requestPath);
+ }
+
private RMBackPortsServer(String scheme, String host, int port)
throws RMException
{
@@ -62,13 +79,13 @@
try
{
InvokerLocator il = new InvokerLocator(this.scheme + "://" + this.host
+ ":" + this.port);
- connector = new Connector();
- connector.setInvokerLocator(il.getLocatorURI());
- connector.create();
+ this.connector = new Connector();
+ this.connector.setInvokerLocator(il.getLocatorURI());
+ this.connector.create();
- RMBackPortsInvocationHandler handler = new RMBackPortsInvocationHandler();
- connector.addInvocationHandler("wsrmBackPortsHandler", handler);
- connector.start();
+ this.handler = new RMBackPortsInvocationHandler();
+ this.connector.addInvocationHandler("wsrmBackPortsHandler",
this.handler);
+ this.connector.start();
LOG.debug("WS-RM Backports Server started on: " +
il.getLocatorURI());
}
catch (Exception e)
Added:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMCallbackHandler.java
===================================================================
---
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMCallbackHandler.java
(rev 0)
+++
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMCallbackHandler.java 2007-11-21
17:21:30 UTC (rev 5097)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.ws.extensions.wsrm.backchannel;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.logging.Logger;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.ws.core.MessageTrace;
+import org.jboss.ws.extensions.wsrm.RMChannelRequest;
+import org.jboss.ws.extensions.wsrm.RMMessage;
+import org.jboss.ws.extensions.wsrm.RMMessageFactory;
+import org.jboss.ws.extensions.wsrm.RMMetadata;
+
+/**
+ * TODO: Add comment
+ *
+ * @author richard.opalka(a)jboss.com
+ *
+ * @since Nov 21, 2007
+ */
+public final class RMCallbackHandler implements CallbackHandler
+{
+ private static final Logger LOG = Logger.getLogger(RMCallbackHandler.class);
+ private final String handledPath;
+ private final Object instanceLock = new Object();
+ private Map<String, RMMessage> arrivedMessages = new HashMap<String,
RMMessage>();
+
+ public RMCallbackHandler(String handledPath)
+ {
+ super();
+ this.handledPath = handledPath;
+ }
+
+ public Throwable getFault(String messageId)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public final String getHandledPath()
+ {
+ return this.handledPath;
+ }
+
+ public final void handle(InvocationRequest request)
+ {
+ String requestMessage = (String)request.getParameter();
+ System.out.println("=================================================");
+ System.out.println("4 - " + request.getRequestPayload());
+ System.out.println("5 - " + request.getReturnPayload());
+ synchronized (instanceLock)
+ {
+ LOG.debug("Setting response object");
+ MessageTrace.traceMessage("Incoming RM Response Message",
requestMessage.getBytes());
+ String startPattern = "<wsa:RelatesTo>"; // TODO: remove this
with XML content inspection
+ String endPattern = "</wsa:RelatesTo>";
+ int begin = requestMessage.indexOf(startPattern) + startPattern.length();
+ int end = requestMessage.indexOf(endPattern);
+ String messageId = requestMessage.substring(begin, end);
+ RMMessage message = RMMessageFactory.newMessage(requestMessage.getBytes(), new
RMMetadata(new java.util.HashMap<String, Object>())); // TODO create map metadata
+ System.out.println("Arrived message id: " + messageId);
+ System.out.println("Message content is: " + requestMessage);
+ this.arrivedMessages.put(messageId, message);
+ System.out.println("Response object is null? -> " + (message ==
null));
+
System.out.println("=================================================");
+ }
+ }
+
+ public RMMessage getMessage(String messageId)
+ {
+ synchronized (instanceLock)
+ {
+ while (this.arrivedMessages.get(messageId) == null)
+ {
+ try
+ {
+ LOG.debug("waiting for response object associated with message id:
" + messageId);
+ instanceLock.wait(100);
+ }
+ catch (InterruptedException ignore)
+ {
+ // TODO: never ignore exceptions - LOG it using logger
+ }
+ }
+ return this.arrivedMessages.get(messageId);
+ }
+ }
+
+}
Property changes on:
stack/native/trunk/src/main/java/org/jboss/ws/extensions/wsrm/backchannel/RMCallbackHandler.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF