List of usage examples for org.springframework.amqp.support.converter MessageConversionException MessageConversionException
public MessageConversionException(String message, Throwable cause)
From source file:com.jbrisbin.vpc.jobsched.sql.SqlMessageConverter.java
public Message toMessage(Object object, MessageProperties props) throws MessageConversionException { if (object instanceof SqlMessage) { SqlMessage msg = (SqlMessage) object; props.setCorrelationId(msg.getId().getBytes()); byte[] bytes; try {//ww w .j a v a 2 s.co m bytes = unmapObject(msg.getResults()); } catch (IOException e) { throw new MessageConversionException(e.getMessage(), e); } props.setContentType("application/json"); return new Message(bytes, props); } else { throw new MessageConversionException( "Cannot convert object " + String.valueOf(object) + " using " + getClass().toString()); } }
From source file:com.auditbucket.helper.JsonToSearchResultConverter.java
@Override public Object fromMessage(final Message message) throws MessageConversionException { final Object content = super.fromMessage(message); try {//from w w w. ja v a 2 s .c om if (content instanceof String) { ObjectMapper mapper = new ObjectMapper(); SearchResult searchResult = mapper.readValue(((String) content).getBytes(), SearchResult.class); return searchResult; } } catch (IOException e1) { throw new MessageConversionException("failed to convert text-based Message content", e1); } return content; }
From source file:com.dc.gameserver.extComponents.SpringRabbitmq.FastJsonMessageConverter.java
protected Message createMessage(Object objectToConvert, MessageProperties messageProperties) throws MessageConversionException { byte[] bytes = null; try {/*from w w w. j a va 2s .com*/ String jsonString = JSON.toJSONString(objectToConvert); bytes = jsonString.getBytes(this.defaultCharset); } catch (UnsupportedEncodingException e) { throw new MessageConversionException("Failed to convert Message content", e); } messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON); messageProperties.setContentEncoding(this.defaultCharset); messageProperties.setContentLength(bytes.length); return new Message(bytes, messageProperties); }
From source file:com.jbrisbin.vpc.jobsched.exe.ExeMessageConverter.java
public Object fromMessage(Message message) throws MessageConversionException { MessageProperties props = message.getMessageProperties(); if (isAuthorized(props)) { //Map<String, Object> headers = props.getHeaders(); byte[] bytes = message.getBody(); ExeMessage msg;/*w w w.j a v a 2 s .co m*/ try { msg = mapObject(bytes, ExeMessage.class); if (log.isDebugEnabled()) { log.debug(String.format(" MSG: %s", msg)); } } catch (IOException e) { throw new MessageConversionException(e.getMessage(), e); } return msg; } else { throw new MessageConversionException("Invalid security key."); } }
From source file:amqp.spring.converter.StringConverter.java
@Override protected Message createMessage(Object object, MessageProperties messageProperties) { try {/*from w w w .j av a2 s .com*/ byte[] body = null; if (object != null) { body = object.toString().getBytes(this.encoding); } String msgContentType = this.contentType == null ? DEFAULT_CONTENT_TYPE : this.contentType; messageProperties.setContentType(msgContentType); messageProperties.setContentEncoding(this.encoding); messageProperties.setContentLength(body != null ? body.length : 0); return new Message(body, messageProperties); } catch (UnsupportedEncodingException ex) { LOG.error("Cannot encode strings as {}", this.encoding, ex); throw new MessageConversionException("Cannot encode strings as " + this.encoding, ex); } }
From source file:com.jbrisbin.vpc.jobsched.batch.BatchMessageConverter.java
public Message toMessage(Object object, MessageProperties props) throws MessageConversionException { if (object instanceof BatchMessage) { BatchMessage batch = (BatchMessage) object; props.setCorrelationId(batch.getId().getBytes()); props.setContentType("application/zip"); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ZipOutputStream zout = new ZipOutputStream(bout); for (Map.Entry<String, String> msg : batch.getMessages().entrySet()) { ZipEntry zentry = new ZipEntry(msg.getKey()); try { zout.putNextEntry(zentry); zout.write(msg.getValue().getBytes()); zout.closeEntry();/*from w w w. j a v a 2 s .c om*/ } catch (IOException e) { throw new MessageConversionException(e.getMessage(), e); } } try { zout.flush(); zout.close(); } catch (IOException e) { throw new MessageConversionException(e.getMessage(), e); } return new Message(bout.toByteArray(), props); } else { throw new MessageConversionException( "Cannot convert object " + String.valueOf(object) + " using " + getClass().toString()); } }
From source file:com.github.liyp.rabbitmq.demo.FastJsonMessageConverter.java
protected Message createMessage(Object objectToConvert, MessageProperties messageProperties) throws MessageConversionException { byte[] bytes = null; try {//from ww w .j a v a 2s . c om String jsonString = JSON.toJSONString(objectToConvert); bytes = jsonString.getBytes(this.defaultCharset); } catch (UnsupportedEncodingException e) { throw new MessageConversionException("Failed to convert Message content", e); } messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON); messageProperties.setContentEncoding(this.defaultCharset); if (bytes != null) { messageProperties.setContentLength(bytes.length); } return new Message(bytes, messageProperties); }
From source file:org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper.java
private JavaType getClassIdType(String classId) { if (getIdClassMapping().containsKey(classId)) { return TypeFactory.defaultInstance().constructType(getIdClassMapping().get(classId)); }/*from w w w . j av a 2s . c o m*/ try { return TypeFactory.defaultInstance() .constructType(ClassUtils.forName(classId, getClass().getClassLoader())); } catch (ClassNotFoundException e) { throw new MessageConversionException("failed to resolve class name. Class not found [" + classId + "]", e); } catch (LinkageError e) { throw new MessageConversionException("failed to resolve class name. Linkage error [" + classId + "]", e); } }
From source file:com.jbrisbin.vpc.jobsched.sql.SqlMessageConverter.java
public Object fromMessage(Message message) throws MessageConversionException { MessageProperties props = message.getMessageProperties(); if (isAuthorized(props)) { //Map<String, Object> headers = props.getHeaders(); byte[] bytes = message.getBody(); SqlMessage msg;//from ww w. j a va 2 s. com try { msg = mapObject(bytes, SqlMessage.class); msg.setId(new String(props.getCorrelationId())); msg.setReplyTo(props.getReplyTo().toString()); if (log.isDebugEnabled()) { log.debug(String.format(" MSG: %s", msg)); } } catch (IOException e) { throw new MessageConversionException(e.getMessage(), e); } return msg; } else { throw new MessageConversionException("Invalid security key."); } }
From source file:com.jbrisbin.vpc.jobsched.mapred.MapReduceMessageConverter.java
public Object fromMessage(Message message) throws MessageConversionException { MessageProperties props = message.getMessageProperties(); if (isAuthorized(props)) { //Map<String, Object> headers = props.getHeaders(); byte[] bytes = message.getBody(); MapReduceMessage msg = new MapReduceMessage(); msg.setId(new String(props.getCorrelationId())); try {//w ww. ja va2s .c o m msg.setReplyTo(props.getReplyTo().toString()); } catch (NullPointerException ignored) { } msg.setKey(props.getHeaders().get("mapreduce.key").toString()); msg.setSrc(props.getHeaders().get("mapreduce.src").toString()); msg.setType(props.getReceivedRoutingKey()); try { try { msg.setData(mapObject(bytes, List.class)); } catch (JsonMappingException e1) { try { msg.setData(mapObject(bytes, Map.class)); } catch (JsonMappingException e2) { try { msg.setData(mapObject(bytes, Integer.class)); } catch (JsonMappingException e3) { try { msg.setData(mapObject(bytes, String.class)); } catch (JsonMappingException e4) { } } } } } catch (IOException ioe) { throw new MessageConversionException(ioe.getMessage(), ioe); } return msg; } else { throw new MessageConversionException("Invalid security key."); } }