@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof MailTextBody)) { return false; } MailTextBody that = (MailTextBody) o; if (mimeType != null ? !mimeType.equals(that.mimeType) : that.mimeType != null) { return false; } if (text != null ? !text.equals(that.text) : that.text != null) { return false; } return true; }
private Object deserializePayload(Object payload, MimeType contentType) { if (payload instanceof byte[]) { if (contentType == null || APPLICATION_OCTET_STREAM.equals(contentType)) { return payload; } else { return deserializePayload((byte[]) payload, contentType); } } return payload; }
public void read(String mimeType, InputStream is) throws IOException { Assert.hasText(mimeType, "MimeType string is null or empty."); Assert.notNull(is, "InputStream is null or empty."); MimeType mimeTypeObj = MimeTypeUtils.parseMimeType(mimeType); if(MimeTypeUtils.APPLICATION_JSON.equals(mimeTypeObj)) { Assert.hasText(mimeType, "MimeType '" + mimeType + "' is not supported."); } AppConfigObject aco = objectMapper.readValue(is, AppConfigObject.class); final String version = aco.getVersion(); if(!VERSION.equals(version)) { throw new RuntimeException("Unsupported version of config: " + version); } ConfigReadContext ctx = new ConfigReadContext(); Map<String, Object> map = aco.getData(); Assert.notNull(map, "config has empty map"); for(Map.Entry<String, Object> oe : map.entrySet()) { String name = oe.getKey(); ReConfigurableAdapter ca = adapters.get(name); Assert.notNull(ca, "Can not find adapter with name: " + name); Object value = oe.getValue(); Assert.notNull(value, "Config object is null for name: " + name); ca.setConfig(ctx, value); } } }
private static MimeType resolveMimeType(Map<String, ?> configs) { if (configs.containsKey(MessageHeaders.CONTENT_TYPE)) { String contentType = (String) configs.get(MessageHeaders.CONTENT_TYPE); if (DEFAULT_AVRO_MIME_TYPE.equals(MimeTypeUtils.parseMimeType(contentType))) { return DEFAULT_AVRO_MIME_TYPE; } else if (contentType.contains("avro")) { return MimeTypeUtils.parseMimeType("application/avro"); } else { return new MimeType("application", "json", StandardCharsets.UTF_8); } } else { return new MimeType("application", "json", StandardCharsets.UTF_8); } }
private Object deserializePayload(byte[] bytes, MimeType contentType) { if (TEXT_PLAIN.equals(contentType)) { try { return new String(bytes, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new SerializationException("unable to deserialize [java.lang.String]. Encoding not supported.", e); } } else { String className = JavaClassMimeTypeConversion.classNameFromMimeType(contentType); try { // Cache types to avoid unnecessary ClassUtils.forName calls. Class<?> targetType = payloadTypeCache.get(className); if (targetType == null) { targetType = ClassUtils.forName(className, null); payloadTypeCache.put(className, targetType); } return codec.decode(bytes, targetType); } catch (ClassNotFoundException e) { throw new SerializationException("unable to deserialize [" + className + "]. Class not found.", e);//NOSONAR } catch (IOException e) { throw new SerializationException("unable to deserialize [" + className + "]", e); } } }
/** */ public void write(String mimeType, OutputStream os) throws IOException { Assert.hasText(mimeType, "MimeType string is null or empty."); Assert.notNull(os, "OutputStream is null or empty."); MimeType mimeTypeObj = MimeTypeUtils.parseMimeType(mimeType); if(MimeTypeUtils.APPLICATION_JSON.equals(mimeTypeObj)) { Assert.hasText(mimeType, "MimeType '" + mimeType + "' is not supported."); } AppConfigObject aco = new AppConfigObject(); aco.setDate(LocalDateTime.now()); aco.setVersion(VERSION); Map<String, Object> map = new HashMap<>(); aco.setData(map); ConfigWriteContext ctx = ConfigWriteContext.builder() .mimeType(mimeTypeObj) .build(); for(ConcurrentMap.Entry<String, ReConfigurableAdapter> cae : adapters.entrySet()) { ReConfigurableAdapter ca = cae.getValue(); Object o = ca.getConfig(ctx); if(o == null) { continue; } String name = cae.getKey(); map.put(name, o); } objectMapper.writeValue(os, aco); }