本文整理匯總了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();
}
}