本文整理汇总了Java中org.springframework.http.HttpInputMessage类的典型用法代码示例。如果您正苦于以下问题:Java HttpInputMessage类的具体用法?Java HttpInputMessage怎么用?Java HttpInputMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpInputMessage类属于org.springframework.http包,在下文中一共展示了HttpInputMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
protected ApplicationLogs readInternal(Class<? extends ApplicationLogs> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
String boundary = getMessageBoundary(inputMessage);
Multipart multipart = new Multipart(inputMessage.getBody(), boundary);
ApplicationLogs logs = new ApplicationLogs();
Multipart.Part part;
while ((part = multipart.nextPart()) != null) {
ApplicationLog log = messageParser.parseMessage(part.getContent());
logs.add(log);
}
return logs;
}
示例2: EmptyBodyCheckingHttpInputMessage
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
public EmptyBodyCheckingHttpInputMessage(HttpInputMessage inputMessage) throws IOException {
this.headers = inputMessage.getHeaders();
InputStream inputStream = inputMessage.getBody();
if (inputStream == null) {
this.body = null;
}
else if (inputStream.markSupported()) {
inputStream.mark(1);
this.body = (inputStream.read() != -1 ? inputStream : null);
inputStream.reset();
}
else {
PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);
int b = pushbackInputStream.read();
if (b == -1) {
this.body = null;
}
else {
this.body = pushbackInputStream;
pushbackInputStream.unread(b);
}
}
this.method = ((HttpRequest) inputMessage).getMethod();
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AbstractMessageConverterMethodArgumentResolver.java
示例3: unwrap
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
/**
* Unwrap a wrapped response created by Vault Response Wrapping
*
* @param wrappedResponse the wrapped response , must not be empty or {@literal null}.
* @param responseType the type of the return value.
* @return the unwrapped response.
*/
@SuppressWarnings("unchecked")
public static <T> T unwrap(final String wrappedResponse, Class<T> responseType) {
Assert.hasText(wrappedResponse, "Wrapped response must not be empty");
try {
return (T) converter.read(responseType, new HttpInputMessage() {
@Override
public InputStream getBody() throws IOException {
return new ByteArrayInputStream(wrappedResponse.getBytes());
}
@Override
public HttpHeaders getHeaders() {
return new HttpHeaders();
}
});
}
catch (IOException e) {
throw new IllegalStateException(e);
}
}
示例4: readJavaType
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@SuppressWarnings("deprecation")
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
try {
if (inputMessage instanceof MappingJacksonInputMessage) {
Class<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
if (deserializationView != null) {
return this.objectMapper.readerWithView(deserializationView).withType(javaType).
readValue(inputMessage.getBody());
}
}
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
}
catch (IOException ex) {
throw new HttpMessageNotReadableException("Could not read document: " + ex.getMessage(), ex);
}
}
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:17,代码来源:AbstractJackson2HttpMessageConverter.java
示例5: doFilterInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
protected void doFilterInternal(final HttpServletRequest request, HttpServletResponse response,
FilterChain filterChain) throws ServletException, IOException {
if (("PUT".equals(request.getMethod()) || "PATCH".equals(request.getMethod())) && isFormContentType(request)) {
HttpInputMessage inputMessage = new ServletServerHttpRequest(request) {
@Override
public InputStream getBody() throws IOException {
return request.getInputStream();
}
};
MultiValueMap<String, String> formParameters = formConverter.read(null, inputMessage);
HttpServletRequest wrapper = new HttpPutFormContentRequestWrapper(request, formParameters);
filterChain.doFilter(wrapper, response);
}
else {
filterChain.doFilter(request, response);
}
}
示例6: readInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
WireFeedInput feedInput = new WireFeedInput();
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset;
if (contentType != null && contentType.getCharSet() != null) {
charset = contentType.getCharSet();
} else {
charset = DEFAULT_CHARSET;
}
try {
Reader reader = new InputStreamReader(inputMessage.getBody(), charset);
return (T) feedInput.build(reader);
}
catch (FeedException ex) {
throw new HttpMessageNotReadableException("Could not read WireFeed: " + ex.getMessage(), ex);
}
}
示例7: readInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.class.equals(clazz)) {
return (T) readDOMSource(body);
}
else if (SAXSource.class.equals(clazz)) {
return (T) readSAXSource(body);
}
else if (StAXSource.class.equals(clazz)) {
return (T) readStAXSource(body);
}
else if (StreamSource.class.equals(clazz) || Source.class.equals(clazz)) {
return (T) readStreamSource(body);
}
else {
throw new HttpMessageConversionException("Could not read class [" + clazz +
"]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.");
}
}
示例8: handleHttpEntityResponse
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
public void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
if (responseEntity == null) {
return;
}
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
if (responseEntity instanceof ResponseEntity && outputMessage instanceof ServerHttpResponse) {
((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
}
HttpHeaders entityHeaders = responseEntity.getHeaders();
if (!entityHeaders.isEmpty()) {
outputMessage.getHeaders().putAll(entityHeaders);
}
Object body = responseEntity.getBody();
if (body != null) {
writeWithMessageConverters(body, inputMessage, outputMessage);
}
else {
outputMessage.getBody();
}
}
示例9: readInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
protected Resource readInternal(Class<? extends Resource> clazz, HttpInputMessage inputMessage)
throws IOException, HttpMessageNotReadableException {
WxMediaResource wxMediaResource = new WxMediaResource(inputMessage);
if (wxMediaResource.isUrlMedia() && !clazz.isAssignableFrom(WxMediaResource.class)) {
throw new WxApiException("不支持的返回类型,接口返回了url");
}
if (InputStreamResource.class == clazz) {
return new InputStreamResource(wxMediaResource.getInputStream());
} else if (clazz.isAssignableFrom(WxMediaResource.class)) {
return wxMediaResource;
} else if (clazz.isAssignableFrom(ByteArrayResource.class)) {
return new ByteArrayResource(wxMediaResource.getBody());
} else if (clazz.isAssignableFrom(FileSystemResource.class)) {
return new FileSystemResource(wxMediaResource.getFile());
}
// else if (clazz.isAssignableFrom(File.class)) {
// return wxMediaResource.getFile();
// }
throw new WxApiException("不支持的返回类型");
}
示例10: extractData
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
public <T> T extractData(ResponseEntity<HttpInputMessage> responseEntity, Class<T> returnType) {
// 本来应该有response数据为空的判断的,其实这里已经被前一步的restTemplate获取中判断过了,这里只用判断body为空即可
if (returnType == null || void.class == returnType || Void.class == returnType || responseEntity.getBody() == null) {
return null;
}
/* 先不管文件
if (WxWebUtils.isMutlipart(returnType)) {
return null;
}
不是不管文件,而是可以被messageConverter处理了
*/
WxApiMessageConverterExtractor<T> delegate = delegates.get(returnType);
if (delegate == null) {
delegate = new WxApiMessageConverterExtractor(returnType, converters);
delegates.put(returnType, delegate);
}
// 这里遇到了个坑,很长时间没玩过IO了,这个坑就和IO相关,每次提取数据时都抛出IO异常,IO已关闭
// 本来以为是我的error判断那里提前读了IO导致后来IO关闭了,调试后发现真正原因,因为
// ResponseEntity<HttpInputMessage> responseEntity = wxApiInvoker.exchange(requestEntity, HttpInputMessage.class);
// 上面代码执行结束后,有个finally,就是用于关闭response的,也就是说,一旦执行结束就无法再执行提取数据的操作了
// 所以我只能把WxHttpInputMessageConverter里返回的inputStream包装一下了
// 这里还涉及一个问题,是否有必要把所有消息都返回inputStream?当然没有必要,只要特定几种类型返回InputStream
// 其他类型直接转换即可。
try {
return delegate.extractData(responseEntity);
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new WxApiResponseException("提取数据时发生IO异常", responseEntity);
}
}
示例11: extractData
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
public T extractData(ResponseEntity<HttpInputMessage> responseEntity) throws IOException {
MediaType contentType = getContentType(responseEntity);
for (HttpMessageConverter<?> messageConverter : this.messageConverters) {
if (messageConverter instanceof GenericHttpMessageConverter) {
GenericHttpMessageConverter<?> genericMessageConverter =
(GenericHttpMessageConverter<?>) messageConverter;
if (genericMessageConverter.canRead(this.responseType, null, contentType)) {
return (T) genericMessageConverter.read(this.responseType, null, responseEntity.getBody());
}
}
if (this.responseClass != null) {
if (messageConverter.canRead(this.responseClass, contentType)) {
return (T) messageConverter.read((Class) this.responseClass, responseEntity.getBody());
}
}
}
throw new WxApiResponseException("不能转换相应数据为类型:" + this.responseType, responseEntity);
}
示例12: readInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
if (MEDIA_TYPE.isCompatibleWith(contentType)) {
final Schema<?> schema = getSchema(clazz);
final Object value = schema.newMessage();
try (final InputStream stream = inputMessage.getBody()) {
ProtobufIOUtil.mergeFrom(stream, value, (Schema<Object>) schema);
return value;
}
}
throw new HttpMessageNotReadableException(
"Unrecognized HTTP media type " + inputMessage.getHeaders().getContentType().getType() + ".");
}
示例13: read
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
public Object read(Type type, Class<?> contextClass, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = inputMessage.getBody();
byte[] buf = new byte[1024];
for (; ; ) {
int len = in.read(buf);
if (len == -1) {
break;
}
if (len > 0) {
baos.write(buf, 0, len);
}
}
byte[] bytes = baos.toByteArray();
return readByBytes(type, bytes);
}
示例14: readInternal
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
@Override
protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException,
HttpMessageNotReadableException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream in = inputMessage.getBody();
byte[] buf = new byte[1024];
for (; ; ) {
int len = in.read(buf);
if (len == -1) {
break;
}
if (len > 0) {
baos.write(buf, 0, len);
}
}
byte[] bytes = baos.toByteArray();
return readByBytes(clazz, bytes);
}
示例15: handleHttpEntityResponse
import org.springframework.http.HttpInputMessage; //导入依赖的package包/类
private void handleHttpEntityResponse(HttpEntity<?> responseEntity, ServletWebRequest webRequest) throws Exception {
if (responseEntity == null) {
return;
}
HttpInputMessage inputMessage = createHttpInputMessage(webRequest);
HttpOutputMessage outputMessage = createHttpOutputMessage(webRequest);
if (responseEntity instanceof ResponseEntity && outputMessage instanceof ServerHttpResponse) {
((ServerHttpResponse) outputMessage).setStatusCode(((ResponseEntity<?>) responseEntity).getStatusCode());
}
HttpHeaders entityHeaders = responseEntity.getHeaders();
if (!entityHeaders.isEmpty()) {
outputMessage.getHeaders().putAll(entityHeaders);
}
Object body = responseEntity.getBody();
if (body != null) {
writeWithMessageConverters(body, inputMessage, outputMessage);
}
else {
// flush headers
outputMessage.getBody();
}
}