Here are the examples of the java api org.springframework.http.HttpInputMessage.getBody() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
62 Examples
19
Source : HttpTunnelPayload.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
/**
* Return the {@link HttpTunnelPayload} for the given message or {@code null} if there
* is no payload.
* @param message the HTTP message
* @return the payload or {@code null}
* @throws IOException in case of I/O errors
*/
public static HttpTunnelPayload get(HttpInputMessage message) throws IOException {
long length = message.getHeaders().getContentLength();
if (length <= 0) {
return null;
}
String seqHeader = message.getHeaders().getFirst(SEQ_HEADER);
replacedert.state(StringUtils.hasLength(seqHeader), "Missing sequence header");
ReadableByteChannel body = Channels.newChannel(message.getBody());
ByteBuffer payload = ByteBuffer.allocate((int) length);
while (payload.hasRemaining()) {
body.read(payload);
}
body.close();
payload.flip();
return new HttpTunnelPayload(Long.valueOf(seqHeader), payload);
}
19
Source : MutipartMixedConverterUnitTest.java
with Apache License 2.0
from xm-online
with Apache License 2.0
from xm-online
@Test
public void testRead() throws IOException {
when(httpInputMessage.getHeaders()).thenReturn(httpHeaders);
when(httpInputMessage.getBody()).thenReturn(IOUtils.toInputStream("text=value", Charsets.UTF_8));
MultiValueMap<String, String> result = multipartMixedConverter.read(null, httpInputMessage);
replacedertEquals("value", result.getFirst("text"));
}
19
Source : MultipartMixedConverter.java
with Apache License 2.0
from xm-online
with Apache License 2.0
from xm-online
@Override
public MultiValueMap<String, String> read(Clreplaced<? extends MultiValueMap<String, ?>> clazz, HttpInputMessage inputMessage) throws IOException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = contentType.getCharset() != null ? contentType.getCharset() : this.defaultCharset;
String body = StreamUtils.copyToString(inputMessage.getBody(), charset);
String[] pairs = StringUtils.tokenizeToStringArray(body, "&");
MultiValueMap<String, String> result = new LinkedMultiValueMap<>(pairs.length);
for (String pair : pairs) {
int idx = pair.indexOf('=');
if (idx == -1) {
result.add(URLDecoder.decode(pair, charset.name()), null);
} else {
String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
result.add(name, value);
}
}
return result;
}
19
Source : StringHttpMessageConverter.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
protected String readInternal(Clreplaced<? extends String> clazz, HttpInputMessage inputMessage) throws IOException {
Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
return StreamUtils.copyToString(inputMessage.getBody(), charset);
}
19
Source : AbstractJackson2HttpMessageConverter.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) throws IOException {
try {
if (inputMessage instanceof MappingJacksonInputMessage) {
Clreplaced<?> deserializationView = ((MappingJacksonInputMessage) inputMessage).getDeserializationView();
if (deserializationView != null) {
return this.objectMapper.readerWithView(deserializationView).forType(javaType).readValue(inputMessage.getBody());
}
}
return this.objectMapper.readValue(inputMessage.getBody(), javaType);
} catch (InvalidDefinitionException ex) {
throw new HttpMessageConversionException("Type definition error: " + ex.getType(), ex);
} catch (JsonProcessingException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getOriginalMessage(), ex, inputMessage);
}
}
19
Source : FormHttpMessageConverter.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
public MultiValueMap<String, String> read(@Nullable Clreplaced<? extends MultiValueMap<String, ?>> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = (contentType != null && contentType.getCharset() != null ? contentType.getCharset() : this.charset);
String body = StreamUtils.copyToString(inputMessage.getBody(), charset);
String[] pairs = StringUtils.tokenizeToStringArray(body, "&");
MultiValueMap<String, String> result = new LinkedMultiValueMap<>(pairs.length);
for (String pair : pairs) {
int idx = pair.indexOf('=');
if (idx == -1) {
result.add(URLDecoder.decode(pair, charset.name()), null);
} else {
String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
result.add(name, value);
}
}
return result;
}
19
Source : FastJsonHttpMessageConverter.java
with Apache License 2.0
from uavorg
with Apache License 2.0
from uavorg
private Object readType(Type type, HttpInputMessage inputMessage) throws IOException {
try {
InputStream in = inputMessage.getBody();
return JSON.parseObject(in, fastJsonConfig.getCharset(), type, fastJsonConfig.getFeatures());
} catch (JSONException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new HttpMessageNotReadableException("I/O error while reading input message", ex);
}
}
19
Source : EncrypConverter.java
with Apache License 2.0
from Lengchuan
with Apache License 2.0
from Lengchuan
/**
* 重写read()方法
*
* @param type
* @param contextClreplaced
* @param inputMessage
* @return
* @throws IOException
* @throws HttpMessageNotReadableException
*/
@Override
public Object read(Type type, Clreplaced<?> contextClreplaced, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
InputStream in = inputMessage.getBody();
byte[] data = Base64.decode(IOUtils.toString(in, "UTF-8"));
return JSON.parseObject(data, 0, data.length, getFastJsonConfig().getCharset(), type, getFastJsonConfig().getFeatures());
}
19
Source : EncrypConverter.java
with Apache License 2.0
from Lengchuan
with Apache License 2.0
from Lengchuan
/**
* 重写readInternal
*
* @param clazz
* @param inputMessage
* @return
* @throws IOException
* @throws HttpMessageNotReadableException
*/
@Override
protected Object readInternal(Clreplaced<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
InputStream in = inputMessage.getBody();
byte[] data = Base64.decode(IOUtils.toString(in, "UTF-8"));
return JSON.parseObject(data, 0, data.length, getFastJsonConfig().getCharset(), clazz, getFastJsonConfig().getFeatures());
}
19
Source : ProtobufHttpMessageConverter.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Override
protected Message readInternal(Clreplaced<? extends Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
contentType = (contentType != null ? contentType : PROTOBUF);
Charset charset = getCharset(inputMessage.getHeaders());
InputStreamReader reader = new InputStreamReader(inputMessage.getBody(), charset);
try {
Message.Builder builder = getMessageBuilder(clazz);
if (MediaType.APPLICATION_JSON.isCompatibleWith(contentType)) {
JsonFormat.merge(reader, this.extensionRegistry, builder);
} else if (MediaType.TEXT_PLAIN.isCompatibleWith(contentType)) {
TextFormat.merge(reader, this.extensionRegistry, builder);
} else if (MediaType.APPLICATION_XML.isCompatibleWith(contentType)) {
XmlFormat.merge(reader, this.extensionRegistry, builder);
} else {
builder.mergeFrom(inputMessage.getBody(), this.extensionRegistry);
}
return builder.build();
} catch (Exception e) {
throw new HttpMessageNotReadableException("Could not read Protobuf message: " + e.getMessage(), e);
}
}
19
Source : AbstractJackson2HttpMessageConverter.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@SuppressWarnings("deprecation")
private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) {
try {
if (inputMessage instanceof MappingJacksonInputMessage) {
Clreplaced<?> 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 doreplacedent: " + ex.getMessage(), ex);
}
}
19
Source : FormHttpMessageConverter.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Override
public MultiValueMap<String, String> read(Clreplaced<? extends MultiValueMap<String, ?>> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
Charset charset = (contentType.getCharSet() != null ? contentType.getCharSet() : this.charset);
String body = StreamUtils.copyToString(inputMessage.getBody(), charset);
String[] pairs = StringUtils.tokenizeToStringArray(body, "&");
MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(pairs.length);
for (String pair : pairs) {
int idx = pair.indexOf('=');
if (idx == -1) {
result.add(URLDecoder.decode(pair, charset.name()), null);
} else {
String name = URLDecoder.decode(pair.substring(0, idx), charset.name());
String value = URLDecoder.decode(pair.substring(idx + 1), charset.name());
result.add(name, value);
}
}
return result;
}
19
Source : HttpTunnelPayload.java
with Apache License 2.0
from hello-shf
with Apache License 2.0
from hello-shf
/**
* Return the {@link HttpTunnelPayload} for the given message or {@code null} if there
* is no payload.
*
* @param message the HTTP message
* @return the payload or {@code null}
* @throws IOException in case of I/O errors
*/
public static HttpTunnelPayload get(HttpInputMessage message) throws IOException {
long length = message.getHeaders().getContentLength();
if (length <= 0) {
return null;
}
String seqHeader = message.getHeaders().getFirst(SEQ_HEADER);
replacedert.state(StringUtils.hasLength(seqHeader), "Missing sequence header");
ReadableByteChannel body = Channels.newChannel(message.getBody());
ByteBuffer payload = ByteBuffer.allocate((int) length);
while (payload.hasRemaining()) {
body.read(payload);
}
body.close();
payload.flip();
return new HttpTunnelPayload(Long.valueOf(seqHeader), payload);
}
19
Source : JsonConverter.java
with Apache License 2.0
from Frodez
with Apache License 2.0
from Frodez
@Override
public Object read(Type type, @Nullable Clreplaced<?> contextClreplaced, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
return JSONUtil.as(inputMessage.getBody(), GenericTypeResolver.resolveType(type, contextClreplaced));
}
19
Source : JsonConverter.java
with Apache License 2.0
from Frodez
with Apache License 2.0
from Frodez
@Override
protected Object readInternal(Clreplaced<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
return JSONUtil.as(inputMessage.getBody(), clazz);
}
19
Source : SecretRequestAdvice.java
with Apache License 2.0
from faster-framework
with Apache License 2.0
from faster-framework
/**
* 解密消息体,3des解析(cbc模式)
*
* @param inputMessage 消息体
* @return 明文
*/
private String decryptBody(HttpInputMessage inputMessage) throws IOException {
InputStream encryptStream = inputMessage.getBody();
String encryptBody = StreamUtils.copyToString(encryptStream, Charset.defaultCharset());
return DesCbcUtil.decode(encryptBody, secretProperties.getDesSecretKey(), secretProperties.getDesIv());
}
19
Source : FastJsonHttpMessageConverter.java
with Apache License 2.0
from fangjinuo
with Apache License 2.0
from fangjinuo
private Object readType(Type type, HttpInputMessage inputMessage) {
try {
InputStream in = inputMessage.getBody();
return JSON.parseObject(in, fastJsonConfig.getCharset(), type, fastJsonConfig.getParserConfig(), fastJsonConfig.getParseProcess(), JSON.DEFAULT_PARSER_FEATURE, fastJsonConfig.getFeatures());
} catch (JSONException ex) {
throw new HttpMessageNotReadableException("JSON parse error: " + ex.getMessage(), ex);
} catch (IOException ex) {
throw new HttpMessageNotReadableException("I/O error while reading input message", ex);
}
}
19
Source : ProtobufHttpMessageConverter.java
with Apache License 2.0
from eu-federation-gateway-service
with Apache License 2.0
from eu-federation-gateway-service
@Override
protected Message readInternal(Clreplaced<? extends Message> clazz, HttpInputMessage httpInputMessage) throws IOException {
MediaType contentType = httpInputMessage.getHeaders().getContentType();
if (contentType == null) {
log.error("Accept must be set");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Content Type must not be null!");
}
MediaType targetContentType = null;
String targetContentTypeVersion = null;
if (PROTOBUF_MEDIA_TYPE.isCompatibleWith(contentType)) {
targetContentType = PROTOBUF_MEDIA_TYPE;
targetContentTypeVersion = properties.getContentNegotiation().getProtobufVersion();
} else if (JSON_MEDIA_TYPE.isCompatibleWith(contentType)) {
targetContentType = JSON_MEDIA_TYPE;
targetContentTypeVersion = properties.getContentNegotiation().getJsonVersion();
}
EfgsMdc.put("requestedMediaType", contentType.toString());
if (targetContentType == null) {
log.error("Accepted Content-Type is not compatible");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unknown Content-Type!");
}
if (contentType.getParameter(VERSION_STRING) == null) {
log.error("Version parameter of Accepted Content-Type is required");
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Version parameter of Content-Type is required!");
}
try {
if (!SemVerUtils.parseSemVerAndCheckCompatibility(targetContentTypeVersion, contentType.getParameter(VERSION_STRING))) {
log.error("Serialization: Protocol version is not compatible");
throw new ResponseStatusException(HttpStatus.NOT_ACCEPTABLE, "Protocol version is not compatible!");
}
} catch (SemVerUtils.SemVerParsingException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
}
Message.Builder builder;
try {
builder = (Message.Builder) clazz.getMethod("newBuilder").invoke(clazz);
} catch (IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid Protobuf Message type: no invocable newBuilder() method on " + clazz);
}
if (targetContentType == PROTOBUF_MEDIA_TYPE) {
return builder.mergeFrom(httpInputMessage.getBody()).build();
} else {
ProtobufFormatter formatter = new ProtobufConverter();
formatter.merge(httpInputMessage.getBody(), builder);
return builder.build();
}
}
19
Source : AbstractMessageConverter.java
with MIT License
from dlcs
with MIT License
from dlcs
private String consume(HttpInputMessage inputMessage) throws IOException {
InputStream messageInputStream = inputMessage.getBody();
return IOUtils.toString(messageInputStream, Charset.defaultCharset());
}
19
Source : PartialUpdateArgumentResolver.java
with GNU General Public License v3.0
from countrogue
with GNU General Public License v3.0
from countrogue
private Object readJavaType(Object object, HttpInputMessage inputMessage) {
try {
return this.objectMapper.readerForUpdating(object).readValue(inputMessage.getBody());
} catch (IOException ex) {
throw new HttpMessageNotReadableException("Could not read doreplacedent: " + ex.getMessage(), ex);
}
}
19
Source : QqAccessTokenResponseHttpMessageConverter.java
with MIT License
from blocklang
with MIT License
from blocklang
@Override
protected OAuth2AccessTokenResponse readInternal(Clreplaced<? extends OAuth2AccessTokenResponse> clazz, HttpInputMessage inputMessage) throws HttpMessageNotReadableException {
try {
String body = StreamUtils.copyToString(inputMessage.getBody(), Charset.defaultCharset());
Map<String, String> tokenResponseParameters = new HashMap<String, String>();
Pattern pattern = Pattern.compile("(?<key>\\w+)=(?<value>\\w+)");
Matcher matcher = pattern.matcher(body);
while (matcher.find()) {
String key = matcher.group("key");
String value = matcher.group("value");
tokenResponseParameters.put(key, value);
}
// qq 的返回值中没有 tokenType
tokenResponseParameters.put(OAuth2ParameterNames.TOKEN_TYPE, OAuth2AccessToken.TokenType.BEARER.getValue());
return this.tokenResponseConverter.convert(tokenResponseParameters);
} catch (Exception ex) {
logger.error("An error occurred reading the OAuth 2.0 Access Token Response: ", ex);
throw new HttpMessageNotReadableException("An error occurred reading the OAuth 2.0 Access Token Response: " + ex.getMessage(), ex, inputMessage);
}
}
19
Source : MutableHttpServerRequest.java
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
@Override
public InputStream getBody() throws IOException {
return httpInputMessage.getBody();
}
18
Source : PropertiesHttpMessageConverter.java
with MIT License
from wuyouzhuguli
with MIT License
from wuyouzhuguli
@Override
protected Properties readInternal(Clreplaced<? extends Properties> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
Properties properties = new Properties();
// 获取请求头
HttpHeaders headers = inputMessage.getHeaders();
// 获取 content-type
MediaType contentType = headers.getContentType();
// 获取编码
Charset charset = null;
if (contentType != null) {
charset = contentType.getCharset();
}
charset = charset == null ? Charset.forName("UTF-8") : charset;
// 获取请求体
InputStream body = inputMessage.getBody();
InputStreamReader inputStreamReader = new InputStreamReader(body, charset);
properties.load(inputStreamReader);
return properties;
}
18
Source : SourceHttpMessageConverter.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Clreplaced<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.clreplaced == clazz) {
return (T) readDOMSource(body, inputMessage);
} else if (SAXSource.clreplaced == clazz) {
return (T) readSAXSource(body, inputMessage);
} else if (StAXSource.clreplaced == clazz) {
return (T) readStAXSource(body, inputMessage);
} else if (StreamSource.clreplaced == clazz || Source.clreplaced == clazz) {
return (T) readStreamSource(body);
} else {
throw new HttpMessageNotReadableException("Could not read clreplaced [" + clazz + "]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.", inputMessage);
}
}
18
Source : ProtobufHttpMessageConverter.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
protected Message readInternal(Clreplaced<? extends Message> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
MediaType contentType = inputMessage.getHeaders().getContentType();
if (contentType == null) {
contentType = PROTOBUF;
}
Charset charset = contentType.getCharset();
if (charset == null) {
charset = DEFAULT_CHARSET;
}
Message.Builder builder = getMessageBuilder(clazz);
if (PROTOBUF.isCompatibleWith(contentType)) {
builder.mergeFrom(inputMessage.getBody(), this.extensionRegistry);
} else if (TEXT_PLAIN.isCompatibleWith(contentType)) {
InputStreamReader reader = new InputStreamReader(inputMessage.getBody(), charset);
TextFormat.merge(reader, this.extensionRegistry, builder);
} else if (this.protobufFormatSupport != null) {
this.protobufFormatSupport.merge(inputMessage.getBody(), charset, contentType, this.extensionRegistry, builder);
}
return builder.build();
}
18
Source : Log4jFastJsonHttpMessageConverter.java
with BSD 3-Clause "New" or "Revised" License
from ueboot
with BSD 3-Clause "New" or "Revised" License
from ueboot
@Override
protected Object readInternal(Clreplaced<? extends Object> 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();
String jsonStr = new String(bytes);
// 防止xss攻击,sql注入
XSSNotCheck notCheck = clazz.getAnnotation(XSSNotCheck.clreplaced);
// 加了注解则不进行xss字段拦截
if (notCheck == null) {
jsonStr = XSSUtil.checkXssStr(jsonStr);
} else {
log.warn("当前类:{}标注无需进行xss字段拦截,注意安全!", clazz.getName());
}
bytes = jsonStr.getBytes();
NotLog notLog = clazz.getAnnotation(NotLog.clreplaced);
if (notLog == null) {
log.info("Request Clreplaced:{},json:{}", clazz.getName(), jsonStr);
}
Object reqBody = JSON.parseObject(bytes, 0, bytes.length, charset.newDecoder(), clazz);
Set<ConstraintViolation<Object>> validRetval = this.getValidator().validate(reqBody);
// 自定义处理校验结论
if (!httpRequestValidatorService.doValidatorMsg(validRetval)) {
StringBuilder sb = new StringBuilder();
// 校验失败
if (!validRetval.isEmpty()) {
for (ConstraintViolation<Object> t : validRetval) {
sb.append(t.getPropertyPath()).append(t.getMessage()).append(",");
}
}
String checkError = sb.toString();
if (!isEmpty(checkError)) {
checkError = "请求参数格式校验不通过:" + checkError;
throw new BusinessException(checkError);
}
}
httpRequestValidatorService.validator(jsonStr, clazz);
return reqBody;
}
18
Source : FastJsonHttpMessageConverter.java
with GNU Affero General Public License v3.0
from stategen
with GNU Affero General Public License v3.0
from stategen
@Override
public Object read(Type type, Clreplaced<?> contextClreplaced, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
type = getType(type, contextClreplaced);
// fastjson直接读取String
if (type == String.clreplaced) {
InputStream is = inputMessage.getBody();
FastJsonConfig fastJsonConfig = getFastJsonConfig();
Charset charset = fastJsonConfig.getCharset();
charset = OptionalUtil.ifNull(charset, IOUtils.UTF8);
ByteBuffer byteBuffer = getByteBuffer(is);
String result = new String(byteBuffer.array(), byteBuffer.arrayOffset(), byteBuffer.limit(), charset);
if (logger.isDebugEnabled()) {
logger.debug(new StringBuilder("==>fastjson read plain text:\n").append(result).toString());
}
return result;
}
return super.read(type, contextClreplaced, inputMessage);
}
18
Source : ProtostuffHttpMessageConverter.java
with Apache License 2.0
from smart-cloud
with Apache License 2.0
from smart-cloud
@Override
protected Object readInternal(Clreplaced<?> clazz, HttpInputMessage inputMessage) throws IOException {
return SerializingUtil.deserialize(inputMessage.getBody(), clazz);
}
18
Source : MessageConverter.java
with MIT License
from mouradski
with MIT License
from mouradski
@Override
public Trade[] read(Clreplaced<? extends Trade[]> aClreplaced, HttpInputMessage httpInputMessage) throws IOException, HttpMessageNotReadableException {
String json = IOUtils.toString(httpInputMessage.getBody(), StandardCharsets.UTF_8.name());
return new ObjectMapper().readValue(json, Trade[].clreplaced);
}
18
Source : MessageConverter.java
with MIT License
from mouradski
with MIT License
from mouradski
@Override
public Response read(Clreplaced<? extends Response> aClreplaced, HttpInputMessage httpInputMessage) throws IOException, HttpMessageNotReadableException {
String json = IOUtils.toString(httpInputMessage.getBody(), StandardCharsets.UTF_8.name());
return new ObjectMapper().readValue(json, Response.clreplaced);
}
18
Source : FastJsonHttpMessageConverter.java
with Apache License 2.0
from mcg-helper
with Apache License 2.0
from mcg-helper
@Override
public Object read(Type type, Clreplaced<?> contextClreplaced, 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();
this.readBefore(bytes);
Object obj = JSON.parseObject(bytes, 0, bytes.length, charset.newDecoder(), type);
this.readAfter(obj);
return obj;
}
18
Source : FastJsonHttpMessageConverter.java
with Apache License 2.0
from mcg-helper
with Apache License 2.0
from mcg-helper
@Override
protected Object readInternal(Clreplaced<? extends Object> 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();
this.readBefore(bytes);
Object obj = JSON.parseObject(bytes, 0, bytes.length, charset.newDecoder(), clazz);
this.readAfter(obj);
return obj;
}
18
Source : SourceHttpMessageConverter.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Override
@SuppressWarnings("unchecked")
protected T readInternal(Clreplaced<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
InputStream body = inputMessage.getBody();
if (DOMSource.clreplaced == clazz) {
return (T) readDOMSource(body);
} else if (SAXSource.clreplaced == clazz) {
return (T) readSAXSource(body);
} else if (StAXSource.clreplaced == clazz) {
return (T) readStAXSource(body);
} else if (StreamSource.clreplaced == clazz || Source.clreplaced == clazz) {
return (T) readStreamSource(body);
} else {
throw new HttpMessageConversionException("Could not read clreplaced [" + clazz + "]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported.");
}
}
18
Source : WxHttpInputMessageConverter.java
with Apache License 2.0
from FastBootWeixin
with Apache License 2.0
from FastBootWeixin
@Override
protected void writeInternal(HttpInputMessage httpInputMessage, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException {
StreamUtils.copy(httpInputMessage.getBody(), outputMessage.getBody());
}
18
Source : DataStreamSerializableMessageConverter.java
with BSD 3-Clause "New" or "Revised" License
from dhis2
with BSD 3-Clause "New" or "Revised" License
from dhis2
@Override
public DataStreamSerializable read(Clreplaced<? extends DataStreamSerializable> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
return DataStreamSerializer.read(clazz, inputMessage.getBody());
}
18
Source : FederationGatewayHttpMessageConverterTest.java
with Apache License 2.0
from covid-be-app
with Apache License 2.0
from covid-be-app
private static HttpInputMessage buildHttpInputMessage(byte[] body, String batchTag, String nextBatchTag) throws IOException {
HttpInputMessage message = mock(HttpInputMessage.clreplaced);
when(message.getBody()).thenReturn(new ByteArrayInputStream(body));
HttpHeaders headers = new HttpHeaders();
headers.add(CONTENT_TYPE, "application/protobuf; version=1.0");
headers.add("batchTag", batchTag);
headers.add("nextBatchTag", nextBatchTag);
when(message.getHeaders()).thenReturn(headers);
return message;
}
18
Source : FederationGatewayHttpMessageConverter.java
with Apache License 2.0
from covid-be-app
with Apache License 2.0
from covid-be-app
@Override
protected DiagnosisKeyBatch readInternal(Clreplaced<? extends DiagnosisKeyBatch> clazz, HttpInputMessage message) throws IOException {
try (InputStream body = message.getBody()) {
return DiagnosisKeyBatch.parseFrom(body);
} catch (InvalidProtocolBufferException e) {
throw new HttpMessageNotReadableException("Failed to parse protocol buffers message", e, message);
}
}
18
Source : XmlNamespaceIgnoringHttpMessageConverter.java
with Apache License 2.0
from cloudfoundry-incubator
with Apache License 2.0
from cloudfoundry-incubator
private Source createNamespaceSettingSource(Clreplaced<?> type, HttpInputMessage inputMessage, Unmarshaller unmarshaller) throws SAXException, ParserConfigurationException, IOException {
return replacedource(inputMessage.getBody(), createNamespaceSettingFilter(unmarshaller, type));
}
18
Source : JsonMergePatchHttpMessageConverter.java
with MIT License
from cassiomolin
with MIT License
from cassiomolin
@Override
protected JsonMergePatch readInternal(Clreplaced<? extends JsonMergePatch> clazz, HttpInputMessage inputMessage) throws HttpMessageNotReadableException {
try (JsonReader reader = Json.createReader(inputMessage.getBody())) {
return Json.createMergePatch(reader.readValue());
} catch (Exception e) {
throw new HttpMessageNotReadableException(e.getMessage(), inputMessage);
}
}
18
Source : QqOpenIdHttpMessageConverter.java
with MIT License
from blocklang
with MIT License
from blocklang
@Override
protected OAuth2OpenIdResponse readInternal(Clreplaced<? extends OAuth2OpenIdResponse> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
String body = StreamUtils.copyToString(inputMessage.getBody(), Charset.defaultCharset());
String jsonString = body.substring(10, body.length() - 2);
try {
return objectMapper.readValue(jsonString, OAuth2OpenIdResponse.clreplaced);
} catch (Exception ex) {
throw new HttpMessageNotReadableException("An error occurred reading the QQ open id Response: " + ex.getMessage(), ex, inputMessage);
}
}
18
Source : HttpConverterXml.java
with Apache License 2.0
from Accenture
with Apache License 2.0
from Accenture
@Override
public Object read(Clreplaced<?> clazz, HttpInputMessage inputMessage) throws HttpMessageNotReadableException {
// validate clreplaced with white list before loading the input stream
SimpleMapper.getInstance().getWhiteListMapper(clazz);
if (inputMessage != null) {
try {
SimpleXmlParser xml = new SimpleXmlParser();
Map<String, Object> map = xml.parse(inputMessage.getBody());
for (String key : map.keySet()) {
Object o = map.get(key);
if (o instanceof Map) {
return o;
}
}
return new HashMap<String, Object>();
} catch (IOException e) {
throw new IllegalArgumentException(e.getMessage());
}
} else {
return null;
}
}
17
Source : StringToResultHttpMessageConverter.java
with MIT License
from zidoshare
with MIT License
from zidoshare
@Override
protected String readInternal(Clreplaced<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType());
return StreamUtils.copyToString(inputMessage.getBody(), charset);
}
17
Source : Jaxb2CollectionHttpMessageConverter.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Override
@SuppressWarnings("unchecked")
public T read(Type type, @Nullable Clreplaced<?> contextClreplaced, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ParameterizedType parameterizedType = (ParameterizedType) type;
T result = createCollection((Clreplaced<?>) parameterizedType.getRawType());
Clreplaced<?> elementClreplaced = (Clreplaced<?>) parameterizedType.getActualTypeArguments()[0];
try {
Unmarshaller unmarshaller = createUnmarshaller(elementClreplaced);
XMLStreamReader streamReader = this.inputFactory.createXMLStreamReader(inputMessage.getBody());
int event = moveToFirstChildOfRootElement(streamReader);
while (event != XMLStreamReader.END_DOreplacedENT) {
if (elementClreplaced.isAnnotationPresent(XmlRootElement.clreplaced)) {
result.add(unmarshaller.unmarshal(streamReader));
} else if (elementClreplaced.isAnnotationPresent(XmlType.clreplaced)) {
result.add(unmarshaller.unmarshal(streamReader, elementClreplaced).getValue());
} else {
// should not happen, since we check in canRead(Type)
throw new HttpMessageNotReadableException("Cannot unmarshal to [" + elementClreplaced + "]", inputMessage);
}
event = moveToNextElement(streamReader);
}
return result;
} catch (XMLStreamException ex) {
throw new HttpMessageNotReadableException("Failed to read XML stream: " + ex.getMessage(), ex, inputMessage);
} catch (UnmarshalException ex) {
throw new HttpMessageNotReadableException("Could not unmarshal to [" + elementClreplaced + "]: " + ex.getMessage(), ex, inputMessage);
} catch (JAXBException ex) {
throw new HttpMessageConversionException("Invalid JAXB setup: " + ex.getMessage(), ex);
}
}
17
Source : ProtostuffHttpMessageConverter.java
with Apache License 2.0
from smart-cloud
with Apache License 2.0
from smart-cloud
@Override
public Object read(Type type, Clreplaced<?> contextClreplaced, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
Clreplaced<?> c = null;
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;
c = (Clreplaced<?>) parameterizedType.getRawType();
return SerializingUtil.deserialize(inputMessage.getBody(), c);
} else {
c = (Clreplaced<?>) type;
}
return SerializingUtil.deserialize(inputMessage.getBody(), c);
}
17
Source : SecretRequestAdvice.java
with Apache License 2.0
from mayee
with Apache License 2.0
from mayee
/**
* 解密消息体
*
* @param inputMessage 消息体
* @return 明文
*/
private String decryptBody(HttpInputMessage inputMessage, MethodParameter parameter) {
try {
InputStream encryptStream = inputMessage.getBody();
String encryptBody = StreamUtils.copyToString(encryptStream, Charset.defaultCharset());
if (log.isDebugEnabled()) {
log.debug("Decrypt body for input > {}", encryptBody);
}
SecretBody secretBodyAnnotation = (SecretBody) getAlgorithmValue(parameter);
if (secretBodyAnnotation != null) {
String algorithmName = secretBodyAnnotation.value();
String ciphertextType = secretBodyAnnotation.ciphertextType();
if (ALGORITHM_AES.equalsIgnoreCase(algorithmName)) {
AESKey aesKey = new AESKey(aesProperties.getKey());
AbstractRequestDecrypt requestDecrypt = new RequestAESDecrypt(ciphertextType, aesKey);
return requestDecrypt.decryptBody(encryptBody);
} else if (ALGORITHM_RSA.equalsIgnoreCase(algorithmName)) {
RSAKey rsaKey = new RSAKey(rsaProperties.getPublicKey(), rsaProperties.getPrivateKey(), rsaProperties.getModulus(), null);
Clreplaced<? extends Provider>[] providerClreplaced = secretBodyAnnotation.providerClreplaced();
if (providerClreplaced.length > 0) {
rsaKey.setProviderClreplaced(providerClreplaced[0]);
}
AbstractRequestDecrypt requestDecrypt = new RequestRSADecrypt(ciphertextType, rsaKey);
return requestDecrypt.decryptBody(encryptBody);
}
} else {
return encryptBody;
}
} catch (Exception e) {
log.warn(e.getMessage());
}
return null;
}
17
Source : MyMessageConverter.java
with Apache License 2.0
from longjiazuo
with Apache License 2.0
from longjiazuo
/**
* ③
*/
@Override
protected DemoObj readInternal(Clreplaced<? extends DemoObj> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
String temp = StreamUtils.copyToString(inputMessage.getBody(), Charset.forName("UTF-8"));
String[] tempArr = temp.split("-");
return new DemoObj(new Long(tempArr[0]), tempArr[1]);
}
17
Source : Jaxb2CollectionHttpMessageConverter.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
@Override
@SuppressWarnings("unchecked")
public T read(Type type, Clreplaced<?> contextClreplaced, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
ParameterizedType parameterizedType = (ParameterizedType) type;
T result = createCollection((Clreplaced<?>) parameterizedType.getRawType());
Clreplaced<?> elementClreplaced = (Clreplaced<?>) parameterizedType.getActualTypeArguments()[0];
try {
Unmarshaller unmarshaller = createUnmarshaller(elementClreplaced);
XMLStreamReader streamReader = this.inputFactory.createXMLStreamReader(inputMessage.getBody());
int event = moveToFirstChildOfRootElement(streamReader);
while (event != XMLStreamReader.END_DOreplacedENT) {
if (elementClreplaced.isAnnotationPresent(XmlRootElement.clreplaced)) {
result.add(unmarshaller.unmarshal(streamReader));
} else if (elementClreplaced.isAnnotationPresent(XmlType.clreplaced)) {
result.add(unmarshaller.unmarshal(streamReader, elementClreplaced).getValue());
} else {
// should not happen, since we check in canRead(Type)
throw new HttpMessageConversionException("Could not unmarshal to [" + elementClreplaced + "]");
}
event = moveToNextElement(streamReader);
}
return result;
} catch (UnmarshalException ex) {
throw new HttpMessageNotReadableException("Could not unmarshal to [" + elementClreplaced + "]: " + ex.getMessage(), ex);
} catch (JAXBException ex) {
throw new HttpMessageConversionException("Could not instantiate JAXBContext: " + ex.getMessage(), ex);
} catch (XMLStreamException ex) {
throw new HttpMessageConversionException(ex.getMessage(), ex);
}
}
17
Source : ResultConverter.java
with Apache License 2.0
from Frodez
with Apache License 2.0
from Frodez
@Override
protected Object readInternal(Clreplaced<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException {
return Result.reader().readValue(inputMessage.getBody());
}
17
Source : JsonMessageConverter.java
with Apache License 2.0
from didi
with Apache License 2.0
from didi
private byte[] getBody(HttpInputMessage inputMessage) throws IOException {
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);
}
}
if (baos.size() == 0) {
accessLogger.info("Request Body={}", RequestContext.getBody());
String body = RequestContext.getBody();
if (StringUtils.isNotBlank(body)) {
return body.getBytes("UTF-8");
}
return null;
} else {
// 记录请求的body内容
RequestContext.setBody(baos.toString());
accessLogger.info("Request Body={}", RequestContext.getBody());
return baos.toByteArray();
}
}
17
Source : StreamingHttpMessageConverter.java
with Apache License 2.0
from Decathlon
with Apache License 2.0
from Decathlon
@Override
public R read(Clreplaced<? extends R> clazz, HttpInputMessage inputMessage) throws IOException {
try (InputStream inputStream = inputMessage.getBody();
JsonParser parser = factory.createParser(inputStream)) {
return jsonStreamer.stream(parser);
}
}
See More Examples