org.fabric3.spi.container.invocation.Message类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中org.fabric3.spi.container.invocation.Message类的一些代码示例,展示了Message类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message类的具体详情如下:
包路径:org.fabric3.spi.container.invocation.Message
类名称:Message

Message介绍

[英]Represents a request, response, or exception flowing through a wire.
[中]表示通过连接的请求、响应或异常。

代码示例

代码示例来源:origin: org.fabric3/fabric3-binding-ws-metro

public Object invoke(Packet packet, Method method, Object... args) throws InvocationTargetException {
  // the work context is populated by the current tubeline
  WorkContext workContext = (WorkContext) packet.invocationProperties.get(MetroConstants.WORK_CONTEXT);
  if (workContext == null) {
    // programming error
    throw new AssertionError("Work context not set");
  }
  Message input = MessageCache.getAndResetMessage();
  try {
    input.setWorkContext(workContext);
    input.setBody(args);
    Interceptor head = chains.get(method.getName()).getHeadInterceptor();
    Message ret = head.invoke(input);
    if (!ret.isFault()) {
      return ret.getBody();
    } else {
      Throwable th = (Throwable) ret.getBody();
      throw new InvocationTargetException(th);
    }
  } finally {
    input.reset();
  }
}

代码示例来源:origin: com.carecon.fabric3/fabric3-pojo

/**
 * Performs the invocation on the target component instance. If a target classloader is configured for the interceptor, it will be set as the TCCL.
 *
 * @param msg      the messaging containing the invocation data
 * @param instance the target component instance
 * @return the response message
 */
private Message invoke(Message msg, Object instance) {
  try {
    Object body = msg.getBody();
    if (targetTCCLClassLoader == null) {
      msg.setBody(invoker.invoke(instance, body));
    } else {
      ClassLoader old = Thread.currentThread().getContextClassLoader();
      try {
        Thread.currentThread().setContextClassLoader(targetTCCLClassLoader);
        msg.setBody(invoker.invoke(instance, body));
      } finally {
        Thread.currentThread().setContextClassLoader(old);
      }
    }
  } catch (InvocationTargetException e) {
    msg.setBodyWithFault(e.getCause());
  } catch (IllegalAccessException e) {
    throw new InvocationRuntimeException(e);
  }
  return msg;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-zeromq

public Message invoke(Message msg) {
  byte[] body = (byte[]) msg.getBody();
  WorkContext workContext = msg.getWorkContext();
  byte[] value = sender.sendAndReply(body, index, workContext);
  msg.setBody(value);
  return msg;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-zeromq

public Message invoke(Message msg) {
  byte[] body = (byte[]) msg.getBody();
  WorkContext workContext = msg.getWorkContext();
  sender.send(body, index, workContext);
  return ONE_WAY_RESPONSE;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-zeromq

public Message invoke(Message msg) {
  msg.setBody(new Object[]{msg.getBody()});
  return next.invoke(msg);
}

代码示例来源:origin: com.carecon.fabric3/fabric3-fabric

private Message transformOutput(Message ret) {
  // FIXME For exception transformation, if it is checked convert as application fault
  Object body = ret.getBody();
  // TODO handle null types
  if (body != null) {
    try {
      Object transformed = outTransformer.transform(body, outLoader);
      if (ret.isFault()) {
        ret.setBodyWithFault(transformed);
      } else {
        ret.setBody(transformed);
      }
    } catch (ClassCastException e) {
      // an unexpected type was returned by the target service or an interceptor later in the chain. This is an error in the extension or
      // interceptor and not user code since errors should be trapped and returned in the format expected by the transformer
      if (body instanceof Throwable) {
        throw new ServiceRuntimeException("Unexpected exception returned", (Throwable) body);
      } else {
        throw new ServiceRuntimeException("Unexpected type returned: " + body.getClass());
      }
    } catch (Fabric3Exception e) {
      throw new ServiceRuntimeException(e);
    }
  }
  return ret;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-rs-jersey

public Message invoke(Message message) {
  Object[] args = (Object[]) message.getBody();
  ClassLoader old = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    Object body = response.build(args);
    message.reset();
    message.setBody(body);
  } catch (RuntimeException e) {
    throw new ServiceRuntimeException(e);
  } finally {
    Thread.currentThread().setContextClassLoader(old);
  }
  return message;
}

代码示例来源:origin: org.fabric3/fabric3-binding-ws-metro

public boolean handleMessage(SOAPMessageContext smc) {
  Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
  WorkContext workContext = WorkContextCache.getThreadWorkContext();
  workContext = (WorkContext) (workContext == null ? smc.get(MetroConstants.WORK_CONTEXT) : workContext);
  if (workContext == null) {
    throw new ServiceRuntimeException("Work context not set");
  }
  if (outbound) {
    // reference proxy outbound or service invocation return
    Message msg = MessageCache.getMessage();
    if (msg.getWorkContext() == null) {
      // service invocation return
      msg.setBody(smc.getMessage());
      msg.setWorkContext(workContext);
    }
    delegateHandler.handleOutbound(msg, smc.getMessage());
  } else {
    // reference proxy invocation return or service invocation
    Message msg = MessageCache.getMessage();
    if (msg.getWorkContext() == null) {
      // reference proxy return
      msg.setBody(smc.getMessage());
      msg.setWorkContext(workContext);
    }
    delegateHandler.handleInbound(smc.getMessage(), msg);
    msg.reset();
  }
  return true;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-zeromq

public void run() {
    Message request = MessageCache.getAndResetMessage();
    try {
      request.setBody(frames[0]);
      int methodIndex = ByteBuffer.wrap(frames[1]).getInt();
      WorkContext context = setWorkContext(frames[2]);
      request.setWorkContext(context);
      Interceptor interceptor = interceptors[methodIndex];
      interceptor.invoke(request);
    } finally {
      request.reset();
    }
  }
});

代码示例来源:origin: org.fabric3/fabric3-binding-ftp

ftpClient.connect(hostAddress, port);
  monitor.onResponse(ftpClient.getReplyString());
  String type = msg.getWorkContext().getHeader(String.class, FtpConstants.HEADER_CONTENT_TYPE);
  if (type != null && type.equalsIgnoreCase(FtpConstants.BINARY_TYPE)) {
    monitor.onCommand("TYPE I");
  monitor.onResponse(ftpClient.getReplyString());
  Object[] args = (Object[]) msg.getBody();
  String fileName = (String) args[0];
  String remoteFileLocation = fileName;
msg.reset();
return msg;

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-jms

if (resultMessage.getBooleanProperty(JmsRuntimeConstants.FAULT_HEADER)) {
  Object payload = MessageHelper.getPayload(resultMessage, payloadTypes.getFaultType());
  message.setBodyWithFault(payload);
} else {
  Object payload = MessageHelper.getPayload(resultMessage, payloadTypes.getOutputType());
  message.setBody(payload);

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-rs-jersey

private Object handleFault(Message ret) throws InvocationTargetException {
  if (ret.getBody() instanceof ServiceRuntimeException) {
    ServiceRuntimeException e = (ServiceRuntimeException) ret.getBody();
    if (e.getCause() instanceof NotAuthorizedException) {
      // authorization exceptions need to be mapped to a client 403 response
      throw new InvocationTargetException(new WebApplicationException(Response.Status.FORBIDDEN));
    }
    throw new InvocationTargetException(e);
  }
  throw new InvocationTargetException((Throwable) ret.getBody());
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-file

private Message dispatch(Object[] payload, Message message) {
  message.setBody(payload);
  return interceptor.invoke(message);
}

代码示例来源:origin: org.fabric3/fabric3-spi

/**
   * Resets and returns the Message for the current thread.
   *
   * @return the Message for the current thread
   */
  public static Message getAndResetMessage() {
    Message message = getMessage();
    message.reset();
    return message;
  }
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-jms

private void sendResponse(Message request, Session responseSession, org.fabric3.spi.container.invocation.Message outMessage, Message response)
    throws JMSException, JmsBadMessageException {
  CorrelationScheme correlationScheme = wireHolder.getCorrelationScheme();
  switch (correlationScheme) {
    case CORRELATION_ID: {
      response.setJMSCorrelationID(request.getJMSCorrelationID());
      break;
    }
    case MESSAGE_ID: {
      response.setJMSCorrelationID(request.getJMSMessageID());
      break;
    }
  }
  if (outMessage.isFault()) {
    response.setBooleanProperty(JmsRuntimeConstants.FAULT_HEADER, true);
  }
  MessageProducer producer;
  if (request.getJMSReplyTo() != null) {
    // if a reply to destination is set, use it
    producer = responseSession.createProducer(request.getJMSReplyTo());
  } else {
    if (defaultResponseDestination == null) {
      throw new JmsBadMessageException("JMSReplyTo must be set as no response destination was configured on the service");
    }
    producer = responseSession.createProducer(defaultResponseDestination);
  }
  producer.send(response);
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-jms

/**
 * Adds F3-specific routing headers to a message.
 *
 * @param message    the invocation message
 * @param jmsMessage the JMS message to be dispatched
 * @throws JMSException if an error occurs setting the headers
 * @throws IOException  if an error occurs serializing the routing information
 */
private void setRoutingHeaders(Message message, javax.jms.Message jmsMessage) throws JMSException, IOException {
  List<String> stack = message.getWorkContext().getCallbackReferences();
  if (stack == null || stack.isEmpty()) {
    return;
  }
  jmsMessage.setObjectProperty(JmsRuntimeConstants.CONTEXT_HEADER, CallbackReferenceSerializer.serializeToString(stack));
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-zeromq

public Message invoke(Message msg) {
  Object body = msg.getBody();
  if (body == null || !body.getClass().isArray()) {
    return next.invoke(msg);
  }
  Object[] payload = (Object[]) body;
  if (payload.length != 1) {
    throw new ServiceRuntimeException("Unexpected payload size: " + payload.length);
  }
  msg.setBody(payload[0]);
  return next.invoke(msg);
}

代码示例来源:origin: org.fabric3/fabric3-fabric

private Message transformOutput(Message ret) {
  // FIXME For exception transformation, if it is checked convert as application fault
  Object body = ret.getBody();
  // TODO handle null types
  if (body != null) {
    try {
      Object transformed = outTransformer.transform(body, outLoader);
      if (ret.isFault()) {
        ret.setBodyWithFault(transformed);
      } else {
        ret.setBody(transformed);
      }
    } catch (ClassCastException e) {
      // an unexpected type was returned by the target service or an interceptor later in the chain. This is an error in the extension or
      // interceptor and not user code since errors should be trapped and returned in the format expected by the transformer
      if (body instanceof Throwable) {
        throw new ServiceRuntimeException("Unexpected exception returned", (Throwable) body);
      } else {
        throw new ServiceRuntimeException("Unexpected type returned: " + body.getClass());
      }
    } catch (Fabric3Exception e) {
      throw new ServiceRuntimeException(e);
    }
  }
  return ret;
}

代码示例来源:origin: org.fabric3/fabric3-binding-rs-jersey

public Message invoke(Message message) {
  Object[] args = (Object[]) message.getBody();
  ClassLoader old = Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    Object body = response.build(args);
    message.reset();
    message.setBody(body);
  } catch (RuntimeException e) {
    throw new ServiceRuntimeException(e);
  } finally {
    Thread.currentThread().setContextClassLoader(old);
  }
  return message;
}

代码示例来源:origin: com.carecon.fabric3/fabric3-binding-ws

public boolean handleMessage(SOAPMessageContext smc) {
  Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
  WorkContext workContext = WorkContextCache.getThreadWorkContext();
  workContext = (WorkContext) (workContext == null ? smc.get(MetroConstants.WORK_CONTEXT) : workContext);
  if (workContext == null) {
    throw new ServiceRuntimeException("Work context not set");
  }
  if (outbound) {
    // reference proxy outbound or service invocation return
    Message msg = MessageCache.getMessage();
    if (msg.getWorkContext() == null) {
      // service invocation return
      msg.setBody(smc.getMessage());
      msg.setWorkContext(workContext);
    }
    delegateHandler.handleOutbound(msg, smc.getMessage());
  } else {
    // reference proxy invocation return or service invocation
    Message msg = MessageCache.getMessage();
    if (msg.getWorkContext() == null) {
      // reference proxy return
      msg.setBody(smc.getMessage());
      msg.setWorkContext(workContext);
    }
    delegateHandler.handleInbound(smc.getMessage(), msg);
    msg.reset();
  }
  return true;
}

相关文章