public static String readBody(InputStream is, String encoding) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(is, bos, 1024); return new String(bos.toByteArray(), encoding); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
private Object createResponseEntity(String entity, boolean isJson) { if (!isJson) { return entity; } try { return StaxUtils.read(new StringReader(entity)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
public static String readBody(InputStream is, String encoding) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); IOUtils.copy(is, bos, 1024); return new String(bos.toByteArray(), encoding); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
private Object createResponseEntity(Message m, UriInfo ui, String entity, boolean isJson) { try { if (!isJson) { if (stylesheetReference != null && applyStylesheetLocally) { return transformLocally(m, ui, new StreamSource(new StringReader(entity))); } return entity; } return StaxUtils.read(new StringReader(entity)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
protected static void handleExceptionEnd(Throwable t, String message, boolean read) { Response.Status status = read ? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR; Response r = JAXRSUtils.toResponseBuilder(status) .type(MediaType.TEXT_PLAIN).entity(message).build(); WebApplicationException ex = read ? ExceptionUtils.toBadRequestException(t, r) : ExceptionUtils.toInternalServerErrorException(t, r); throw ex; }
protected static void handleExceptionEnd(Throwable t, String message, boolean read) { Response.Status status = read ? Response.Status.BAD_REQUEST : Response.Status.INTERNAL_SERVER_ERROR; Response r = JAXRSUtils.toResponseBuilder(status) .type(MediaType.TEXT_PLAIN).entity(message).build(); throw read ? ExceptionUtils.toBadRequestException(t, r) : ExceptionUtils.toInternalServerErrorException(t, r); }
private org.w3c.dom.Document convertToDOM(org.dom4j.Document doc) { String xml = doc.asXML(); try { return StaxUtils.read(new StringReader(xml)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
private org.w3c.dom.Document convertToDOM(org.dom4j.Document doc) { String xml = doc.asXML(); try { return StaxUtils.read(new StringReader(xml)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
private org.w3c.dom.Document convertToDOM(org.dom4j.Document doc) { String xml = doc.asXML(); try { return StaxUtils.read(new StringReader(xml)); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } } }
protected RequestDispatcher getRequestDispatcher(ServletContext sc, Class<?> clazz, String path) { RequestDispatcher rd = dispatcherName != null ? sc.getNamedDispatcher(dispatcherName) : sc.getRequestDispatcher(path); if (rd == null) { String message = new org.apache.cxf.common.i18n.Message("RESOURCE_PATH_NOT_FOUND", BUNDLE, path).toString(); LOG.severe(message); throw ExceptionUtils.toInternalServerErrorException(null, null); } return rd; }
@Override public void writeTo(OutputStream os) { try { writer.writeTo(obj, cls, genericType, anns, contentType, new MetadataMap<String, Object>(), os); } catch (IOException ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
protected XMLStreamReader configureReaderRestrictions(XMLStreamReader reader) { Message message = PhaseInterceptorChain.getCurrentMessage(); if (message != null) { try { return StaxUtils.configureReader(reader, message); } catch (XMLStreamException ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } } return reader; }
protected XMLStreamReader configureReaderRestrictions(XMLStreamReader reader) { Message message = PhaseInterceptorChain.getCurrentMessage(); if (message != null) { try { return StaxUtils.configureReader(reader, message); } catch (XMLStreamException ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } } return reader; }
protected RequestDispatcher getRequestDispatcher(ServletContext sc, Class<?> clazz, String path) { RequestDispatcher rd = dispatcherName != null ? sc.getNamedDispatcher(dispatcherName) : sc.getRequestDispatcher(path); if (rd == null) { String message = new org.apache.cxf.common.i18n.Message("RESOURCE_PATH_NOT_FOUND", BUNDLE, path).toString(); LOG.severe(message); throw ExceptionUtils.toInternalServerErrorException(null, null); } return rd; }
protected XMLStreamReader configureReaderRestrictions(XMLStreamReader reader) { Message message = PhaseInterceptorChain.getCurrentMessage(); if (message != null) { try { return StaxUtils.configureReader(reader, message); } catch (XMLStreamException ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } } else { return reader; } }
private View resolveView(String viewName) { try { return viewResolver.resolveViewName(viewName, getLocale()); } catch (Exception ex) { LOG.warning(ExceptionUtils.getStackTrace(ex)); throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
@Override public boolean hasEntity() { // Is Content-Length is explicitly set to 0 ? if (HttpUtils.isPayloadEmpty(getHeaders())) { return false; } try { return !IOUtils.isEmpty(getEntityStream()); } catch (IOException ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
@Override public boolean hasEntity() { // Is Content-Length is explicitly set to 0 ? if (HttpUtils.isPayloadEmpty(getHeaders())) { return false; } try { return !IOUtils.isEmpty(getEntityStream()); } catch (IOException ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } } }
private void convertExceptionToResponseIfPossible(Throwable ex, Message message) { Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message); if (excResponse == null) { ProviderFactory.getInstance(message).clearThreadLocalProxies(); message.getExchange().put(Message.PROPOGATE_EXCEPTION, ExceptionUtils.propogateException(message)); throw ex instanceof RuntimeException ? (RuntimeException)ex : ExceptionUtils.toInternalServerErrorException(ex, null); } message.getExchange().put(Response.class, excResponse); }
private void convertExceptionToResponseIfPossible(Throwable ex, Message message) { Response excResponse = JAXRSUtils.convertFaultToResponse(ex, message); if (excResponse == null) { ServerProviderFactory.getInstance(message).clearThreadLocalProxies(); message.getExchange().put(Message.PROPOGATE_EXCEPTION, ExceptionUtils.propogateException(message)); throw ex instanceof RuntimeException ? (RuntimeException)ex : ExceptionUtils.toInternalServerErrorException(ex, null); } message.getExchange().put(Response.class, excResponse); message.getExchange().put(Throwable.class, ex); }