org.springframework.util.InvalidMimeTypeException Java Examples

The following examples show how to use org.springframework.util.InvalidMimeTypeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StompDecoder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void readHeaders(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) {
	while (true) {
		ByteArrayOutputStream headerStream = new ByteArrayOutputStream(256);
		boolean headerComplete = false;
		while (byteBuffer.hasRemaining()) {
			if (tryConsumeEndOfLine(byteBuffer)) {
				headerComplete = true;
				break;
			}
			headerStream.write(byteBuffer.get());
		}
		if (headerStream.size() > 0 && headerComplete) {
			String header = new String(headerStream.toByteArray(), StandardCharsets.UTF_8);
			int colonIndex = header.indexOf(':');
			if (colonIndex <= 0) {
				if (byteBuffer.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 (byteBuffer.remaining() > 0) {
						throw ex;
					}
				}
			}
		}
		else {
			break;
		}
	}
}
 
Example #2
Source File: MockHttpServletResponseAssert.java    From gocd with Apache License 2.0 5 votes vote down vote up
public SELF hasContentType(String mimeType) {
    String contentType = actual.getHeader("content-type");
    try {
        if (!(isNotBlank(contentType) && MimeType.valueOf(contentType).isCompatibleWith(MimeType.valueOf(mimeType)))) {
            failWithMessage("Expected content type <%s> but was <%s>", mimeType, contentType);
        }
    } catch (InvalidMimeTypeException e) {
        failWithMessage("Actual content type <%s> could not be parsed", contentType);
    }
    return myself;
}
 
Example #3
Source File: ApiController.java    From gocd with Apache License 2.0 5 votes vote down vote up
protected boolean isJsonContentType(Request request) {
    String mime = request.headers("Content-Type");
    if (isBlank(mime)) {
        return false;
    }
    try {
        MimeType mimeType = MimeType.valueOf(mime);
        return "application".equals(mimeType.getType()) && "json".equals(mimeType.getSubtype());
    } catch (InvalidMimeTypeException e) {
        return false;
    }
}
 
Example #4
Source File: FileResourceUtils.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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;
}
 
Example #5
Source File: DefaultContentTypeResolverTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #6
Source File: StompDecoder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
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;
		}
	}
}
 
Example #7
Source File: DefaultContentTypeResolverTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test(expected = InvalidMimeTypeException.class)
public void resolveInvalidStringContentType() {
	Map<String, Object> map = new HashMap<>();
	map.put(MessageHeaders.CONTENT_TYPE, "invalidContentType");
	MessageHeaders headers = new MessageHeaders(map);
	this.resolver.resolve(headers);
}
 
Example #8
Source File: StompDecoder.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void readHeaders(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) {
	while (true) {
		ByteArrayOutputStream headerStream = new ByteArrayOutputStream(256);
		boolean headerComplete = false;
		while (byteBuffer.hasRemaining()) {
			if (tryConsumeEndOfLine(byteBuffer)) {
				headerComplete = true;
				break;
			}
			headerStream.write(byteBuffer.get());
		}
		if (headerStream.size() > 0 && headerComplete) {
			String header = new String(headerStream.toByteArray(), StandardCharsets.UTF_8);
			int colonIndex = header.indexOf(':');
			if (colonIndex <= 0) {
				if (byteBuffer.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 (byteBuffer.remaining() > 0) {
						throw ex;
					}
				}
			}
		}
		else {
			break;
		}
	}
}
 
Example #9
Source File: DefaultContentTypeResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test(expected = InvalidMimeTypeException.class)
public void resolveInvalidStringContentType() {
	Map<String, Object> map = new HashMap<>();
	map.put(MessageHeaders.CONTENT_TYPE, "invalidContentType");
	MessageHeaders headers = new MessageHeaders(map);
	this.resolver.resolve(headers);
}
 
Example #10
Source File: StompDecoderTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test(expected = InvalidMimeTypeException.class)
public void decodeFrameWithInvalidContentType() {
	assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0");
}
 
Example #11
Source File: InvalidMediaTypeException.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
Example #12
Source File: InvalidMediaTypeException.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
Example #13
Source File: InvalidMediaTypeException.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
Example #14
Source File: StompCodecTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test(expected = InvalidMimeTypeException.class)
public void decodeFrameWithInvalidContentType() {
	assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0");
}
 
Example #15
Source File: InvalidMediaTypeException.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
Example #16
Source File: StompDecoderTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test(expected = InvalidMimeTypeException.class)
public void decodeFrameWithInvalidContentType() {
	assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0");
}
 
Example #17
Source File: ContentTypeResolver.java    From java-technology-stack with MIT License 2 votes vote down vote up
/**
 * Determine the {@link MimeType} of a message from the given MessageHeaders.
 * @param headers the headers to use for the resolution
 * @return the resolved {@code MimeType}, or {@code null} if none found
 * @throws InvalidMimeTypeException if the content type is a String that cannot be parsed
 * @throws IllegalArgumentException if there is a content type but its type is unknown
 */
@Nullable
MimeType resolve(@Nullable MessageHeaders headers) throws InvalidMimeTypeException;
 
Example #18
Source File: ContentTypeResolver.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Determine the {@link MimeType} of a message from the given MessageHeaders.
 * @param headers the headers to use for the resolution
 * @return the resolved {@code MimeType}, or {@code null} if none found
 * @throws InvalidMimeTypeException if the content type is a String that cannot be parsed
 * @throws IllegalArgumentException if there is a content type but its type is unknown
 */
@Nullable
MimeType resolve(@Nullable MessageHeaders headers) throws InvalidMimeTypeException;