当前位置: 首页>>代码示例>>Java>>正文


Java HttpInputMessage类代码示例

本文整理汇总了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;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:18,代码来源:LoggregatorHttpMessageConverter.java

示例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);
	}
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:30,代码来源:VaultResponses.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:HttpPutFormContentFilter.java

示例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);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:AbstractWireFeedHttpMessageConverter.java

示例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.");
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:SourceHttpMessageConverter.java

示例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();
    }
}
 
开发者ID:PatternFM,项目名称:tokamak,代码行数:25,代码来源:RestExceptionRenderer.java

示例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("不支持的返回类型");
    }
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:23,代码来源:WxMediaResourceMessageConverter.java

示例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);
    }
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:31,代码来源:WxApiResponseExtractor.java

示例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);
}
 
开发者ID:FastBootWeixin,项目名称:FastBootWeixin,代码行数:21,代码来源:WxApiMessageConverterExtractor.java

示例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() + ".");
}
 
开发者ID:bobxwang,项目名称:springboot-scala-withswagger,代码行数:18,代码来源:ProtostuffHttpMessageConverter.java

示例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);
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:18,代码来源:FastJsonGenericHttpMessageConverter.java

示例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);
}
 
开发者ID:hs-web,项目名称:hsweb-framework,代码行数:19,代码来源:FastJsonHttpMessageConverter.java

示例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();
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:AnnotationMethodHandlerAdapter.java


注:本文中的org.springframework.http.HttpInputMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。