/** * Rethrow the original exception as required by JAX-RS, 3.3.4. * * @param error throwable to be re-thrown */ private void rethrow(final Throwable error) { if (error instanceof RuntimeException) { throw (RuntimeException) error; } else { throw new ContainerException(error); } }
/** * Rethrow the original exception as required by JAX-RS, 3.3.4 * * @param error throwable to be re-thrown */ private void rethrow(final Throwable error) { if (error instanceof RuntimeException) { throw (RuntimeException) error; } else { throw new ContainerException(error); } }
/** * Rethrow the original exception as required by JAX-RS, 3.3.4 * * @param error throwable to be re-thrown */ private void rethrow(final Throwable error) { if (error instanceof RuntimeException) { throw (RuntimeException) error; } else { throw new ContainerException(error); } }
/** * Rethrow the original exception as required by JAX-RS, 3.3.4 * * @param error throwable to be re-thrown */ private void rethrow(final Throwable error) { if (error instanceof RuntimeException) { throw (RuntimeException) error; } else { throw new ContainerException(error); } }
/** * Rethrow the original exception as required by JAX-RS, 3.3.4 * * @param error throwable to be re-thrown */ private void rethrow(final Throwable error) { if (error instanceof RuntimeException) { throw (RuntimeException) error; } else { throw new ContainerException(error); } }
/** * Rethrow the original exception as required by JAX-RS, 3.3.4 * * @param error throwable to be re-thrown */ private void rethrow(final Throwable error) { if (error instanceof RuntimeException) { throw (RuntimeException) error; } else { throw new ContainerException(error); } } }
public ContainerResponse getResponseContext() { try { return responseContext.get(); } catch (InterruptedException | ExecutionException ex) { throw new ContainerException(ex); } }
public ContainerResponse getResponseContext() { try { return responseContext.get(); } catch (InterruptedException | ExecutionException ex) { throw new ContainerException(ex); } }
@Override public Object resolve(Injectee injectee) { if (!injectee.getRequiredType().equals(EntityManagerFactory.class)) { return null; } final PersistenceUnit annotation = injectee.getParent().getAnnotation(PersistenceUnit.class); final String unitName = annotation.unitName(); if (!persistenceUnits.containsKey(unitName)) { throw new ContainerException(LocalizationMessages.PERSISTENCE_UNIT_NOT_CONFIGURED(unitName)); } return Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] {EntityManagerFactory.class}, new ThreadLocalNamedInvoker<EntityManagerFactory>(persistenceUnits.get(unitName))); }
@Override public Object resolve(Injectee injectee) { if (!injectee.getRequiredType().equals(EntityManagerFactory.class)) { return null; } final PersistenceUnit annotation = injectee.getParent().getAnnotation(PersistenceUnit.class); final String unitName = annotation.unitName(); if (!persistenceUnits.containsKey(unitName)) { throw new ContainerException(LocalizationMessages.PERSISTENCE_UNIT_NOT_CONFIGURED(unitName)); } return Proxy.newProxyInstance( this.getClass().getClassLoader(), new Class[] {EntityManagerFactory.class}, new ThreadLocalNamedInvoker<EntityManagerFactory>(persistenceUnits.get(unitName))); }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { try { if (configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } else { response.sendError(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... LOGGER.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException(LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."), ex); } finally { asyncExt.complete(); } } } finally { requestTimeoutHandler.close(); rethrow(error); } }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { try { if (configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } else { response.sendError(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... LOGGER.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException(LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE( Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Request failed."), ex); } finally { asyncExt.complete(); } } } finally { requestTimeoutHandler.close(); rethrow(error); } }
@Override public void writeTo(final Template template, final Viewable viewable, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream out) throws IOException { try { Object model = viewable.getModel(); if (!(model instanceof Map)) { model = new HashMap<String, Object>() {{ put("model", viewable.getModel()); }}; } Charset encoding = setContentType(mediaType, httpHeaders); template.process(model, new OutputStreamWriter(out, encoding)); } catch (TemplateException te) { throw new ContainerException(te); } } }
throw new ContainerException( LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(status, reason != null ? reason : "--"), ex);
throw new ContainerException( LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(status, reason != null ? reason : "--"), ex);
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final MultivaluedMap<String, String> responseHeaders = context.getStringHeaders(); final Headers serverHeaders = exchange.getResponseHeaders(); for (final Map.Entry<String, List<String>> e : responseHeaders.entrySet()) { for (final String value : e.getValue()) { serverHeaders.add(e.getKey(), value); } } try { if (context.getStatus() == Response.Status.NO_CONTENT.getStatusCode()) { // Work around bug in LW HTTP server // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6886436 exchange.sendResponseHeaders(context.getStatus(), -1); } else { exchange.sendResponseHeaders(context.getStatus(), getResponseLength(contentLength)); } } catch (final IOException ioe) { throw new ContainerException(LocalizationMessages.ERROR_RESPONSEWRITER_WRITING_HEADERS(), ioe); } return exchange.getResponseBody(); }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? HttpStatus.getMessage(code) : statusInfo.getReasonPhrase(); response.setStatusWithReason(code, reason); if (contentLength != -1 && contentLength < Integer.MAX_VALUE) { response.setContentLength((int) contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addHeader(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
@Override public OutputStream writeResponseStatusAndHeaders(final long contentLength, final ContainerResponse context) throws ContainerException { final javax.ws.rs.core.Response.StatusType statusInfo = context.getStatusInfo(); final int code = statusInfo.getStatusCode(); final String reason = statusInfo.getReasonPhrase() == null ? Status.getDescription(code) : statusInfo.getReasonPhrase(); response.setCode(code); response.setDescription(reason); if (contentLength != -1) { response.setContentLength(contentLength); } for (final Map.Entry<String, List<String>> e : context.getStringHeaders().entrySet()) { for (final String value : e.getValue()) { response.addValue(e.getKey(), value); } } try { return response.getOutputStream(); } catch (final IOException ioe) { throw new ContainerException("Error during writing out the response headers.", ioe); } }
@Override @SuppressWarnings("MagicNumber") public void failure(final Throwable error) { try { if (!grizzlyResponse.isCommitted()) { try { if (configSetStatusOverSendError) { grizzlyResponse.reset(); grizzlyResponse.setStatus(500, "Request failed."); } else { grizzlyResponse.sendError(500, "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... logger.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException( LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(500, "Request failed."), ex); } } } finally { logger.debugLog("{0} - failure(...) called", name); rethrow(error); } }
@Override public void failure(final Throwable error) { try { if (!response.isCommitted()) { try { if (configSetStatusOverSendError) { response.reset(); //noinspection deprecation response.setStatus(INTERNAL_SERVER_ERROR, "Request failed."); } else { response.sendError(INTERNAL_SERVER_ERROR, "Request failed."); } } catch (final IllegalStateException ex) { // a race condition externally committing the response can still occur... LOGGER.log(Level.FINER, "Unable to reset failed response.", ex); } catch (final IOException ex) { throw new ContainerException(LocalizationMessages.EXCEPTION_SENDING_ERROR_RESPONSE(INTERNAL_SERVER_ERROR, "Request failed."), ex); } } } finally { LOGGER.log(Level.FINEST, "failure(...) called"); commit(); rethrow(error); } }