use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class PacketUtil method dumpBody.
/**
* Dump the body of the packet.
*
* Note: This method is being refactored from the Packet class so that it can also be used by the old packet code, i.e.
* the client. By doing this, the client doesn't have any dependency on the broker's Packet class.
*/
public static // Stream to dump contents to
void dumpBody(// Stream to dump contents to
PrintStream os, // Type of packet
int pType, // Input stream to body
InputStream is, // Number of bytes in body
int bodySize, // Packet properties
Hashtable props) {
os.print(" Message Body: " + bodySize + " bytes ");
if (is == null) {
os.println();
os.flush();
return;
}
int n;
switch(pType) {
case PacketType.ACKNOWLEDGE:
case PacketType.REDELIVER:
SysMessageID id = new SysMessageID();
n = bodySize / (SysMessageID.ID_SIZE + 8);
// Read acknowledgement blocks out of body of packet
try {
Integer idType = null;
if (props != null) {
idType = (Integer) props.get("JMQBodyType");
}
DataInputStream dis = new DataInputStream(is);
while (n > 0) {
if (idType == null || idType.intValue() == PacketType.CONSUMERID_L_SYSMESSAGEID) {
os.print("[" + dis.readLong() + ":");
} else {
os.print("[" + dis.readInt() + ":");
}
id.readID(dis);
os.print(id + "]");
n--;
}
dis.close();
} catch (Exception e) {
os.println("Exception when reading packet body: " + e);
}
break;
case PacketType.TEXT_MESSAGE:
n = bodySize;
if (n > 40) {
n = 40;
}
byte[] buf = new byte[40];
try {
is.read(buf);
os.print("[" + new String(buf));
if (n < bodySize) {
os.print(". . .");
}
os.print("]");
} catch (IOException e) {
os.println("Exception when reading packet body: " + e);
}
break;
case PacketType.MAP_MESSAGE:
case PacketType.OBJECT_MESSAGE:
try {
ObjectInputStream ois = new FilteringObjectInputStream(is);
Object o = ois.readObject();
String s = o.toString();
if (s.length() > 512) {
os.println(s.substring(0, 512) + ". . .");
} else {
os.println(s);
}
ois.close();
} catch (Exception e) {
os.println("Exception when deserializing packet body: " + e);
}
break;
case PacketType.AUTHENTICATE:
try {
String type = (String) props.get("JMQAuthType");
os.print(type + ": ");
DataInputStream dis = new DataInputStream(is);
if (type.equals("basic")) {
String username = dis.readUTF();
String password = dis.readUTF();
os.print("username=" + username + ", password=" + password);
} else if (type.equals("digest")) {
String username = dis.readUTF();
String password = dis.readUTF();
os.print("username=" + username + ", password=" + password);
} else {
os.print("Unknown authentication type");
}
} catch (Exception e) {
os.println("Exception when reading packet body: " + e);
}
break;
case PacketType.RECOVER_TRANSACTION_REPLY:
try {
JMQXid xid;
Integer quantity = (Integer) props.get("JMQQuantity");
n = 0;
if (quantity != null) {
n = quantity.intValue();
}
DataInputStream dis = new DataInputStream(is);
while (n > 0) {
xid = JMQXid.read(dis);
os.println("[XID=" + xid + "], ");
n--;
}
} catch (IOException e) {
os.println("Could not decode XIDs: " + e);
}
break;
case PacketType.INFO:
try {
ObjectInputStream dis = new FilteringObjectInputStream(is);
Hashtable ht = (Hashtable) dis.readObject();
Iterator itr = ht.entrySet().iterator();
while (itr.hasNext()) {
Map.Entry mEntry = (Map.Entry) itr.next();
Object key = mEntry.getKey();
Object value = mEntry.getValue();
if (value instanceof Hashtable) {
os.println("\tTable: " + key);
Iterator itr1 = ((Hashtable) value).entrySet().iterator();
while (itr1.hasNext()) {
Map.Entry mEntry1 = (Map.Entry) itr1.next();
Object key1 = mEntry1.getKey();
Object value1 = mEntry1.getValue();
os.println("\t\t" + key1 + "=" + value1);
}
} else {
os.println("\t" + key + "=" + value);
}
}
} catch (Exception e) {
os.println("Could not decode INFO packet: " + e);
}
break;
case PacketType.START_TRANSACTION:
case PacketType.COMMIT_TRANSACTION:
case PacketType.ROLLBACK_TRANSACTION:
case PacketType.END_TRANSACTION:
case PacketType.PREPARE_TRANSACTION:
case PacketType.RECOVER_TRANSACTION:
try {
JMQXid xid;
xid = JMQXid.read(new DataInputStream(is));
os.println("[XID=" + xid + "]");
} catch (IOException e) {
os.println("Could not decode XID: " + e);
}
break;
case PacketType.VERIFY_TRANSACTION_REPLY:
try {
ObjectInputStream oos = new FilteringObjectInputStream(is);
Object newo = oos.readObject();
os.println(newo);
} catch (Exception e) {
os.println("Could not decode verify body: " + e);
}
break;
}
os.println();
os.flush();
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class MapMessageImpl method getMessageBodyFromPacket.
// deserialize message body
// This is called after message is received in Session Reader.
@Override
protected void getMessageBodyFromPacket() throws JMSException {
try {
messageBody = getMessageBody();
byteArrayInputStream = new ByteArrayInputStream(messageBody);
objectInputStream = new FilteringObjectInputStream(byteArrayInputStream);
mapMessage = (Map) objectInputStream.readObject();
} catch (Exception e) {
ExceptionHandler.handleException(e, ClientResources.X_MESSAGE_DESERIALIZE);
}
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class MessageTransformer method SOAPMessageFromJMSMessage.
/**
* Extracts a <code>jakarta.xml.soap.SOAPMessage</code> object from the <code>jakarta.jms.Message</code> object into which
* it was transformed using the <code>SOAPMessageIntoJMSMessage</code> method.
*
* The <code>MessageFactory</code> parameter is used to construct the <code>jakarta.xml.soap.SOAPMessage</code> object.
* <p>
* If <code>MessageFactory</code> is <code>null</code> then the default SOAP MessageFactory will be used to construct
* the SOAP message.
*
* @param message The JMS message from which the SOAP message is to be extracted.
* @param messageFactory The SOAP MessageFactory to be used to contruct the SOAP message.
*
* @exception MessageTransformerException If any error is encountered when extracting the message.
*/
public static SOAPMessage SOAPMessageFromJMSMessage(Message message, MessageFactory messageFactory) throws MessageTransformerException {
SOAPMessage soapMessage = null;
BytesMessage bmessage = (BytesMessage) message;
try {
// 1. construct mime header
int mimeLength = bmessage.readInt();
byte[] mbuf = new byte[mimeLength];
bmessage.readBytes(mbuf, mimeLength);
ByteArrayInputStream mbin = new ByteArrayInputStream(mbuf);
ObjectInputStream oi = new FilteringObjectInputStream(mbin);
Hashtable ht = (Hashtable) oi.readObject();
MimeHeaders mimeHeaders = hashtableToMime(ht);
// 2. get soap body stream.
int bodyLength = bmessage.readInt();
byte[] buf = new byte[bodyLength];
bmessage.readBytes(buf, bodyLength);
ByteArrayInputStream bin = new ByteArrayInputStream(buf);
if (messageFactory == null) {
messageFactory = getMessageFactory();
}
// 3. construct soap message object.
soapMessage = messageFactory.createMessage(mimeHeaders, bin);
} catch (Exception e) {
throw new MessageTransformerException(e);
}
return soapMessage;
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class PHashMapMMF method setClientDataMarker.
/**
* Mark starting position of client data for the specified ByteBuffer.
*
* Note: Calling method is responsible for synchronize on VRFile (backing file).
*/
private void setClientDataMarker(ByteBuffer buffer) {
// Try to look for the marker, i.e. "%CD"
for (int i = 0, limit = buffer.limit(); i < limit; i++) {
if (buffer.get(i) == CLIENT_DATA_MARKER[0]) {
// Found '%', so check if the next 2 bytes is "CD"
if ((i + 2) < limit && buffer.get(i + 1) == CLIENT_DATA_MARKER[1] && buffer.get(i + 2) == CLIENT_DATA_MARKER[2]) {
buffer.position(i);
buffer.mark();
// marker has been found and set
return;
}
}
}
// Record doesn't contain client data so just reset the marker at the
// end of the value object; the position where client data should start.
// The crude way to do this is to re-read the key and value object.
Object key = null;
Object value = null;
Throwable kex = null;
Throwable vex = null;
Throwable ex = null;
try {
buffer.position(0);
int limit = buffer.limit();
byte[] data = new byte[limit];
buffer.get(data);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = new FilteringObjectInputStream(bais);
try {
key = ois.readObject();
} catch (Throwable e) {
kex = e;
}
try {
value = ois.readObject();
} catch (Throwable e) {
vex = e;
}
// Mark starting position of client data
if (maxClientDataSize > 0) {
// Since we've already read in the whole buffer we need to
// reset buffer's position back to the start of client data
int pos = limit - bais.available();
buffer.position(pos);
buffer.mark();
}
ois.close();
bais.close();
} catch (IOException e) {
ex = e;
}
if (kex != null || vex != null || ex != null) {
PHashMapLoadException le = new PHashMapLoadException("Failed to set client data marker");
le.setKey(key);
le.setValue(value);
le.setKeyCause(kex);
le.setValueCause(vex);
le.initCause(ex);
throw new RuntimeException(le);
}
}
use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.
the class MessageManagerMonitor method constructMessageInfo.
private HashMap constructMessageInfo(SysMessageID sysMsgID, boolean getBody, HashMap destNameType) throws BrokerException {
HashMap h = new HashMap();
PacketReference pr = getPacketReference(sysMsgID);
Packet pkt = pr.getPacket();
HashMap msgHeaders = pr.getHeaders();
// Destination d = pr.getDestination();
String corrID = pkt.getCorrelationID(), errMsg;
String destType = DestinationType.QUEUE;
byte[] b = null;
h.put("CorrelationID", corrID);
if (corrID != null) {
try {
b = corrID.getBytes("UTF8");
} catch (Exception e) {
}
}
h.put("CorrelationIDAsBytes", b);
h.put("DeliveryMode", (pkt.getPersistent()) ? Integer.valueOf(jakarta.jms.DeliveryMode.PERSISTENT) : Integer.valueOf(jakarta.jms.DeliveryMode.NON_PERSISTENT));
h.put("DestinationName", pkt.getDestination());
if (pkt.getIsQueue()) {
destType = DestinationType.QUEUE;
} else {
destType = DestinationType.TOPIC;
}
h.put("DestinationType", destType);
h.put("Expiration", Long.valueOf(pkt.getExpiration()));
h.put("MessageID", msgHeaders.get("JMSMessageID"));
h.put("Priority", Integer.valueOf(pkt.getPriority()));
h.put("Redelivered", Boolean.valueOf(pkt.getRedelivered()));
/*
* The ReplyTo information in the packet contains the destination name and class name (i.e. dest class name), which the
* broker cannot really use. We need to query/check if: - the destination exists - what it's type is
*/
String replyToDestName = pkt.getReplyTo();
if (replyToDestName != null) {
boolean destFound = false, isQueue = true;
if (destNameType != null) {
Boolean isQ = (Boolean) destNameType.get(replyToDestName);
if (isQ != null) {
isQueue = isQ.booleanValue();
destFound = true;
}
}
if (!destFound) {
try {
Destination topic, queue;
Destination[] ds = DL.findDestination(null, replyToDestName, true);
// PART
queue = ds[0];
ds = DL.findDestination(null, replyToDestName, false);
topic = ds[0];
if ((queue != null) && (topic != null)) {
errMsg = "Cannot determine type of ReplyTo destination." + " There is a topic and queue with the name: " + replyToDestName;
throw new BrokerException(errMsg);
} else if (queue != null) {
destFound = true;
isQueue = true;
} else if (topic != null) {
destFound = true;
isQueue = false;
}
if (destFound) {
/*
* Cache dest name/type so that we can look it up there next time.
*/
destNameType.put(replyToDestName, Boolean.valueOf(isQueue));
} else {
/*
* It is possible that this destination no longer exists. e.g. Temporary destination, whose connection has gone away.
* Not sure how to proceed at this point.
*/
}
} catch (Exception e) {
errMsg = "Caught exception while determining ReplyTo destination type";
throw new BrokerException(errMsg);
}
}
h.put("ReplyToDestinationName", replyToDestName);
if (destFound) {
if (isQueue) {
destType = DestinationType.QUEUE;
} else {
destType = DestinationType.TOPIC;
}
h.put("ReplyToDestinationType", destType);
}
}
h.put("Timestamp", Long.valueOf(pkt.getTimestamp()));
h.put("Type", pkt.getMessageType());
Hashtable msgProps;
try {
msgProps = pr.getProperties();
} catch (Exception e) {
msgProps = null;
}
h.put("MessageProperties", msgProps);
int packetType = pr.getPacket().getPacketType();
h.put("MessageBodyType", Integer.valueOf(packetType));
if (getBody) {
ByteBuffer bb = pr.getPacket().getMessageBodyByteBuffer();
byte[] msgBody = null;
if (bb.hasArray()) {
msgBody = bb.array();
}
switch(packetType) {
case PacketType.TEXT_MESSAGE:
try {
String textMsg = new String(msgBody, "UTF8");
h.put("MessageBody", textMsg);
} catch (Exception e) {
errMsg = "Caught exception while creating text message body";
throw new BrokerException(errMsg);
}
break;
case PacketType.BYTES_MESSAGE:
case PacketType.STREAM_MESSAGE:
h.put("MessageBody", msgBody);
break;
case PacketType.MAP_MESSAGE:
try {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(msgBody);
ObjectInputStream objectInputStream = new FilteringObjectInputStream(byteArrayInputStream);
HashMap mapMsg = (HashMap) objectInputStream.readObject();
h.put("MessageBody", mapMsg);
} catch (Exception e) {
errMsg = "Caught exception while creating map message body";
throw new BrokerException(errMsg);
}
break;
case PacketType.OBJECT_MESSAGE:
try {
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(msgBody);
ObjectInputStream objectInputStream = new FilteringObjectInputStream(byteArrayInputStream);
Object objMsg = objectInputStream.readObject();
h.put("MessageBody", objMsg);
} catch (Exception e) {
errMsg = "Caught exception while creating object message body";
throw new BrokerException(errMsg);
}
break;
default:
errMsg = "Unsupported message type for GET_MESSAGES handler: " + packetType;
throw new BrokerException(errMsg);
}
}
return (h);
}
Aggregations