Search in sources :

Example 1 with FilteringObjectInputStream

use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.

the class GetMessagesHandler method constructMessageInfo.

public HashMap constructMessageInfo(SysMessageID sysMsgID, boolean getBody, HashMap destNameType) {
    HashMap h = new HashMap();
    PacketReference pr = getPacketReference(sysMsgID);
    if (pr == null) {
        return null;
    }
    Packet pkt = pr.getPacket();
    if (pkt == null) {
        return null;
    }
    HashMap msgHeaders = pr.getHeaders();
    // Destination d = pr.getDestination();
    String corrID = pkt.getCorrelationID(), errMsg;
    int typeMask = DestType.DEST_TYPE_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()) {
        typeMask = DestType.DEST_TYPE_QUEUE;
    } else {
        typeMask = DestType.DEST_TYPE_TOPIC;
    }
    h.put("DestinationType", Integer.valueOf(typeMask));
    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;
                    logger.log(Logger.WARNING, 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";
                logger.log(Logger.WARNING, errMsg, e);
            }
        }
        h.put("ReplyToDestinationName", replyToDestName);
        if (destFound) {
            if (isQueue) {
                typeMask = DestType.DEST_TYPE_QUEUE;
            } else {
                typeMask = DestType.DEST_TYPE_TOPIC;
            }
            h.put("ReplyToDestinationType", Integer.valueOf(typeMask));
        }
    }
    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));
    byte[] msgBody = null;
    if (getBody) {
        ByteBuffer bb = pr.getPacket().getMessageBodyByteBuffer();
        if (bb != null && bb.hasArray()) {
            msgBody = bb.array();
        }
    }
    if (msgBody != null) {
        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";
                    logger.log(Logger.ERROR, errMsg, e);
                }
                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";
                    logger.log(Logger.ERROR, errMsg, e);
                }
                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";
                    logger.log(Logger.ERROR, errMsg, e);
                }
                break;
            default:
                errMsg = "Unsupported message type for GET_MESSAGES handler: " + packetType;
                logger.log(Logger.ERROR, errMsg);
                break;
        }
    }
    return (h);
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) ByteBuffer(java.nio.ByteBuffer) ByteArrayInputStream(java.io.ByteArrayInputStream) PacketReference(com.sun.messaging.jmq.jmsserver.core.PacketReference) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with FilteringObjectInputStream

use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.

the class FileTxLogImpl method storeTMLogRecord.

/**
 *************************************************************
 * Methods for JMSBridgeStore Interface
 *
 * to be used by imqdbmgr backup/restore JDBC JMSBridge store
 **************************************************************
 */
/**
 * Store a log record
 *
 * @param xid the global XID
 * @param logRecord the log record data for the xid
 * @param name the jmsbridge name
 * @param sync - not used
 * @param logger_ can be null
 * @exception DupKeyException if already exist else Exception on error
 */
@Override
public void storeTMLogRecord(String xid, byte[] logRecord, String name, boolean sync, java.util.logging.Logger logger_) throws DupKeyException, Exception {
    ObjectInputStream ois = new FilteringObjectInputStream(new ByteArrayInputStream(logRecord));
    LogRecord lr = (LogRecord) ois.readObject();
    logGlobalDecision(lr);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream)

Example 3 with FilteringObjectInputStream

use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.

the class JDBCTxLogImpl method getAllLogRecords.

@Override
public List getAllLogRecords() throws Exception {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "jdbcTxLog: get all log records");
    }
    ArrayList<LogRecord> list = new ArrayList<>();
    super.checkClosedAndSetInProgress();
    try {
        List abytes = _store.getTMLogRecordsByName(_jmsbridge, _logger);
        if (abytes == null) {
            return list;
        }
        byte[] data = null;
        Iterator<byte[]> itr = abytes.iterator();
        while (itr.hasNext()) {
            data = itr.next();
            ObjectInputStream ois = new FilteringObjectInputStream(new ByteArrayInputStream(data));
            LogRecord lr = (LogRecord) ois.readObject();
            ois.close();
            list.add(lr);
        }
        return list;
    } finally {
        super.setInProgress(false);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with FilteringObjectInputStream

use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.

the class JDBCTxLogImpl method getLogRecord.

/**
 * @param gxid the GlobalXid
 * @return a copy of LogRecord corresponding gxid or null if not exist
 */
@Override
public LogRecord getLogRecord(GlobalXid gxid) throws Exception {
    String key = gxid.toString();
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "jdbcTxLog: get log record for  xid " + key);
    }
    super.checkClosedAndSetInProgress();
    try {
        byte[] data = _store.getTMLogRecord(key, _jmsbridge, _logger);
        if (data == null) {
            return null;
        }
        ObjectInputStream ois = new FilteringObjectInputStream(new ByteArrayInputStream(data));
        LogRecord lr = (LogRecord) ois.readObject();
        ois.close();
        return lr;
    } finally {
        super.setInProgress(false);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 5 with FilteringObjectInputStream

use of com.sun.messaging.jmq.util.io.FilteringObjectInputStream in project openmq by eclipse-ee4j.

the class PacketProperties method parseProperties.

public static Hashtable parseProperties(InputStream is) throws IOException, ClassNotFoundException {
    DataInputStream dis = new DataInputStream(is);
    int version = dis.readInt();
    if (version != VERSION1) {
        throw new IOException("Unsupported version of properties serialization [" + version + "]");
    }
    int propcnt = dis.readInt();
    Hashtable ht = new Hashtable(propcnt);
    int cnt = 0;
    while (cnt < propcnt) {
        String key = dis.readUTF();
        if (key.length() <= 0) {
            break;
        }
        short type = dis.readShort();
        Object value = null;
        switch(type) {
            case BOOLEAN:
                // value = new Boolean(dis.readBoolean());
                value = Boolean.valueOf(dis.readBoolean());
                break;
            case BYTE:
                value = Byte.valueOf(dis.readByte());
                break;
            case SHORT:
                value = Short.valueOf(dis.readShort());
                break;
            case INTEGER:
                value = Integer.valueOf(dis.readInt());
                break;
            case LONG:
                value = Long.valueOf(dis.readLong());
                break;
            case FLOAT:
                value = Float.valueOf(dis.readFloat());
                break;
            case DOUBLE:
                value = Double.valueOf(dis.readDouble());
                break;
            case STRING:
                value = dis.readUTF();
                break;
            case OBJECT:
                int bytes = dis.readInt();
                byte[] buf = new byte[bytes];
                dis.read(buf, 0, bytes);
                JMQByteArrayInputStream bis = new JMQByteArrayInputStream(buf);
                ObjectInputStream ois = new FilteringObjectInputStream(bis);
                value = ois.readObject();
                ois.close();
                bis.close();
            default:
        }
        ht.put(key, value);
        cnt++;
    }
    return ht;
}
Also used : Hashtable(java.util.Hashtable) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

FilteringObjectInputStream (com.sun.messaging.jmq.util.io.FilteringObjectInputStream)22 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 DataInputStream (java.io.DataInputStream)5 Hashtable (java.util.Hashtable)5 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)2 TransactionWork (com.sun.messaging.jmq.jmsserver.data.TransactionWork)2 JMSException (jakarta.jms.JMSException)2 MessageFormatException (jakarta.jms.MessageFormatException)2 MessageNotWriteableException (jakarta.jms.MessageNotWriteableException)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 UpdateOpaqueDataCallback (com.sun.messaging.bridge.api.UpdateOpaqueDataCallback)1 BranchXid (com.sun.messaging.bridge.service.jms.tx.BranchXid)1 GlobalXid (com.sun.messaging.bridge.service.jms.tx.GlobalXid)1 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)1 ClusterTransaction (com.sun.messaging.jmq.jmsserver.data.ClusterTransaction)1