Search in sources :

Example 81 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class VerifyDestinationHandler method handle.

/**
 * Method to handle Destination (create or delete) messages
 */
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
    int status = Status.OK;
    String reason = null;
    assert msg.getPacketType() == PacketType.VERIFY_DESTINATION;
    Packet pkt = new Packet(con.useDirectBuffers());
    pkt.setConsumerID(msg.getConsumerID());
    pkt.setPacketType(PacketType.VERIFY_DESTINATION_REPLY);
    Hashtable hash = new Hashtable();
    Hashtable props = null;
    String selectorstr = null;
    int type = 0;
    try {
        props = msg.getProperties();
        String destination = (String) props.get("JMQDestination");
        Integer inttype = (Integer) props.get("JMQDestType");
        // destination & type required
        assert destination != null;
        type = (inttype == null) ? 0 : inttype.intValue();
        selectorstr = (String) props.get("JMQSelector");
        if (selectorstr != null) {
            Selector.compile(selectorstr);
        }
        boolean notFound = false;
        DestinationSpi d = null;
        if (DestinationUID.isWildcard(destination)) {
            // retrieve the list of destinations
            pkt.setWildcard(true);
            // see if there are any destinations that match
            DestinationUID duid = DestinationUID.getUID(destination, type);
            List[] ll = coreLifecycle.findMatchingIDs(con.getPartitionedStore(), duid);
            List l = ll[0];
            if (l.isEmpty()) {
                notFound = true;
            }
        } else {
            DestinationSpi[] ds = coreLifecycle.getDestination(con.getPartitionedStore(), destination, DestType.isQueue(type));
            d = ds[0];
            notFound = (d == null);
        }
        if (notFound) {
            // not found
            status = Status.NOT_FOUND;
            reason = "destination not found";
            hash.put("JMQCanCreate", Boolean.valueOf(coreLifecycle.canAutoCreate(DestType.isQueue(type))));
        } else {
            if (d != null) {
                hash.put("JMQDestType", Integer.valueOf(d.getType()));
            }
        }
    } catch (SelectorFormatException ex) {
        reason = ex.getMessage();
        status = Status.BAD_REQUEST;
        logger.log(Logger.WARNING, BrokerResources.W_SELECTOR_PARSE, selectorstr, ex);
    } catch (IOException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination - no properties", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } catch (ClassNotFoundException ex) {
        logger.logStack(Logger.ERROR, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination -bad class", ex);
        reason = ex.getMessage();
        status = Status.ERROR;
    } catch (BrokerException ex) {
        reason = ex.getMessage();
        status = ex.getStatusCode();
        logger.logStack(Logger.DEBUG, BrokerResources.E_INTERNAL_BROKER_ERROR, "Unable to verify destination ", ex);
    } catch (SecurityException ex) {
        reason = ex.getMessage();
        status = Status.FORBIDDEN;
        logger.log(Logger.WARNING, ex.toString(), ex);
    }
    hash.put("JMQStatus", Integer.valueOf(status));
    if (reason != null) {
        hash.put("JMQReason", reason);
    }
    if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
        hash.put("JMQReqID", msg.getSysMessageID().toString());
    }
    pkt.setProperties(hash);
    con.sendControlMessage(pkt);
    return true;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) DestinationSpi(com.sun.messaging.jmq.jmsserver.plugin.spi.DestinationSpi) SelectorFormatException(com.sun.messaging.jmq.util.selector.SelectorFormatException) DestinationUID(com.sun.messaging.jmq.jmsserver.core.DestinationUID)

Example 82 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class Topic method forwardOrphanMessages.

@Override
public void forwardOrphanMessages(Collection refs, ConsumerUID consumer) throws BrokerException {
    BrokerException ex = new BrokerException("INTERNAL ERROR: Unexpected call");
    logger.logStack(Logger.ERROR, ex.getMessage(), ex);
    throw ex;
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 83 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class DestinationManagerConfig method create.

public void create(String type, String name, AttributeList attrs) throws MBeanException {
    DestinationInfo info = DestinationUtil.getDestinationInfoFromAttrs(type, name, attrs);
    try {
        DestinationUtil.checkCreateDestinationAttrs(type, attrs);
        DestinationUtil.createDestination(info);
    } catch (BrokerException e) {
        handleOperationException(DestinationOperations.CREATE, e);
    }
}
Also used : DestinationInfo(com.sun.messaging.jmq.util.admin.DestinationInfo) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 84 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException in project openmq by eclipse-ee4j.

the class MessageManagerConfig method replaceMessage.

public String replaceMessage(String destinationType, String destinationName, String messageID, HashMap messageBody) throws MBeanException {
    String newMsgID = null;
    try {
        if (destinationType == null) {
            throw new BrokerException("Admin replaceMessage: destination name and type not specified", Status.BAD_REQUEST);
        }
        PacketRouter pr = Globals.getPacketRouter(1);
        if (pr == null) {
            throw new BrokerException("Admin deleteMessage: Could not locate Admin Packet Router");
        }
        AdminDataHandler dhd = (AdminDataHandler) pr.getHandler(PacketType.OBJECT_MESSAGE);
        ReplaceMessageHandler hd = (ReplaceMessageHandler) dhd.getHandler(com.sun.messaging.jmq.util.admin.MessageType.REPLACE_MESSAGE);
        newMsgID = hd.replaceMessage(messageID, destinationName, messageBody, destinationType.equals(DestinationType.QUEUE));
    } catch (Exception e) {
        boolean logstack = true;
        if (e instanceof BrokerException) {
            int status = ((BrokerException) e).getStatusCode();
            if (status == Status.NOT_ALLOWED || status == Status.NOT_FOUND || status == Status.CONFLICT || status == Status.BAD_REQUEST) {
                logstack = false;
            }
        }
        Object[] args = { messageID, destinationName, e.getMessage() };
        String emsg = rb.getKString(rb.X_ADMIN_DELETE_MSG, args);
        if (logstack) {
            logger.logStack(Logger.ERROR, emsg, e);
        } else {
            logger.log(Logger.ERROR, emsg, e);
        }
        handleOperationException("replaceMessage", e);
    }
    return (newMsgID);
}
Also used : BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) PacketRouter(com.sun.messaging.jmq.jmsserver.data.PacketRouter) AdminDataHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.AdminDataHandler) ReplaceMessageHandler(com.sun.messaging.jmq.jmsserver.data.handlers.admin.ReplaceMessageHandler) MBeanException(javax.management.MBeanException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 85 with BrokerException

use of com.sun.messaging.jmq.jmsserver.util.BrokerException 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);
}
Also used : Destination(com.sun.messaging.jmq.jmsserver.core.Destination) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) HashMap(java.util.HashMap) Hashtable(java.util.Hashtable) ByteBuffer(java.nio.ByteBuffer) MBeanException(javax.management.MBeanException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) 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)

Aggregations

BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)290 IOException (java.io.IOException)72 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)33 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)31 SizeString (com.sun.messaging.jmq.util.SizeString)31 ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)29 Iterator (java.util.Iterator)26 ArrayList (java.util.ArrayList)25 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)24 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)23 HashMap (java.util.HashMap)22 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)21 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)21 LoadException (com.sun.messaging.jmq.jmsserver.persist.api.LoadException)21 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)18 List (java.util.List)18 Packet (com.sun.messaging.jmq.io.Packet)16 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)16 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 ConsumerAlreadyAddedException (com.sun.messaging.jmq.jmsserver.util.ConsumerAlreadyAddedException)15