/** * Deserializes the data as an object of the <code>resultClass</code> type using the given * <code>serialization</code> instance. * * @param <R> the type of the object once deserialized. * @param serialization the serialization object to be used. * @param resultClass the parameterized type of the object once deserialized. * @param contentType the contentType of <code>data</code>. * @param data the data to deserialize. @return The deserialized object. */ protected <R> R deserializeValue(Serialization serialization, String resultClass, ContentType contentType, String data) throws ActionException { try { return serialization.deserialize(resultClass, contentType, data); } catch (SerializationException e) { throw new ActionException(e); } }
@Override public void undo(String cookieSentByRPC, Action<Result> action, Result result) throws ActionException, ServiceException { if (action.isSecured() && !cookieMatch(cookieSentByRPC)) { String message = xsrfAttackMessage + " While undoing action: " + action.getClass().getName(); logger.severe(message); throw new ServiceException(message); } try { dispatch.undo(action, result); } catch (ActionException e) { logger.warning("Action exception while undoing " + action.getClass().getName() + ": " + e.getMessage()); throw new ActionException(e.getMessage()); } catch (ServiceException e) { logger.warning("Service exception while undoing " + action.getClass().getName() + ": " + e.getMessage()); throw new ServiceException(e.getMessage()); } catch (RuntimeException e) { logger.warning("Unexpected exception while undoing " + action.getClass().getName() + ": " + e.getMessage()); throw new ServiceException(e.getMessage()); } }
if (logger.isLoggable(Level.WARNING)) { String newMessage = "Action exception while executing " + action.getClass().getName() + ": " + e.getMessage(); logger.log(Level.WARNING, newMessage, e);
if (logger.isLoggable(Level.WARNING)) { String newMessage = "Action exception while executing " + action.getClass().getName() + ": " + e.getMessage(); logger.log(Level.WARNING, newMessage, e);
/** * Serialize the given object using the given <code>serialization</code> instance. * * @param serialization the serialization object to be used. * @param object the object to serialize. * @param bodyClass The parameterized type of the object to serialize. * @param contentTypes A list of content types a serializer is allowed to return. * * @return The serialized string. */ protected SerializedValue serialize(Serialization serialization, Object object, String bodyClass, List<ContentType> contentTypes) throws ActionException { try { return serialization.serialize(bodyClass, contentTypes, object); } catch (SerializationException e) { throw new ActionException(e); } }
@Override public void undo(String cookieSentByRPC, Action<Result> action, Result result) throws ActionException, ServiceException { if (action.isSecured() && !cookieMatch(cookieSentByRPC)) { String message = xsrfAttackMessage + " While undoing action: " + action.getClass().getName(); logger.severe(message); throw new ServiceException(message); } try { dispatch.undo(action, result); } catch (ActionException e) { logger.warning("Action exception while undoing " + action.getClass().getName() + ": " + e.getMessage()); throw new ActionException(e.getMessage()); } catch (ServiceException e) { logger.warning("Service exception while undoing " + action.getClass().getName() + ": " + e.getMessage()); throw new ServiceException(e.getMessage()); } catch (RuntimeException e) { logger.warning("Unexpected exception while undoing " + action.getClass().getName() + ": " + e.getMessage()); throw new ServiceException(e.getMessage()); } }
doRun(request, response); } catch (Exception e) { throw new ActionException(e);
@Override public void undo(String cookieSentByRPC, Action<Result> action, Result result) throws ActionException, ServiceException { if (action.isSecured() && !cookieMatch(cookieSentByRPC)) { String message = xsrfAttackMessage + " While undoing action: " + action.getClass().getName(); logger.severe(message); throw new ServiceException(message); } try { dispatch.undo(action, result); } catch (ActionException e) { logger.log(e, action, DispatchType.Undo); throw new ActionException(e.getMessage()); } catch (ServiceException e) { logger.log(e, action, DispatchType.Undo); throw new ServiceException(e.getMessage()); } catch (RuntimeException e) { logger.log(e, action, DispatchType.Undo); throw new ServiceException(e.getMessage()); } }
@Override public <A extends RestAction<R>, R> R deserialize(A action, Response response) throws ActionException { if (isSuccessStatusCode(response)) { return getDeserializedResponse(action, response); } else { throw new ActionException(response.getStatusText()); } }
public BatchResult execute(BatchAction action, ExecutionContext context) throws ActionException { OnException onException = action.getOnException(); List<Result> results = new java.util.ArrayList<Result>(); for (Action<?> a : action.getActions()) { Result result = null; try { result = context.execute(a); } catch (Exception e) { if (onException == OnException.ROLLBACK) { if (e instanceof ActionException) { throw (ActionException) e; } if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ActionException(e); } } } results.add(result); } return new BatchResult(results); }
public BatchResult execute(BatchAction action, ExecutionContext context) throws ActionException { OnException onException = action.getOnException(); List<Result> results = new java.util.ArrayList<>(); for (Action<?> a : action.getActions()) { Result result = null; try { result = context.execute(a); } catch (Exception e) { if (onException == OnException.ROLLBACK) { if (e instanceof ActionException) { throw (ActionException) e; } if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ActionException(e); } } } results.add(result); } return new BatchResult(results); }
public BatchResult execute(BatchAction action, ExecutionContext context) throws ActionException { OnException onException = action.getOnException(); List<Result> results = new java.util.ArrayList<Result>(); for (Action<?> a : action.getActions()) { Result result = null; try { result = context.execute(a); } catch (Exception e) { if (onException == OnException.ROLLBACK) { if (e instanceof ActionException) { throw (ActionException) e; } if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ActionException(e); } } } results.add(result); } return new BatchResult(results); }
private SerializedValue getSerializedValue(RestAction<?> action, Object object) throws ActionException { String bodyClass = action.getBodyClass(); if (bodyClass != null) { List<ContentType> contentTypes = action.getClientProducedContentTypes(); Serialization serialization = findSerialization(bodyClass, contentTypes); if (serialization != null) { return serialize(serialization, object, bodyClass, contentTypes); } } throw new ActionException("Unable to serialize request body. No serializer found."); }
private <R> R getDeserializedResponse(RestAction<R> action, Response response) throws ActionException { String resultClass = action.getResultClass(); if (resultClass != null) { ContentType contentType = ContentType.valueOf(response.getHeader(HttpHeaders.CONTENT_TYPE)); Serialization serialization = findSerialization(resultClass, contentType); if (serialization != null) { return deserializeValue(serialization, resultClass, contentType, response.getText()); } } throw new ActionException("Unable to deserialize response. No serializer found."); }