private void readHeaders(ByteBuffer buffer, StompHeaderAccessor headerAccessor) { while (true) { ByteArrayOutputStream headerStream = new ByteArrayOutputStream(256); boolean headerComplete = false; while (buffer.hasRemaining()) { if (tryConsumeEndOfLine(buffer)) { headerComplete = true; break; } headerStream.write(buffer.get()); } if (headerStream.size() > 0 && headerComplete) { String header = new String(headerStream.toByteArray(), UTF8_CHARSET); int colonIndex = header.indexOf(':'); if (colonIndex <= 0) { if (buffer.remaining() > 0) { throw new StompConversionException("Illegal header: '" + header + "'. A header must be of the form <name>:[<value>]."); } } else { String headerName = unescape(header.substring(0, colonIndex)); String headerValue = unescape(header.substring(colonIndex + 1)); try { headerAccessor.addNativeHeader(headerName, headerValue); } catch (InvalidMimeTypeException ex) { if (buffer.remaining() > 0) { throw ex; } } } } else { break; } } }
@Test(expected = InvalidMimeTypeException.class) public void resolveInvalidStringContentType() { Map<String, Object> map = new HashMap<String, Object>(); map.put(MessageHeaders.CONTENT_TYPE, "invalidContentType"); MessageHeaders headers = new MessageHeaders(map); this.resolver.resolve(headers); }
/** * Indicates whether the content type represented by the given string * is a valid, known content type. * * @param contentType the content type string. * @return true if the content is valid, false if not. */ public static boolean isValidContentType( String contentType ) { try { MimeTypeUtils.parseMimeType( contentType ); } catch ( InvalidMimeTypeException ignored ) { return false; } return true; }
private boolean isValidContentType( String contentType ) { try { MimeTypeUtils.parseMimeType( contentType ); } catch ( InvalidMimeTypeException e ) { return false; } return true; }
/** * Constructor that allows wrapping {@link InvalidMimeTypeException}. */ InvalidMediaTypeException(InvalidMimeTypeException ex) { super(ex.getMessage(), ex); this.mediaType = ex.getMimeType(); }
@Test(expected = InvalidMimeTypeException.class) public void decodeFrameWithInvalidContentType() { assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0"); }