List of usage examples for org.springframework.http.converter HttpMessageConversionException HttpMessageConversionException
public HttpMessageConversionException(String msg)
From source file:com.yahoo.glimmer.web.QueryController.java
@ModelAttribute(INDEX_KEY) public RDFIndex getIndex(@RequestParam(required = false) String index) { if (index != null) { RDFIndex rdfIndex = indexMap.get(index); if (rdfIndex == null) { throw new HttpMessageConversionException("No index found with name:" + index); }/*from w ww . j a v a 2s . com*/ return rdfIndex; } else { return null; } }
From source file:com.yahoo.glimmer.web.QueryController.java
@RequestMapping(value = "/indexStatistics", method = RequestMethod.GET) public Map<String, ?> getIndexStatistics(@ModelAttribute(INDEX_KEY) RDFIndex index, @RequestParam(required = false) String callback) { if (index == null) { throw new HttpMessageConversionException("No index given"); }/* ww w .j a v a 2 s .c om*/ RDFIndexStatistics statistics = index.getStatistics(); return Collections.singletonMap(OBJECT_KEY, statistics); }
From source file:com.yahoo.glimmer.web.QueryController.java
@RequestMapping(value = { "/query", "/v1/search" }, method = RequestMethod.GET) public Map<String, ?> query(@ModelAttribute(INDEX_KEY) RDFIndex index, @Valid QueryCommand command, HttpServletRequest httpServletRequest) throws QueryParserException, QueryBuilderVisitorException, IOException { if (index == null) { throw new HttpMessageConversionException("No index given."); }//from w w w . jav a 2s. c om String query = command.getQuery(); if (query == null || query.isEmpty()) { throw new HttpMessageConversionException("No query given."); } QueryResult result; if (queryFilter != null && queryFilter.filter(query)) { LOGGER.info("Blocking query:" + query + " from address:" + httpServletRequest.getRemoteAddr()); throw new HttpMessageConversionException("Bad query given."); } query = decodeEntities(command.getQuery()).trim(); query = encodeResources(index, query); Query parsedQuery; switch (command.getType()) { case MG4J: parsedQuery = new SimpleParser().parse(query); result = querier.doQuery(index, parsedQuery, command.getPageStart(), command.getPageSize(), command.isDeref(), defaultObjectLengthLimit); break; case YAHOO: if (query.startsWith(DOC_PSEUDO_FIELD)) { String idOrSubject = query.substring(DOC_PSEUDO_FIELD.length()); Long id; if (Character.isDigit(idOrSubject.charAt(0))) { try { id = Long.parseLong(idOrSubject); } catch (NumberFormatException e) { throw new IllegalArgumentException( "Query " + query + " failed to parse as a numeric subject ID(int)"); } } else { id = index.getSubjectId(idOrSubject); if (id == null) { throw new IllegalArgumentException("subject " + idOrSubject + " is not in collection."); } } result = querier.doQueryForDocId(index, id, command.isDeref(), null); } else { try { parsedQuery = index.getParser().parse(query); } catch (QueryParserException e) { throw new IllegalArgumentException("Query failed to parse:" + query, e); } result = querier.doQuery(index, parsedQuery, command.getPageStart(), command.getPageSize(), command.isDeref(), defaultObjectLengthLimit); } break; default: throw new IllegalArgumentException("No query type given."); } return Collections.singletonMap(OBJECT_KEY, result); }
From source file:demo.SourceHttpMessageConverter.java
@Override @SuppressWarnings("unchecked") protected T readInternal(Class<? extends T> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { InputStream body = inputMessage.getBody(); if (DOMSource.class == clazz) { return (T) readDOMSource(body); } else if (SAXSource.class == clazz) { return (T) readSAXSource(body); } else if (StAXSource.class == clazz) { return (T) readStAXSource(body); } else if (StreamSource.class == clazz || Source.class == clazz) { return (T) readStreamSource(body); } else {//w w w .j av a 2 s.c om throw new HttpMessageConversionException("Could not read class [" + clazz + "]. Only DOMSource, SAXSource, StAXSource, and StreamSource are supported."); } }
From source file:org.cloudfoundry.identity.uaa.scim.endpoints.ScimUserEndpointsTests.java
@Test public void testHandleExceptionWithBadFieldName() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(); MockHttpServletResponse response = new MockHttpServletResponse(); endpoints.setMessageConverters(new HttpMessageConverter<?>[] { new ExceptionReportHttpMessageConverter() }); View view = endpoints.handleException(new HttpMessageConversionException("foo"), request); ConvertingExceptionView converted = (ConvertingExceptionView) view; converted.render(Collections.<String, Object>emptyMap(), request, response); String body = response.getContentAsString(); assertEquals(HttpStatus.BAD_REQUEST.value(), response.getStatus()); // System.err.println(body); assertTrue("Wrong body: " + body, body.contains("message\":\"foo")); }