Example usage for javax.jms JMSException JMSException

List of usage examples for javax.jms JMSException JMSException

Introduction

In this page you can find the example usage for javax.jms JMSException JMSException.

Prototype

public JMSException(String reason) 

Source Link

Document

Constructs a JMSException with the specified reason and with the error code defaulting to null.

Usage

From source file:org.apache.activemq.blob.FTPBlobDownloadStrategy.java

public void deleteFile(ActiveMQBlobMessage message) throws IOException, JMSException {
    url = message.getURL();/*from  ww  w . jav  a 2s . co  m*/
    final FTPClient ftp = createFTP();

    String path = url.getPath();
    try {
        if (!ftp.deleteFile(path)) {
            throw new JMSException("Delete file failed: " + ftp.getReplyString());
        }
    } finally {
        ftp.quit();
        ftp.disconnect();
    }

}

From source file:org.apache.activemq.blob.FTPBlobUploadStrategy.java

@Override
public URL uploadStream(ActiveMQBlobMessage message, InputStream in) throws JMSException, IOException {

    FTPClient ftp = createFTP();//from  w  ww. ja va  2 s.c om
    try {
        String path = url.getPath();
        String workingDir = path.substring(0, path.lastIndexOf("/"));
        String filename = message.getMessageId().toString().replaceAll(":", "_");
        ftp.setFileType(FTPClient.BINARY_FILE_TYPE);

        String url;
        if (!ftp.changeWorkingDirectory(workingDir)) {
            url = this.url.toString().replaceFirst(this.url.getPath(), "") + "/";
        } else {
            url = this.url.toString();
        }

        if (!ftp.storeFile(filename, in)) {
            throw new JMSException("FTP store failed: " + ftp.getReplyString());
        }
        return new URL(url + filename);
    } finally {
        ftp.quit();
        ftp.disconnect();
    }

}

From source file:org.apache.activemq.blob.FTPStrategy.java

protected FTPClient createFTP() throws IOException, JMSException {
    String connectUrl = url.getHost();
    setUserInformation(url.getUserInfo());
    int port = url.getPort() < 1 ? 21 : url.getPort();

    FTPClient ftp = new FTPClient();
    try {//from  www. j  a  va  2 s. c  o m
        ftp.connect(connectUrl, port);
    } catch (ConnectException e) {
        throw new JMSException("Problem connecting the FTP-server");
    }
    if (!ftp.login(ftpUser, ftpPass)) {
        ftp.quit();
        ftp.disconnect();
        throw new JMSException("Cant Authentificate to FTP-Server");
    }
    return ftp;
}

From source file:org.apache.activemq.jms.pool.PooledConnectionFactory.java

private JMSException createJmsException(String msg, Exception cause) {
    JMSException exception = new JMSException(msg);
    exception.setLinkedException(cause);
    exception.initCause(cause);//from  www. ja v  a2 s.c  om
    return exception;
}

From source file:org.apache.axis2.transport.jms.JMSSender.java

/**
 * Create a JMS Message from the given MessageContext and using the given
 * session/*w  w w  .j  ava 2s.  c om*/
 *
 * @param msgContext the MessageContext
 * @param session    the JMS session
 * @param contentTypeProperty the message property to be used to store the
 *                            content type
 * @return a JMS message from the context and session
 * @throws JMSException on exception
 * @throws AxisFault on exception
 */
private Message createJMSMessage(MessageContext msgContext, Session session, String contentTypeProperty)
        throws JMSException, AxisFault {

    Message message = null;
    String msgType = getProperty(msgContext, JMSConstants.JMS_MESSAGE_TYPE);

    // check the first element of the SOAP body, do we have content wrapped using the
    // default wrapper elements for binary (BaseConstants.DEFAULT_BINARY_WRAPPER) or
    // text (BaseConstants.DEFAULT_TEXT_WRAPPER) ? If so, do not create SOAP messages
    // for JMS but just get the payload in its native format
    String jmsPayloadType = guessMessageType(msgContext);

    if (jmsPayloadType == null) {

        OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext);
        MessageFormatter messageFormatter = null;
        try {
            messageFormatter = TransportUtils.getMessageFormatter(msgContext);
        } catch (AxisFault axisFault) {
            throw new JMSException("Unable to get the message formatter to use");
        }

        String contentType = messageFormatter.getContentType(msgContext, format, msgContext.getSoapAction());

        boolean useBytesMessage = msgType != null && JMSConstants.JMS_BYTE_MESSAGE.equals(msgType)
                || contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1;

        OutputStream out;
        StringWriter sw;
        if (useBytesMessage) {
            BytesMessage bytesMsg = session.createBytesMessage();
            sw = null;
            out = new BytesMessageOutputStream(bytesMsg);
            message = bytesMsg;
        } else {
            sw = new StringWriter();
            try {
                out = new WriterOutputStream(sw, format.getCharSetEncoding());
            } catch (UnsupportedCharsetException ex) {
                handleException("Unsupported encoding " + format.getCharSetEncoding(), ex);
                return null;
            }
        }

        try {
            messageFormatter.writeTo(msgContext, format, out, true);
            out.close();
        } catch (IOException e) {
            handleException("IO Error while creating BytesMessage", e);
        }

        if (!useBytesMessage) {
            TextMessage txtMsg = session.createTextMessage();
            txtMsg.setText(sw.toString());
            message = txtMsg;
        }

        if (contentTypeProperty != null) {
            message.setStringProperty(contentTypeProperty, contentType);
        }

    } else if (JMSConstants.JMS_BYTE_MESSAGE.equals(jmsPayloadType)) {
        message = session.createBytesMessage();
        BytesMessage bytesMsg = (BytesMessage) message;
        OMElement wrapper = msgContext.getEnvelope().getBody()
                .getFirstChildWithName(BaseConstants.DEFAULT_BINARY_WRAPPER);
        OMNode omNode = wrapper.getFirstOMChild();
        if (omNode != null && omNode instanceof OMText) {
            Object dh = ((OMText) omNode).getDataHandler();
            if (dh != null && dh instanceof DataHandler) {
                try {
                    ((DataHandler) dh).writeTo(new BytesMessageOutputStream(bytesMsg));
                } catch (IOException e) {
                    handleException("Error serializing binary content of element : "
                            + BaseConstants.DEFAULT_BINARY_WRAPPER, e);
                }
            }
        }

    } else if (JMSConstants.JMS_TEXT_MESSAGE.equals(jmsPayloadType)) {
        message = session.createTextMessage();
        TextMessage txtMsg = (TextMessage) message;
        txtMsg.setText(msgContext.getEnvelope().getBody()
                .getFirstChildWithName(BaseConstants.DEFAULT_TEXT_WRAPPER).getText());
    }

    // set the JMS correlation ID if specified
    String correlationId = getProperty(msgContext, JMSConstants.JMS_COORELATION_ID);
    if (correlationId == null && msgContext.getRelatesTo() != null) {
        correlationId = msgContext.getRelatesTo().getValue();
    }

    if (correlationId != null) {
        message.setJMSCorrelationID(correlationId);
    }

    if (msgContext.isServerSide()) {
        // set SOAP Action as a property on the JMS message
        setProperty(message, msgContext, BaseConstants.SOAPACTION);
    } else {
        String action = msgContext.getOptions().getAction();
        if (action != null) {
            message.setStringProperty(BaseConstants.SOAPACTION, action);
        }
    }

    JMSUtils.setTransportHeaders(msgContext, message);
    return message;
}

From source file:org.apache.cactus.internal.server.MessageDrivenBeanTestController.java

/**
 * This method is supposed to handle the request from the Redirector.
 * //www.j  a v a  2s  .  co  m
 * @param theObjects for the request
 * @throws JMSException in case an error occurs
 */
public void handleRequest(ImplicitObjects theObjects) throws JMSException {
    MessageDrivenBeanImplicitObjects mdbImplicitObjects = (MessageDrivenBeanImplicitObjects) theObjects;

    // If the Cactus user has forgotten to put a needed jar on the server
    // classpath (i.e. in WEB-INF/lib), then the servlet engine Webapp
    // class loader will throw a NoClassDefFoundError exception. As this
    // method is the entry point of the webapp, we'll catch all
    // NoClassDefFoundError exceptions and report a nice error message
    // for the user so that he knows he has forgotten to put a jar in the
    // classpath. If we don't do this, the error will be trapped by the
    // container and may not result in an ... err ... understandable error
    // message (like in Tomcat) ...
    try {
        String serviceName = getServiceName(mdbImplicitObjects.getMessage());

        MessageDrivenBeanTestCaller caller = getTestCaller(mdbImplicitObjects);

        // TODO: will need a factory here real soon...

        ServiceEnumeration service = ServiceEnumeration.valueOf(serviceName);

        // Is it the call test method service ?
        if (service == ServiceEnumeration.CALL_TEST_SERVICE) {
            caller.doTest();
        }
        // Is it the get test results service ?
        else if (service == ServiceEnumeration.GET_RESULTS_SERVICE) {
            caller.doGetResults();
        }
        // Is it the test connection service ?
        // This service is only used to verify that connection between
        // client and server is working fine
        else if (service == ServiceEnumeration.RUN_TEST_SERVICE) {
            caller.doRunTest();
        }
        // Is it the service to create an HTTP session?
        else if (service == ServiceEnumeration.CREATE_SESSION_SERVICE) {
            caller.doCreateSession();
        } else if (service == ServiceEnumeration.GET_VERSION_SERVICE) {
            caller.doGetVersion();
        } else {
            String message = "Unknown service [" + serviceName + "] in HTTP request.";

            LOGGER.error(message);
            throw new JMSException(message);
        }
    } catch (NoClassDefFoundError e) {
        // try to display messages as descriptive as possible !
        if (e.getMessage().startsWith("junit/framework")) {
            String message = "You must put the JUnit jar in "
                    + "your server classpath (in WEB-INF/lib for example)";

            LOGGER.error(message, e);
            throw new JMSException(message);
        } else {
            String message = "You are missing a jar in your " + "classpath (class [" + e.getMessage()
                    + "] could not " + "be found";

            LOGGER.error(message, e);
            throw new JMSException(message);
        }
    }
}

From source file:org.apache.cactus.internal.server.MessageDrivenBeanTestController.java

/**
 * @param theRequest the JMS message/*from   ww  w  .  ja v  a 2  s .  co m*/
 * @return the service name of the service to call (there are 2 services
 *         "do test" and "get results"), extracted from the JMS message
 * @exception JMSException if the service to execute is missing from
 *            the JMS message
 */
private String getServiceName(Message theRequest) throws JMSException {
    // Call the correct Service method
    String serviceName = theRequest.getStringProperty(HttpServiceDefinition.SERVICE_NAME_PARAM);

    //String serviceName = ServletUtil.getQueryStringParameter(queueName, 
    //    HttpServiceDefinition.SERVICE_NAME_PARAM);

    if (serviceName == null) {
        String message = "Missing service name parameter [" + HttpServiceDefinition.SERVICE_NAME_PARAM
                + "] in HTTP request. Received query string is [" + serviceName + "].";

        LOGGER.debug(message);
        throw new JMSException(message);
    }

    LOGGER.debug("Service to call = " + serviceName);

    return serviceName;
}

From source file:org.apache.flume.source.jms.TestJMSSource.java

@Test
public void testProcessReconnect() throws Exception {
    source.configure(context);//w  ww  .  j  a  va  2  s  . c  om
    source.start();
    when(consumer.take()).thenThrow(new JMSException("dummy"));
    int attempts = JMSSourceConfiguration.ERROR_THRESHOLD_DEFAULT;
    for (int i = 0; i < attempts; i++) {
        Assert.assertEquals(Status.BACKOFF, source.process());
    }
    Assert.assertEquals(Status.BACKOFF, source.process());
    verify(consumer, times(attempts + 1)).rollback();
    verify(consumer, times(1)).close();
}

From source file:org.apache.hedwig.jms.spi.HedwigConnectionImpl.java

@Override
protected SessionImpl createSessionInstance(boolean transacted, int acknowledgeMode,
        MessagingSessionFacade.DestinationType type) throws JMSException {
    if (null == type)
        return new SessionImpl(this, transacted, acknowledgeMode);
    switch (type) {
    case QUEUE:// ww  w.ja  v  a2s.c om
        return new QueueSessionImpl(this, transacted, acknowledgeMode);
    case TOPIC:
        return new TopicSessionImpl(this, transacted, acknowledgeMode);
    default:
        throw new JMSException("Unknown type " + type);
    }
}

From source file:org.apache.hedwig.jms.spi.HedwigConnectionImpl.java

private ClientConfiguration loadConfig() throws JMSException {
    ClientConfiguration config = new ClientConfiguration();

    // TODO: This is not very extensible and useful ... we need to pick the info from
    // configuration specified by user, NOT only from static files !
    // Also, we need to be able to support multiple configuration in a single client !
    // We need a better solution ....

    try {//ww w . jav  a2s. com
        // 1. try to load the client configuration as specified from a
        // system property
        if (System.getProperty(HEDWIG_CLIENT_CONFIG_FILE) != null) {
            File configFile = new File(System.getProperty(HEDWIG_CLIENT_CONFIG_FILE));
            if (!configFile.exists()) {
                throw new JMSException(
                        "Cannot create connection: cannot find Hedwig client configuration file specified as ["
                                + System.getProperty(HEDWIG_CLIENT_CONFIG_FILE) + "]");
            }
            config.loadConf(configFile.toURI().toURL());
        } else {
            // 2. try to load a "hedwig-client.cfg" file from the classpath
            config.loadConf(new URL(null, "classpath://hedwig-client.cfg", new URLStreamHandler() {
                protected URLConnection openConnection(URL u) throws IOException {
                    // rely on the relevant classloader - not system classloader.
                    final URL resourceUrl = HedwigConnectionImpl.this.getClass().getClassLoader()
                            .getResource(u.getPath());
                    return resourceUrl.openConnection();
                }
            }));
        }

    } catch (MalformedURLException e) {
        JMSException je = new JMSException("Cannot load Hedwig client configuration file " + e);
        je.setLinkedException(e);
        throw je;
    } catch (ConfigurationException e) {
        JMSException je = new JMSException("Cannot load Hedwig client configuration " + e);
        je.setLinkedException(e);
        throw je;
    }

    /*
    System.out.println("getConsumedMessagesBufferSize : " + config.getConsumedMessagesBufferSize());
    System.out.println("getDefaultServerHost : " + config.getDefaultServerHost());
    System.out.println("isSSLEnabled : " + config.isSSLEnabled());
    System.out.println("getMaximumMessageSize : " + config.getMaximumMessageSize());
    System.out.println("getMaximumOutstandingMessages : " + config.getMaximumOutstandingMessages());
    System.out.println("getMaximumServerRedirects : "  + config.getMaximumServerRedirects());
    System.out.println("getServerAckResponseTimeout : "  + config.getServerAckResponseTimeout());
    */

    return config;
}