List of usage examples for javax.jms JMSException JMSException
public JMSException(String reason)
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Writes a <code>long</code> to the stream message. * * @param value//from w ww . j a va2s.com * the <code>long</code> value to be written * @throws JMSException * if the JMS provider fails to write the message due to some * internal error. * @throws MessageNotWriteableException * if the message is in read-only mode. */ public void writeLong(long value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalLong(dataOut, value); } catch (IOException e) { String exMessage = "Could not write long: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Writes a <code>float</code> to the stream message. * * @param value/* w w w.ja v a 2s. co m*/ * the <code>float</code> value to be written * @throws JMSException * if the JMS provider fails to write the message due to some * internal error. * @throws MessageNotWriteableException * if the message is in read-only mode. */ public void writeFloat(float value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalFloat(dataOut, value); } catch (IOException e) { String exMessage = "Could not write float: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Writes a <code>double</code> to the stream message. * * @param value/*from w w w. j av a 2 s. com*/ * the <code>double</code> value to be written * @throws JMSException * if the JMS provider fails to write the message due to some * internal error. * @throws MessageNotWriteableException * if the message is in read-only mode. */ public void writeDouble(double value) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalDouble(dataOut, value); } catch (IOException e) { String exMessage = "Could not write double: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Writes a <code>String</code> to the stream message. * * @param value/*from w w w. ja va2 s.c o m*/ * the <code>String</code> value to be written * @throws JMSException * if the JMS provider fails to write the message due to some * internal error. * @throws MessageNotWriteableException * if the message is in read-only mode. */ public void writeString(String value) throws JMSException { initializeWriting(); try { if (value == null) { MarshallingSupport.marshalNull(dataOut); } else { MarshallingSupport.marshalString(dataOut, value); } } catch (IOException e) { String exMessage = "Could not write string: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Writes a portion of a byte array as a byte array field to the stream * message. <p/>/*from w w w. j av a2 s . co m*/ * <P> * The a portion of the byte array <code>value</code> is written to the * message as a byte array field. Consecutively written byte array fields * are treated as two distinct fields when the fields are read. * * @param value * the byte array value to be written * @param offset * the initial offset within the byte array * @param length * the number of bytes to use * @throws JMSException * if the JMS provider fails to write the message due to some * internal error. * @throws MessageNotWriteableException * if the message is in read-only mode. */ public void writeBytes(byte[] value, int offset, int length) throws JMSException { initializeWriting(); try { MarshallingSupport.marshalByteArray(dataOut, value, offset, length); } catch (IOException e) { String exMessage = "Could not write byte[]: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } }
From source file:org.skyscreamer.nevado.jms.message.NevadoStreamMessage.java
/** * Writes an object to the stream message. <p/> * <P>//from w ww . j a va 2s .co m * This method works only for the objectified primitive object types (<code>Integer</code>, * <code>Double</code>, <code>Long</code> ...), * <code>String</code> objects, and byte arrays. * * @param value * the Java object to be written * @throws JMSException * if the JMS provider fails to write the message due to some * internal error. * @throws MessageFormatException * if the object is invalid. * @throws MessageNotWriteableException * if the message is in read-only mode. */ public void writeObject(Object value) throws JMSException { initializeWriting(); if (value == null) { try { MarshallingSupport.marshalNull(dataOut); } catch (IOException e) { String exMessage = "Could not write object: " + e.getMessage(); _log.error(exMessage, e); throw new JMSException(exMessage); } } else if (value instanceof String) { writeString(value.toString()); } else if (value instanceof Character) { writeChar(((Character) value).charValue()); } else if (value instanceof Boolean) { writeBoolean(((Boolean) value).booleanValue()); } else if (value instanceof Byte) { writeByte(((Byte) value).byteValue()); } else if (value instanceof Short) { writeShort(((Short) value).shortValue()); } else if (value instanceof Integer) { writeInt(((Integer) value).intValue()); } else if (value instanceof Long) { writeLong(((Long) value).longValue()); } else if (value instanceof Float) { writeFloat(((Float) value).floatValue()); } else if (value instanceof Double) { writeDouble(((Double) value).doubleValue()); } else if (value instanceof byte[]) { writeBytes((byte[]) value); } }
From source file:org.soulwing.oaq.CommonsServerSessionPool.java
/** * {@inheritDoc}//w ww .j av a2 s. c om */ @Override public ServerSession getServerSession() throws JMSException { try { return pool.borrowObject(); } catch (RuntimeException ex) { throw ex; } catch (UnavailableException ex) { throw (JMSException) new JMSException("cannot create endpoint").initCause(ex); } catch (JMSException ex) { throw ex; } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:org.springframework.integration.jms.JmsOutboundGateway.java
private javax.jms.Message retryableReceiveReply(Session session, Destination replyTo, String messageSelector) throws JMSException { Connection consumerConnection = null; //NOSONAR Session consumerSession = session;//from ww w.ja v a2s . co m MessageConsumer messageConsumer = null; JMSException exception = null; boolean isTemporaryReplyTo = replyTo instanceof TemporaryQueue || replyTo instanceof TemporaryTopic; long replyTimeout = isTemporaryReplyTo ? Long.MIN_VALUE : this.receiveTimeout < 0 ? Long.MAX_VALUE : System.currentTimeMillis() + this.receiveTimeout; try { do { try { messageConsumer = consumerSession.createConsumer(replyTo, messageSelector); javax.jms.Message reply = receiveReplyMessage(messageConsumer); if (reply == null) { if (replyTimeout > System.currentTimeMillis()) { throw new JMSException("Consumer closed before timeout"); } } return reply; } catch (JMSException e) { exception = e; if (logger.isDebugEnabled()) { logger.debug("Connection lost waiting for reply, retrying: " + e.getMessage()); } do { try { consumerConnection = createConnection(); consumerSession = createSession(consumerConnection); break; } catch (JMSException ee) { exception = ee; if (logger.isDebugEnabled()) { logger.debug("Could not reconnect, retrying: " + ee.getMessage()); } try { Thread.sleep(1000); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); return null; } } } while (replyTimeout > System.currentTimeMillis()); } } while (replyTimeout > System.currentTimeMillis()); if (isTemporaryReplyTo) { return null; } else { throw exception; } } finally { if (consumerSession != session) { JmsUtils.closeSession(consumerSession); JmsUtils.closeConnection(consumerConnection); } JmsUtils.closeMessageConsumer(messageConsumer); } }
From source file:org.springframework.jms.listener.serversession.CommonsPoolServerSessionFactory.java
/** * Returns a ServerSession from the pool, creating a new pool for the given * session manager if necessary.//w w w . j a v a 2s. c o m * @see #createObjectPool */ public ServerSession getServerSession(ListenerSessionManager sessionManager) throws JMSException { ObjectPool pool = null; synchronized (this.serverSessionPools) { pool = (ObjectPool) this.serverSessionPools.get(sessionManager); if (pool == null) { if (logger.isInfoEnabled()) { logger.info("Creating Commons ServerSession pool for: " + sessionManager); } pool = createObjectPool(sessionManager); this.serverSessionPools.put(sessionManager, pool); } } try { return (ServerSession) pool.borrowObject(); } catch (Exception ex) { JMSException jmsEx = new JMSException("Failed to borrow ServerSession from pool"); jmsEx.setLinkedException(ex); throw jmsEx; } }
From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.JMSReplySender.java
/** * Create a JMS Message from the given MessageContext and using the given * session//from w ww . j a v a2 s. com * * @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 synCtx, Session session, String contentTypeProperty) throws JMSException { Message message = null; org.apache.axis2.context.MessageContext msgContext = ((Axis2MessageContext) synCtx) .getAxis2MessageContext(); String msgType = getProperty(msgContext, JMSConstants.JMS_MESSAGE_TYPE); String jmsPayloadType = guessMessageType(msgContext); if (jmsPayloadType == null) { OMOutputFormat format = BaseUtils.getOMOutputFormat(msgContext); MessageFormatter messageFormatter = null; try { messageFormatter = MessageProcessorSelector.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) { log.error("Unsupported encoding " + format.getCharSetEncoding(), ex); throw new JMSException("Unsupported encoding " + format.getCharSetEncoding()); } } try { messageFormatter.writeTo(msgContext, format, out, true); out.close(); } catch (IOException e) { log.error("IO Error while creating BytesMessage", e); throw new JMSException("IO Error while creating BytesMessage"); } 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) { log.error("Error serializing binary content of element : " + BaseConstants.DEFAULT_BINARY_WRAPPER, e); throw new JMSException("Error serializing binary content of element : " + BaseConstants.DEFAULT_BINARY_WRAPPER); } } } } 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()); } else if (JMSConstants.JMS_MAP_MESSAGE.equalsIgnoreCase(jmsPayloadType)) { message = session.createMapMessage(); JMSUtils.convertXMLtoJMSMap( msgContext.getEnvelope().getBody().getFirstChildWithName(JMSConstants.JMS_MAP_QNAME), (MapMessage) message); } // set the JMS correlation ID if specified String correlationId = (String) synCtx.getProperty(JMSConstants.JMS_COORELATION_ID); 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; }