protected void throwFault(String error, Exception ex) { LOG.warning(error); Response response = JAXRSUtils.toResponseBuilder(400).entity(error).build(); throw ExceptionUtils.toBadRequestException(null, response); }
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 Form readFormData(Message message) { try { return FormUtils.readForm(provider, message); } catch (Exception ex) { throw ExceptionUtils.toNotAuthorizedException(null, null); } }
private static RuntimeException createParamConversionException(ParameterType pType, Exception ex) { // // For path, query & matrix parameters this is 404, // for others 400... // if (pType == ParameterType.PATH || pType == ParameterType.QUERY || pType == ParameterType.MATRIX) { return ExceptionUtils.toNotFoundException(ex, null); } return ExceptionUtils.toBadRequestException(ex, null); } public static <T> T createFromParameterHandler(String value,
protected void throwFault(String error, Exception ex) { // TODO: get bundle resource message once this filter is moved // to rt/rs/security String errorMsg = error; if (ex != null) { errorMsg += ": " + ExceptionUtils.getStackTrace(ex); } LOG.warning(errorMsg); Response response = JAXRSUtils.toResponseBuilder(401).entity(error).build(); throw ExceptionUtils.toNotAuthorizedException(null, response); }
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; }
private View resolveView(String viewName) { try { return viewResolver.resolveViewName(viewName, getLocale()); } catch (Exception ex) { LOG.warning(ExceptionUtils.getStackTrace(ex)); throw ExceptionUtils.toInternalServerErrorException(ex, null); } }
handleJAXBException(e, true); } catch (DepthExceededStaxException e) { throw ExceptionUtils.toWebApplicationException(null, JAXRSUtils.toResponse(413)); } catch (WebApplicationException e) { throw e; } catch (Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); throw ExceptionUtils.toBadRequestException(e, null); } finally { try {
throw ExceptionUtils.toNotFoundException(nfe, null); throw ExceptionUtils.toBadRequestException(nfe, null); pClass.getName()).toString()); Response r = JAXRSUtils.toResponse(HttpUtils.getParameterFailureStatus(pType)); throw ExceptionUtils.toHttpException(ex, r);
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); }
protected static StringBuilder handleExceptionStart(Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); StringBuilder sb = new StringBuilder(); if (e.getMessage() != null) { sb.append(e.getMessage()).append(". "); } if (e.getCause() != null && e.getCause().getMessage() != null) { sb.append(e.getCause().getMessage()).append(". "); } return sb; }
private static void checkMediaTypes(MediaType mt1, String mt2) { if (!mt1.isCompatible(JAXRSUtils.toMediaType(mt2))) { throw ExceptionUtils.toNotSupportedException(null, null); } } }
acceptContentTypes = JAXRSUtils.sortMediaTypes(acceptTypes, JAXRSUtils.MEDIA_TYPE_Q_PARAM); } catch (IllegalArgumentException ex) { throw ExceptionUtils.toNotAcceptableException(null, null); Response resp = JAXRSUtils.createResponse(resources, message, errorMsg.toString(), Response.Status.NOT_FOUND.getStatusCode(), false); throw ExceptionUtils.toNotFoundException(null, resp);
requestType = toMediaType(requestContentType); } catch (IllegalArgumentException ex) { throw ExceptionUtils.toNotSupportedException(ex, null); throw ExceptionUtils.toHttpException(null, response);
protected void checkSecurityContext() { SecurityContext sc = mc.getSecurityContext(); if (sc.getUserPrincipal() == null) { throw ExceptionUtils.toNotAuthorizedException(null, null); } if (userRole != null && !sc.isUserInRole(userRole)) { throw ExceptionUtils.toForbiddenException(null, null); } }
public void writeTo(org.dom4j.Document doc, Class<?> cls, Type type, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { if (mt.getSubtype().contains("xml")) { org.dom4j.io.XMLWriter writer = new org.dom4j.io.XMLWriter(os); writer.write(doc); writer.flush(); } else { org.w3c.dom.Document domDoc = convertToDOM(doc); MessageBodyWriter<org.w3c.dom.Document> writer = providers.getMessageBodyWriter(DOM_DOC_CLS, DOM_DOC_CLS, anns, mt); if (writer == null) { throw ExceptionUtils.toNotAcceptableException(null, null); } writer.writeTo(domDoc, DOM_DOC_CLS, DOM_DOC_CLS, anns, mt, headers, os); } }
private List<LogRecord> getLogRecords(int index, SearchCondition<LogRecord> theSearch) { List<LogRecord> list = new LinkedList<LogRecord>(); if (storage != null) { int storageSize = storage.getSize(); if (recordsSize == -1 || index < storageSize) { storage.load(list, theSearch, index, 1); } else if (index < recordsSize) { list.add(records.get(index - storageSize)); } } else { list.add(records.get(index)); } if (list.size() != 1) { throw ExceptionUtils.toNotFoundException(null, null); } return list; }
private void reportError(String message, Exception ex, int status) { LOG.warning(message); Response response = JAXRSUtils.toResponseBuilder(status).type("text/plain").entity(message).build(); throw ExceptionUtils.toHttpException(ex, response); } private void reportError(String message, Exception 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); }
public void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { try { String encoding = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); if (InjectionUtils.isSupportedCollectionOrArray(cls)) { marshalCollection(cls, obj, genericType, encoding, os, m, anns); } else { Object actualObject = checkAdapter(obj, cls, anns, true); Class<?> actualClass = obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls; marshal(actualObject, actualClass, genericType, encoding, os, m, anns); } } catch (JAXBException e) { handleJAXBException(e, false); } catch (WebApplicationException e) { throw e; } catch (Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); throw ExceptionUtils.toInternalServerErrorException(e, null); } }