@Override public void setContentType(MimeType contentType) { super.setContentType(contentType); setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString()); }
private String appendPayload(Object payload) { if (payload.getClass() != byte[].class) { throw new IllegalStateException( "Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass())); } byte[] bytes = (byte[]) payload; MimeType mimeType = getContentType(); String contentType = (mimeType != null ? " " + mimeType.toString() : ""); if (bytes.length == 0 || mimeType == null || !isReadableContentType()) { return contentType; } Charset charset = mimeType.getCharset(); charset = (charset != null ? charset : StandardCharsets.UTF_8); return (bytes.length < 80) ? contentType + " payload=" + new String(bytes, charset) : contentType + " payload=" + new String(Arrays.copyOf(bytes, 80), charset) + "...(truncated)"; }
/** * Set the content-type header. * Applies to the SEND, MESSAGE, and ERROR frames. */ public void setContentType(@Nullable MimeType mimeType) { if (mimeType != null) { Assert.isTrue(!mimeType.isWildcardType(), "'Content-Type' cannot contain wildcard type '*'"); Assert.isTrue(!mimeType.isWildcardSubtype(), "'Content-Type' cannot contain wildcard subtype '*'"); set(CONTENT_TYPE, mimeType.toString()); } else { set(CONTENT_TYPE, null); } }
private void testWithQuotedParameters(String... mimeTypes) { String s = String.join(",", mimeTypes); List<MimeType> actual = MimeTypeUtils.parseMimeTypes(s); assertEquals(mimeTypes.length, actual.size()); for (int i=0; i < mimeTypes.length; i++) { assertEquals(mimeTypes[i], actual.get(i).toString()); } }
void updateStompHeadersFromSimpMessageHeaders() { String destination = getDestination(); if (destination != null) { setNativeHeader(STOMP_DESTINATION_HEADER, destination); } MimeType contentType = getContentType(); if (contentType != null) { setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString()); } trySetStompHeaderForSubscriptionId(); }
@Test public void testToString() { MimeType mimeType = new MimeType("text", "plain"); String result = mimeType.toString(); assertEquals("Invalid toString() returned", "text/plain", result); }
@Override public void setContentType(MimeType contentType) { super.setContentType(contentType); setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString()); }
private String appendPayload(Object payload) { if (payload.getClass() != byte[].class) { throw new IllegalStateException( "Expected byte array payload but got: " + ClassUtils.getQualifiedName(payload.getClass())); } byte[] bytes = (byte[]) payload; MimeType mimeType = getContentType(); String contentType = (mimeType != null ? " " + mimeType.toString() : ""); if (bytes.length == 0 || mimeType == null || !isReadableContentType()) { return contentType; } Charset charset = mimeType.getCharset(); charset = (charset != null ? charset : StandardCharsets.UTF_8); return (bytes.length < 80) ? contentType + " payload=" + new String(bytes, charset) : contentType + " payload=" + new String(Arrays.copyOf(bytes, 80), charset) + "...(truncated)"; }
/** * Set the content-type header. * Applies to the SEND, MESSAGE, and ERROR frames. */ public void setContentType(@Nullable MimeType mimeType) { if (mimeType != null) { Assert.isTrue(!mimeType.isWildcardType(), "'Content-Type' cannot contain wildcard type '*'"); Assert.isTrue(!mimeType.isWildcardSubtype(), "'Content-Type' cannot contain wildcard subtype '*'"); set(CONTENT_TYPE, mimeType.toString()); } else { set(CONTENT_TYPE, null); } }
void updateStompHeadersFromSimpMessageHeaders() { String destination = getDestination(); if (destination != null) { setNativeHeader(STOMP_DESTINATION_HEADER, destination); } MimeType contentType = getContentType(); if (contentType != null) { setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString()); } trySetStompHeaderForSubscriptionId(); }
@Test public void testToMessageWithContentType() throws Exception { TcpMessageMapper mapper = new TcpMessageMapper(); mapper.setAddContentTypeHeader(true); TcpConnection connection = mock(TcpConnection.class); Socket socket = mock(Socket.class); InetAddress local = mock(InetAddress.class); SocketInfo info = new SocketInfo(socket); when(socket.getLocalAddress()).thenReturn(local); when(connection.getPayload()).thenReturn(TEST_PAYLOAD.getBytes()); when(connection.getHostName()).thenReturn("MyHost"); when(connection.getHostAddress()).thenReturn("1.1.1.1"); when(connection.getPort()).thenReturn(1234); when(connection.getSocketInfo()).thenReturn(info); Message<?> message = mapper.toMessage(connection); assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload())); assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME)); assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS)); assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT)); assertSame(local, message.getHeaders().get(IpHeaders.LOCAL_ADDRESS)); assertEquals("application/octet-stream;charset=UTF-8", message.getHeaders().get(MessageHeaders.CONTENT_TYPE)); MimeType parseOk = MimeType.valueOf((String) message.getHeaders().get(MessageHeaders.CONTENT_TYPE)); assertEquals(message.getHeaders().get(MessageHeaders.CONTENT_TYPE), parseOk.toString()); }
@Test public void testToMessageWithCustomContentType() throws Exception { TcpMessageMapper mapper = new TcpMessageMapper(); mapper.setAddContentTypeHeader(true); mapper.setContentType("application/octet-stream;charset=ISO-8859-1"); TcpConnection connection = mock(TcpConnection.class); Socket socket = mock(Socket.class); InetAddress local = mock(InetAddress.class); SocketInfo info = new SocketInfo(socket); when(socket.getLocalAddress()).thenReturn(local); when(connection.getPayload()).thenReturn(TEST_PAYLOAD.getBytes()); when(connection.getHostName()).thenReturn("MyHost"); when(connection.getHostAddress()).thenReturn("1.1.1.1"); when(connection.getPort()).thenReturn(1234); when(connection.getSocketInfo()).thenReturn(info); Message<?> message = mapper.toMessage(connection); assertEquals(TEST_PAYLOAD, new String((byte[]) message.getPayload())); assertEquals("MyHost", message.getHeaders().get(IpHeaders.HOSTNAME)); assertEquals("1.1.1.1", message.getHeaders().get(IpHeaders.IP_ADDRESS)); assertEquals(1234, message.getHeaders().get(IpHeaders.REMOTE_PORT)); assertSame(local, message.getHeaders().get(IpHeaders.LOCAL_ADDRESS)); assertEquals("application/octet-stream;charset=ISO-8859-1", message.getHeaders().get(MessageHeaders.CONTENT_TYPE)); MimeType parseOk = MimeType.valueOf((String) message.getHeaders().get(MessageHeaders.CONTENT_TYPE)); assertEquals(message.getHeaders().get(MessageHeaders.CONTENT_TYPE), parseOk.toString()); }
assertThat(headers.get("fix")).isInstanceOf(NonTrustedHeaderType.class); assertThat(headers.get("linkedMVMap")).isInstanceOf(LinkedMultiValueMap.class); assertThat(headers.get(MessageHeaders.CONTENT_TYPE)).isEqualTo(utf8Text.toString()); assertThat(headers.get("simpleContentType")).isEqualTo(MimeTypeUtils.TEXT_PLAIN.toString()); assertThat(headers.get(MessageHeaders.REPLY_CHANNEL)).isNull(); assertThat(headers.get(MessageHeaders.ERROR_CHANNEL)).isEqualTo("errors");
@Override public void serialize(MimeType value, JsonGenerator gen, SerializerProvider serializers) throws IOException { gen.writeString(value.toString()); } }
private SchemaReference extractSchemaReference(MimeType mimeType) { SchemaReference schemaReference = null; Matcher schemaMatcher = this.versionedSchema.matcher(mimeType.toString()); if (schemaMatcher.find()) { String subject = schemaMatcher.group(1); Integer version = Integer.parseInt(schemaMatcher.group(2)); schemaReference = new SchemaReference(subject, version, AVRO_FORMAT); } return schemaReference; } }
private SchemaReference extractSchemaReference(MimeType mimeType) { SchemaReference schemaReference = null; Matcher schemaMatcher = this.versionedSchema.matcher(mimeType.toString()); if (schemaMatcher.find()) { String subject = schemaMatcher.group(1); Integer version = Integer.parseInt(schemaMatcher.group(2)); schemaReference = new SchemaReference(subject, version, AVRO_FORMAT); } return schemaReference; } }
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT) public Object transform(Message<?> message) { if (message.getPayload() instanceof byte[]) { String contentType = message.getHeaders().containsKey(MessageHeaders.CONTENT_TYPE) ? message.getHeaders().get(MessageHeaders.CONTENT_TYPE).toString() : BindingProperties.DEFAULT_CONTENT_TYPE.toString(); if (contentType.contains("text") || contentType.contains("json") || contentType.contains("x-spring-tuple")) { message = new MutableMessage<>(new String(((byte[]) message.getPayload())), message.getHeaders()); } } return properties.getExpression().getValue(message); }
@Override public Object decode(Response response, Type type) throws IOException, DecodeException, FeignException { Collection<String> contentTypes = response.headers().get("Content-Type"); if (contentTypes.contains(MimeTypeUtils.TEXT_PLAIN.toString())) { return defaultDecoder.decode(response, type); } else { return gsonDecoder.decode(response, type); } } }
@Override public void setContentType(MimeType contentType) { super.setContentType(contentType); setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString()); }
void updateStompHeadersFromSimpMessageHeaders() { String destination = getDestination(); if (destination != null) { setNativeHeader(STOMP_DESTINATION_HEADER, destination); } MimeType contentType = getContentType(); if (contentType != null) { setNativeHeader(STOMP_CONTENT_TYPE_HEADER, contentType.toString()); } trySetStompHeaderForSubscriptionId(); }