类org.springframework.util.InvalidMimeTypeException源码实例Demo

下面列出了怎么用org.springframework.util.InvalidMimeTypeException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: spring-analysis-note   文件: StompDecoder.java
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;
		}
	}
}
 
@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);
}
 
源代码3 项目: java-technology-stack   文件: StompDecoder.java
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;
		}
	}
}
 
@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);
}
 
源代码5 项目: spring4-understanding   文件: StompDecoder.java
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);
}
 
源代码7 项目: dhis2-core   文件: FileResourceUtils.java
/**
 * 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;
}
 
源代码8 项目: gocd   文件: ApiController.java
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;
    }
}
 
源代码9 项目: gocd   文件: MockHttpServletResponseAssert.java
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;
}
 
源代码10 项目: spring-analysis-note   文件: StompDecoderTests.java
@Test(expected = InvalidMimeTypeException.class)
public void decodeFrameWithInvalidContentType() {
	assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0");
}
 
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
源代码12 项目: java-technology-stack   文件: StompDecoderTests.java
@Test(expected = InvalidMimeTypeException.class)
public void decodeFrameWithInvalidContentType() {
	assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0");
}
 
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
源代码14 项目: lams   文件: InvalidMediaTypeException.java
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
源代码15 项目: spring4-understanding   文件: StompCodecTests.java
@Test(expected = InvalidMimeTypeException.class)
public void decodeFrameWithInvalidContentType() {
	assertIncompleteDecode("SEND\ncontent-type:text/plain;charset=U\n\nThe body\0");
}
 
/**
 * Constructor that allows wrapping {@link InvalidMimeTypeException}.
 */
InvalidMediaTypeException(InvalidMimeTypeException ex) {
	super(ex.getMessage(), ex);
	this.mediaType = ex.getMimeType();
}
 
源代码17 项目: spring-analysis-note   文件: ContentTypeResolver.java
/**
 * 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;
 
/**
 * 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;
 
 类所在包
 类方法
 同包方法