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) {}