Ejemplo n.º 1
0
 static String lookatPersistenceContext(final Object obj) throws RuntimeException {
   final Class type = Classes.typeOf(obj);
   final Ats ats = Ats.inClassHierarchy(type);
   PersistenceContext persistenceContext = null;
   if (!ats.has(PersistenceContext.class)) {
     throw new RuntimeException(
         "Attempting to create an entity wrapper instance for non persistent type: "
             + type
             + ".  Class hierarchy contains: \n"
             + ats.toString());
   } else {
     persistenceContext = ats.get(PersistenceContext.class);
   }
   return persistenceContext.name();
 }
 @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
 public void handle(final ExceptionMessage exMsg) {
   EventRecord.here(getClass(), EventType.MSG_REPLY, exMsg.getPayload().getClass().getSimpleName())
       .debug();
   LOG.trace("Caught exception while servicing: " + exMsg.getPayload());
   final Throwable exception = exMsg.getException();
   if (exception instanceof MessagingException
       && exception.getCause() instanceof EucalyptusCloudException) {
     try {
       final EucalyptusCloudException cloudException =
           (EucalyptusCloudException) exception.getCause();
       final BaseMessage payload = parsePayload(exMsg.getPayload());
       final HttpResponseStatus status;
       final Role role;
       final String code;
       if (cloudException instanceof EucalyptusWebServiceException) {
         final EucalyptusWebServiceException webServiceException =
             (EucalyptusWebServiceException) cloudException;
         role = webServiceException.getRole();
         code = webServiceException.getCode();
       } else {
         role = Role.Receiver;
         code = defaultCode;
       }
       final QueryBindingInfo info =
           Ats.inClassHierarchy(cloudException.getClass()).get(QueryBindingInfo.class);
       status =
           info == null
               ? HttpResponseStatus.INTERNAL_SERVER_ERROR
               : new HttpResponseStatus(info.statusCode(), code);
       final BaseMessage errorResp =
           buildErrorResponse(payload.getCorrelationId(), role, code, cloudException.getMessage());
       Contexts.response(new BaseMessageSupplier(errorResp, status));
     } catch (final PayloadParseException e) {
       LOG.error("Failed to parse payload ", e.getCause());
     }
   } else {
     LOG.error("Unable to handle exception", exception);
     final BaseMessage errorResp = buildFatalResponse(exception);
     Contexts.response(
         new BaseMessageSupplier(errorResp, HttpResponseStatus.INTERNAL_SERVER_ERROR));
   }
 }
Ejemplo n.º 3
0
    @Override
    public void handleUpstream(
        final ChannelHandlerContext channelHandlerContext, final ChannelEvent channelEvent)
        throws Exception {
      if (channelEvent instanceof MessageEvent && componentIdClass != null) {
        final BaseMessage message = BaseMessage.extractMessage(channelEvent);
        final ComponentMessage componentMessage =
            message == null
                ? null
                : Ats.inClassHierarchy(message.getClass()).get(ComponentMessage.class);
        if (message != null
            && (componentMessage == null || !componentIdClass.equals(componentMessage.value()))) {
          LOG.warn(
              String.format(
                  "Message %s does not match pipeline component %s",
                  message.getClass(), componentIdClass.getSimpleName()));

          final MappingHttpMessage mappingHttpMessage =
              MappingHttpMessage.extractMessage(channelEvent);
          final BaseMessage baseMessage = BaseMessage.extractMessage(channelEvent);
          if (baseMessage != null) {
            Contexts.clear(Contexts.lookup(baseMessage.getCorrelationId()));
          }
          channelHandlerContext
              .getChannel()
              .write(
                  new MappingHttpResponse(
                      mappingHttpMessage == null
                          ? HttpVersion.HTTP_1_1
                          : mappingHttpMessage.getProtocolVersion(),
                      HttpResponseStatus.BAD_REQUEST));
          return;
        }
      }
      channelHandlerContext.sendUpstream(channelEvent);
    }