List of usage examples for org.springframework.util MimeTypeUtils APPLICATION_OCTET_STREAM
MimeType APPLICATION_OCTET_STREAM
To view the source code for org.springframework.util MimeTypeUtils APPLICATION_OCTET_STREAM.
Click Source Link
From source file:org.springframework.cloud.stream.binder.AbstractBinder.java
private Object deserializePayload(Object payload, MimeType contentType) { if (payload instanceof byte[]) { if (contentType == null || MimeTypeUtils.APPLICATION_OCTET_STREAM.equals(contentType)) { return payload; } else {/*from w ww .ja v a 2s . c om*/ return deserializePayload((byte[]) payload, contentType); } } return payload; }
From source file:org.springframework.messaging.handler.annotation.reactive.PayloadMethodArgumentResolver.java
/** * Decode the content of the given message payload through a compatible * {@link Decoder}.//from w ww .ja va 2 s. c o m * * <p>Validation is applied if the method argument is annotated with * {@code @javax.validation.Valid} or * {@link org.springframework.validation.annotation.Validated}. Validation * failure results in an {@link MethodArgumentNotValidException}. * * @param parameter the target method argument that we are decoding to * @param message the message from which the content was extracted * @return a Mono with the result of argument resolution * * @see #extractContent(MethodParameter, Message) * @see #getMimeType(Message) */ @Override public final Mono<Object> resolveArgument(MethodParameter parameter, Message<?> message) { Payload ann = parameter.getParameterAnnotation(Payload.class); if (ann != null && StringUtils.hasText(ann.expression())) { throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver"); } MimeType mimeType = getMimeType(message); mimeType = mimeType != null ? mimeType : MimeTypeUtils.APPLICATION_OCTET_STREAM; Flux<DataBuffer> content = extractContent(parameter, message); return decodeContent(parameter, message, ann == null || ann.required(), content, mimeType); }
From source file:org.springframework.web.socket.messaging.StompSubProtocolHandler.java
private void sendToClient(WebSocketSession session, StompHeaderAccessor stompAccessor, byte[] payload) { StompCommand command = stompAccessor.getCommand(); try {/*from w w w.jav a 2 s . c o m*/ byte[] bytes = this.stompEncoder.encode(stompAccessor.getMessageHeaders(), payload); boolean useBinary = (payload.length > 0 && !(session instanceof SockJsSession) && MimeTypeUtils.APPLICATION_OCTET_STREAM.isCompatibleWith(stompAccessor.getContentType())); if (useBinary) { session.sendMessage(new BinaryMessage(bytes)); } else { session.sendMessage(new TextMessage(bytes)); } } catch (SessionLimitExceededException ex) { // Bad session, just get out throw ex; } catch (Throwable ex) { // Could be part of normal workflow (e.g. browser tab closed) if (logger.isDebugEnabled()) { logger.debug("Failed to send WebSocket message to client in session " + session.getId(), ex); } command = StompCommand.ERROR; } finally { if (StompCommand.ERROR.equals(command)) { try { session.close(CloseStatus.PROTOCOL_ERROR); } catch (IOException ex) { // Ignore } } } }
From source file:org.springframework.xd.dirt.stream.FileSourceModuleTests.java
@Test public void testFileContentsAsString() throws IOException { deployStream("filestring", "file --dir=" + sourceDirName + " --fixedDelay=0 --outputType='text/plain;charset=UTF-8' | sink"); MessageTest test = new MessageTest() { @Override/*w w w . java 2 s.c o m*/ public void test(Message<?> message) throws MessagingException { assertEquals("foo", message.getPayload()); assertEquals("foo2.txt", message.getHeaders().get(FileHeaders.FILENAME, String.class)); assertEquals(MimeTypeUtils.APPLICATION_OCTET_STREAM, contentTypeResolver.resolve(message.getHeaders())); } }; StreamTestSupport.getSinkInputChannel("filestring").subscribe(test); dropFile("foo2.txt"); test.waitForCompletion(6000); StreamTestSupport.getDeployedModule("filestring", 0).stop(); assertTrue(test.getMessageHandled()); }