List of usage examples for javax.jms BytesMessage getStringProperty
String getStringProperty(String name) throws JMSException;
From source file:com.kinglcc.spring.jms.core.converter.Jackson2JmsMessageConverter.java
/** * Convert a BytesMessage to a Java Object with the specified type. * @param message the input message/* w w w . j a v a2s . c o m*/ * @return the message body * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected String getPayloadFromBytesMessage(BytesMessage message) throws JMSException, IOException { String encoding = this.encoding; if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) { encoding = message.getStringProperty(this.encodingPropertyName); } byte[] bytes = new byte[(int) message.getBodyLength()]; message.readBytes(bytes); try { return new String(bytes, encoding); } catch (UnsupportedEncodingException ex) { throw new MessageConversionException("Cannot convert bytes to String", ex); } }
From source file:org.exist.replication.jms.obsolete.FileSystemListener.java
private eXistMessage convertMessage(BytesMessage bm) { eXistMessage em = new eXistMessage(); try {/*from ww w . j a v a2 s. c o m*/ Enumeration e = bm.getPropertyNames(); while (e.hasMoreElements()) { Object next = e.nextElement(); if (next instanceof String) { em.getMetadata().put((String) next, bm.getObjectProperty((String) next)); } } String value = bm.getStringProperty(eXistMessage.EXIST_RESOURCE_TYPE); eXistMessage.ResourceType resourceType = eXistMessage.ResourceType.valueOf(value); em.setResourceType(resourceType); value = bm.getStringProperty(eXistMessage.EXIST_RESOURCE_OPERATION); eXistMessage.ResourceOperation changeType = eXistMessage.ResourceOperation.valueOf(value); em.setResourceOperation(changeType); value = bm.getStringProperty(eXistMessage.EXIST_SOURCE_PATH); em.setResourcePath(value); value = bm.getStringProperty(eXistMessage.EXIST_DESTINATION_PATH); em.setDestinationPath(value); long size = bm.getBodyLength(); LOG.debug("actual length=" + size); // This is potentially memory intensive byte[] payload = new byte[(int) size]; bm.readBytes(payload); em.setPayload(payload); } catch (JMSException ex) { LOG.error(ex); } return em; }
From source file:org.oxymores.chronix.engine.Runner.java
@Override public void onMessage(Message msg) { if (msg instanceof ObjectMessage) { ObjectMessage omsg = (ObjectMessage) msg; try {//from w w w.j a v a 2 s. c om Object o = omsg.getObject(); if (o instanceof PipelineJob) { PipelineJob pj = (PipelineJob) o; log.debug(String.format("Job execution %s request was received", pj.getId())); recvPJ(pj); jmsCommit(); return; } else if (o instanceof RunResult) { RunResult rr = (RunResult) o; recvRR(rr); jmsCommit(); return; } else { log.warn( "An object was received by the Runner that was not of a valid type. It will be ignored."); jmsCommit(); return; } } catch (JMSException e) { log.error( "An error occurred during job reception. Message will stay in queue and will be analysed later", e); jmsRollback(); return; } } else if (msg instanceof TextMessage) { TextMessage tmsg = (TextMessage) msg; try { recvTextMessage(tmsg); jmsCommit(); } catch (JMSException e) { log.error("An error occurred during parameter resolution", e); jmsRollback(); return; } } else if (msg instanceof BytesMessage) { // log file reception BytesMessage bmsg = (BytesMessage) msg; String fn = "dump.txt"; try { fn = bmsg.getStringProperty("FileName"); } catch (JMSException e) { log.error( "An log file was sent without a FileName property. It will be lost. Will not impact the scheduler itself.", e); jmsCommit(); } try { int l = (int) bmsg.getBodyLength(); byte[] r = new byte[l]; bmsg.readBytes(r); IOUtils.write(r, new FileOutputStream(new File(FilenameUtils.concat(this.logDbPath, fn)))); jmsCommit(); } catch (Exception e) { log.error( "An error has occured while receiving a log file. It will be lost. Will not impact the scheduler itself.", e); jmsCommit(); } } }