List of usage examples for org.springframework.http.converter HttpMessageNotReadableException HttpMessageNotReadableException
public HttpMessageNotReadableException(String msg, HttpInputMessage httpInputMessage)
From source file:org.n52.restfulwpsproxy.serializer.WPSBeansMessageConverter.java
@Override protected XmlObject readInternal(Class<? extends XmlObject> type, HttpInputMessage him) throws IOException, HttpMessageNotReadableException { try {/*ww w . ja va 2 s . c o m*/ if (type == CapabilitiesDocument.class) { return CapabilitiesDocument.Factory.parse(him.getBody()); } else if (type == ProcessOfferingsDocument.class) { return ProcessOfferingsDocument.Factory.parse(him.getBody()); } else if (type == StatusInfoDocument.class) { return StatusInfoDocument.Factory.parse(him.getBody()); } else if (type == ResultDocument.class) { return ResultDocument.Factory.parse(him.getBody()); } else if (type == ExceptionReportDocument.class) { return ExceptionReportDocument.Factory.parse(him.getBody()); } } catch (XmlException ex) { Logger.getLogger(WPSBeansMessageConverter.class.getName()).log(Level.SEVERE, null, ex); throw new HttpMessageNotReadableException(ex.getMessage(), ex); } throw new UnsupportedOperationException("Not supported yet."); }
From source file:org.ccntgrid.extend.spring.http.converter.json.MappingJackson2HttpMessageConverter.java
@Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { JavaType javaType = getJavaType(clazz); try {// w ww .j a v a2 s .c o m return this.objectMapper.readValue(inputMessage.getBody(), javaType); } catch (JsonProcessingException ex) { throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex); } }
From source file:org.springframework.data.rest.webmvc.config.JsonPatchHandler.java
/** * Returns all {@link JsonPatchOperation}s to be applied. * // w w w . j a v a 2 s.com * @param source must not be {@literal null}. * @return * @throws HttpMessageNotReadableException in case the payload can't be read. */ private Patch getPatchOperations(InputStream source) { try { return new JsonPatchPatchConverter().convert(mapper.readTree(source)); } catch (Exception o_O) { throw new HttpMessageNotReadableException( String.format("Could not read PATCH operations! Expected %s!", RestMediaTypes.JSON_PATCH_JSON), o_O); } }
From source file:org.nobel.highriseapi.mapper.SimpleXmlHttpMessageConverter.java
@Override protected Object readInternal(Class<? extends Object> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { Reader source = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); try {/*from w ww . j av a 2 s . co m*/ Object result = this.serializer.read(clazz, source); if (!clazz.isInstance(result)) { throw new TypeMismatchException(result, clazz); } return result; } catch (Exception ex) { throw new HttpMessageNotReadableException("Could not read [" + clazz + "]", ex); } }
From source file:com.cookbook.cq.dao.util.GsonHttpMessageConverter.java
@Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { Reader json = new InputStreamReader(inputMessage.getBody(), getCharset(inputMessage.getHeaders())); try {//from ww w . j a va 2 s . c o m Type typeOfT = getType(); if (typeOfT != null) { return this.gson.fromJson(json, typeOfT); } else { return this.gson.fromJson(json, clazz); } } catch (JsonSyntaxException ex) { throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex); } catch (JsonIOException ex) { throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex); } catch (JsonParseException ex) { throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex); } }
From source file:org.wcy123.ProtobufMessageConverter.java
@Override protected Message readInternal(Class<? 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 {//w w w .j av a 2s. c o m Message.Builder builder = getMessageBuilder(clazz); if (MediaType.APPLICATION_JSON.isCompatibleWith(contentType)) { parser.merge(reader, builder); } else if (MediaType.TEXT_PLAIN.isCompatibleWith(contentType)) { TextFormat.merge(reader, this.extensionRegistry, builder); } else if (MediaType.APPLICATION_XML.isCompatibleWith(contentType)) { throw new UnsupportedOperationException("not supported yet"); } else { builder.mergeFrom(inputMessage.getBody(), this.extensionRegistry); } return builder.build(); } catch (Exception e) { throw new HttpMessageNotReadableException("Could not read Protobuf message: " + e.getMessage(), e); } }
From source file:org.kwet.giteway.mapper.PrettyMappingJacksonHttpMessageConverter.java
@Override protected Object readInternal(Class<?> clazz, HttpInputMessage inputMessage) throws IOException { JavaType javaType = getJavaType(clazz); try {/* w w w. j av a 2s . c o m*/ return this.objectMapper.readValue(inputMessage.getBody(), javaType); } catch (IOException ex) { throw new HttpMessageNotReadableException("Could not read JSON: " + ex.getMessage(), ex); } }
From source file:org.springframework.data.rest.webmvc.json.DomainObjectReader.java
public <T> T merge(ObjectNode source, T target, ObjectMapper mapper) { try {//from ww w .j av a 2 s . co m return doMerge(source, target, mapper); } catch (Exception o_O) { throw new HttpMessageNotReadableException("Could not read payload!", o_O); } }
From source file:org.gvnix.web.json.DataBinderMappingJackson2HttpMessageConverter.java
/** * Before call to {@link ObjectMapper#readValue(java.io.InputStream, Class)} * creates a {@link ServletRequestDataBinder} and put it to current Thread * in order to be used by the {@link DataBinderDeserializer}. * <p/>/* w ww .j a va2s . c om*/ * Ref: <a href= * "http://java.dzone.com/articles/java-thread-local-%E2%80%93-how-use">When * to use Thread Local?</a> * * @param javaType * @param inputMessage * @return */ private Object readJavaType(JavaType javaType, HttpInputMessage inputMessage) { try { Object target = null; String objectName = null; // CRear el DataBinder con un target object en funcion del javaType, // ponerlo en el thread local Class<?> clazz = javaType.getRawClass(); if (Collection.class.isAssignableFrom(clazz)) { Class<?> contentClazz = javaType.getContentType().getRawClass(); target = new DataBinderList<Object>(contentClazz); objectName = "list"; } else if (Map.class.isAssignableFrom(clazz)) { // TODO Class<?> contentClazz = // javaType.getContentType().getRawClass(); target = CollectionFactory.createMap(clazz, 0); objectName = "map"; } else { target = BeanUtils.instantiateClass(clazz); objectName = "bean"; } WebDataBinder binder = new ServletRequestDataBinder(target, objectName); binder.setConversionService(this.conversionService); binder.setAutoGrowNestedPaths(true); binder.setValidator(validator); ThreadLocalUtil.setThreadVariable(BindingResult.MODEL_KEY_PREFIX.concat("JSON_DataBinder"), binder); Object value = getObjectMapper().readValue(inputMessage.getBody(), javaType); return value; } catch (IOException ex) { throw new HttpMessageNotReadableException("Could not read JSON: ".concat(ex.getMessage()), ex); } }
From source file:net.sf.jsog.spring.StringJsogHttpMessageConverter.java
@Override public JSOG read(Class<? extends JSOG> clazz, HttpInputMessage input) throws IOException, HttpMessageNotReadableException { HttpHeaders headers = input.getHeaders(); MediaType contentType = headers.getContentType(); Charset encoding = contentType.getCharSet(); if (encoding == null) { encoding = this.encoding; }/*from w ww . j av a 2 s . com*/ // Read in the JSON String json = IOUtils.toString(input.getBody(), encoding.name()); // Parse the JSON and return a JSOG. try { return JSOG.parse(json); } catch (IOException e) { throw new HttpMessageNotReadableException("Unable to parse JSON.", e); } }