FileDocCategorySizeDatePackage
SimpleJMSWorker.javaAPI DocApache Axis 1.44542Sat Apr 22 18:57:28 BST 2006org.apache.axis.transport.jms

SimpleJMSWorker

public class SimpleJMSWorker extends Object implements Runnable
SimpleJMSWorker is a worker thread that processes messages that are received by SimpleJMSListener. It creates a new message context, invokes the server, and sends back response msg to the replyTo destination.
author
Jaime Meritt (jmeritt@sonicsoftware.com)
author
Richard Chung (rchung@sonicsoftware.com)
author
Dave Chappell (chappell@sonicsoftware.com)

Fields Summary
protected static Log
log
SimpleJMSListener
listener
javax.jms.BytesMessage
message
Constructors Summary
public SimpleJMSWorker(SimpleJMSListener listener, javax.jms.BytesMessage message)


        
    
        this.listener = listener;
        this.message = message;
    
Methods Summary
public voidrun()
This is where the incoming message is processed.

        InputStream in = null;
        try
        {
            // get the incoming msg content into a byte array
            byte[] buffer = new byte[8 * 1024];
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            for(int bytesRead = message.readBytes(buffer);
                bytesRead != -1; bytesRead = message.readBytes(buffer))
            {
                out.write(buffer, 0, bytesRead);
            }
            in = new ByteArrayInputStream(out.toByteArray());
        }
        catch(Exception e)
        {
            log.error(Messages.getMessage("exception00"), e);
            e.printStackTrace();
            return;
        }

        // create the msg and context and invoke the server
        AxisServer server = SimpleJMSListener.getAxisServer();

        // if the incoming message has a contentType set,
        // pass it to my new Message
        String contentType = null;
        try 
        { 
            contentType = message.getStringProperty("contentType");
        } 
        catch(Exception e) 
        { 
            e.printStackTrace();
        }

        Message msg = null;
        if(contentType != null && !contentType.trim().equals("")) 
        {
            msg = new Message(in, true, contentType, null);
        } 
        else 
        {
            msg = new Message(in);
        }

        MessageContext  msgContext = new MessageContext(server);
        msgContext.setRequestMessage( msg );
        try
        {
            server.invoke( msgContext );
            msg = msgContext.getResponseMessage();
        }
        catch (AxisFault af)
        {
            msg = new Message(af);
            msg.setMessageContext(msgContext);
        }
        catch (Exception e)
        {
            msg = new Message(new AxisFault(e.toString()));
            msg.setMessageContext(msgContext);
        }

        try
        {
            // now we need to send the response
            Destination destination = message.getJMSReplyTo();
            if(destination == null)
                return;
            JMSEndpoint replyTo = listener.getConnector().createEndpoint(destination);
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            msg.writeTo(out);
            replyTo.send(out.toByteArray());
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

        if (msgContext.getProperty(MessageContext.QUIT_REQUESTED) != null)
            // why then, quit!
            try {listener.shutdown();} catch (Exception e) {}