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

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

本文整理了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

  1. public Object invoke(Packet packet, Method method, Object... args) throws InvocationTargetException {
  2. // the work context is populated by the current tubeline
  3. WorkContext workContext = (WorkContext) packet.invocationProperties.get(MetroConstants.WORK_CONTEXT);
  4. if (workContext == null) {
  5. // programming error
  6. throw new AssertionError("Work context not set");
  7. }
  8. Message input = MessageCache.getAndResetMessage();
  9. try {
  10. input.setWorkContext(workContext);
  11. input.setBody(args);
  12. Interceptor head = chains.get(method.getName()).getHeadInterceptor();
  13. Message ret = head.invoke(input);
  14. if (!ret.isFault()) {
  15. return ret.getBody();
  16. } else {
  17. Throwable th = (Throwable) ret.getBody();
  18. throw new InvocationTargetException(th);
  19. }
  20. } finally {
  21. input.reset();
  22. }
  23. }

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

  1. /**
  2. * Performs the invocation on the target component instance. If a target classloader is configured for the interceptor, it will be set as the TCCL.
  3. *
  4. * @param msg the messaging containing the invocation data
  5. * @param instance the target component instance
  6. * @return the response message
  7. */
  8. private Message invoke(Message msg, Object instance) {
  9. try {
  10. Object body = msg.getBody();
  11. if (targetTCCLClassLoader == null) {
  12. msg.setBody(invoker.invoke(instance, body));
  13. } else {
  14. ClassLoader old = Thread.currentThread().getContextClassLoader();
  15. try {
  16. Thread.currentThread().setContextClassLoader(targetTCCLClassLoader);
  17. msg.setBody(invoker.invoke(instance, body));
  18. } finally {
  19. Thread.currentThread().setContextClassLoader(old);
  20. }
  21. }
  22. } catch (InvocationTargetException e) {
  23. msg.setBodyWithFault(e.getCause());
  24. } catch (IllegalAccessException e) {
  25. throw new InvocationRuntimeException(e);
  26. }
  27. return msg;
  28. }

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

  1. public Message invoke(Message msg) {
  2. byte[] body = (byte[]) msg.getBody();
  3. WorkContext workContext = msg.getWorkContext();
  4. byte[] value = sender.sendAndReply(body, index, workContext);
  5. msg.setBody(value);
  6. return msg;
  7. }

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

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

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

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

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

  1. private Message transformOutput(Message ret) {
  2. // FIXME For exception transformation, if it is checked convert as application fault
  3. Object body = ret.getBody();
  4. // TODO handle null types
  5. if (body != null) {
  6. try {
  7. Object transformed = outTransformer.transform(body, outLoader);
  8. if (ret.isFault()) {
  9. ret.setBodyWithFault(transformed);
  10. } else {
  11. ret.setBody(transformed);
  12. }
  13. } catch (ClassCastException e) {
  14. // an unexpected type was returned by the target service or an interceptor later in the chain. This is an error in the extension or
  15. // interceptor and not user code since errors should be trapped and returned in the format expected by the transformer
  16. if (body instanceof Throwable) {
  17. throw new ServiceRuntimeException("Unexpected exception returned", (Throwable) body);
  18. } else {
  19. throw new ServiceRuntimeException("Unexpected type returned: " + body.getClass());
  20. }
  21. } catch (Fabric3Exception e) {
  22. throw new ServiceRuntimeException(e);
  23. }
  24. }
  25. return ret;
  26. }

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

  1. public Message invoke(Message message) {
  2. Object[] args = (Object[]) message.getBody();
  3. ClassLoader old = Thread.currentThread().getContextClassLoader();
  4. try {
  5. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  6. Object body = response.build(args);
  7. message.reset();
  8. message.setBody(body);
  9. } catch (RuntimeException e) {
  10. throw new ServiceRuntimeException(e);
  11. } finally {
  12. Thread.currentThread().setContextClassLoader(old);
  13. }
  14. return message;
  15. }

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

  1. public boolean handleMessage(SOAPMessageContext smc) {
  2. Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
  3. WorkContext workContext = WorkContextCache.getThreadWorkContext();
  4. workContext = (WorkContext) (workContext == null ? smc.get(MetroConstants.WORK_CONTEXT) : workContext);
  5. if (workContext == null) {
  6. throw new ServiceRuntimeException("Work context not set");
  7. }
  8. if (outbound) {
  9. // reference proxy outbound or service invocation return
  10. Message msg = MessageCache.getMessage();
  11. if (msg.getWorkContext() == null) {
  12. // service invocation return
  13. msg.setBody(smc.getMessage());
  14. msg.setWorkContext(workContext);
  15. }
  16. delegateHandler.handleOutbound(msg, smc.getMessage());
  17. } else {
  18. // reference proxy invocation return or service invocation
  19. Message msg = MessageCache.getMessage();
  20. if (msg.getWorkContext() == null) {
  21. // reference proxy return
  22. msg.setBody(smc.getMessage());
  23. msg.setWorkContext(workContext);
  24. }
  25. delegateHandler.handleInbound(smc.getMessage(), msg);
  26. msg.reset();
  27. }
  28. return true;
  29. }

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

  1. public void run() {
  2. Message request = MessageCache.getAndResetMessage();
  3. try {
  4. request.setBody(frames[0]);
  5. int methodIndex = ByteBuffer.wrap(frames[1]).getInt();
  6. WorkContext context = setWorkContext(frames[2]);
  7. request.setWorkContext(context);
  8. Interceptor interceptor = interceptors[methodIndex];
  9. interceptor.invoke(request);
  10. } finally {
  11. request.reset();
  12. }
  13. }
  14. });

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

  1. ftpClient.connect(hostAddress, port);
  2. monitor.onResponse(ftpClient.getReplyString());
  3. String type = msg.getWorkContext().getHeader(String.class, FtpConstants.HEADER_CONTENT_TYPE);
  4. if (type != null && type.equalsIgnoreCase(FtpConstants.BINARY_TYPE)) {
  5. monitor.onCommand("TYPE I");
  6. monitor.onResponse(ftpClient.getReplyString());
  7. Object[] args = (Object[]) msg.getBody();
  8. String fileName = (String) args[0];
  9. String remoteFileLocation = fileName;
  10. msg.reset();
  11. return msg;

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

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

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

  1. private Object handleFault(Message ret) throws InvocationTargetException {
  2. if (ret.getBody() instanceof ServiceRuntimeException) {
  3. ServiceRuntimeException e = (ServiceRuntimeException) ret.getBody();
  4. if (e.getCause() instanceof NotAuthorizedException) {
  5. // authorization exceptions need to be mapped to a client 403 response
  6. throw new InvocationTargetException(new WebApplicationException(Response.Status.FORBIDDEN));
  7. }
  8. throw new InvocationTargetException(e);
  9. }
  10. throw new InvocationTargetException((Throwable) ret.getBody());
  11. }

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

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

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

  1. /**
  2. * Resets and returns the Message for the current thread.
  3. *
  4. * @return the Message for the current thread
  5. */
  6. public static Message getAndResetMessage() {
  7. Message message = getMessage();
  8. message.reset();
  9. return message;
  10. }
  11. }

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

  1. private void sendResponse(Message request, Session responseSession, org.fabric3.spi.container.invocation.Message outMessage, Message response)
  2. throws JMSException, JmsBadMessageException {
  3. CorrelationScheme correlationScheme = wireHolder.getCorrelationScheme();
  4. switch (correlationScheme) {
  5. case CORRELATION_ID: {
  6. response.setJMSCorrelationID(request.getJMSCorrelationID());
  7. break;
  8. }
  9. case MESSAGE_ID: {
  10. response.setJMSCorrelationID(request.getJMSMessageID());
  11. break;
  12. }
  13. }
  14. if (outMessage.isFault()) {
  15. response.setBooleanProperty(JmsRuntimeConstants.FAULT_HEADER, true);
  16. }
  17. MessageProducer producer;
  18. if (request.getJMSReplyTo() != null) {
  19. // if a reply to destination is set, use it
  20. producer = responseSession.createProducer(request.getJMSReplyTo());
  21. } else {
  22. if (defaultResponseDestination == null) {
  23. throw new JmsBadMessageException("JMSReplyTo must be set as no response destination was configured on the service");
  24. }
  25. producer = responseSession.createProducer(defaultResponseDestination);
  26. }
  27. producer.send(response);
  28. }

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

  1. /**
  2. * Adds F3-specific routing headers to a message.
  3. *
  4. * @param message the invocation message
  5. * @param jmsMessage the JMS message to be dispatched
  6. * @throws JMSException if an error occurs setting the headers
  7. * @throws IOException if an error occurs serializing the routing information
  8. */
  9. private void setRoutingHeaders(Message message, javax.jms.Message jmsMessage) throws JMSException, IOException {
  10. List<String> stack = message.getWorkContext().getCallbackReferences();
  11. if (stack == null || stack.isEmpty()) {
  12. return;
  13. }
  14. jmsMessage.setObjectProperty(JmsRuntimeConstants.CONTEXT_HEADER, CallbackReferenceSerializer.serializeToString(stack));
  15. }

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

  1. public Message invoke(Message msg) {
  2. Object body = msg.getBody();
  3. if (body == null || !body.getClass().isArray()) {
  4. return next.invoke(msg);
  5. }
  6. Object[] payload = (Object[]) body;
  7. if (payload.length != 1) {
  8. throw new ServiceRuntimeException("Unexpected payload size: " + payload.length);
  9. }
  10. msg.setBody(payload[0]);
  11. return next.invoke(msg);
  12. }

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

  1. private Message transformOutput(Message ret) {
  2. // FIXME For exception transformation, if it is checked convert as application fault
  3. Object body = ret.getBody();
  4. // TODO handle null types
  5. if (body != null) {
  6. try {
  7. Object transformed = outTransformer.transform(body, outLoader);
  8. if (ret.isFault()) {
  9. ret.setBodyWithFault(transformed);
  10. } else {
  11. ret.setBody(transformed);
  12. }
  13. } catch (ClassCastException e) {
  14. // an unexpected type was returned by the target service or an interceptor later in the chain. This is an error in the extension or
  15. // interceptor and not user code since errors should be trapped and returned in the format expected by the transformer
  16. if (body instanceof Throwable) {
  17. throw new ServiceRuntimeException("Unexpected exception returned", (Throwable) body);
  18. } else {
  19. throw new ServiceRuntimeException("Unexpected type returned: " + body.getClass());
  20. }
  21. } catch (Fabric3Exception e) {
  22. throw new ServiceRuntimeException(e);
  23. }
  24. }
  25. return ret;
  26. }

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

  1. public Message invoke(Message message) {
  2. Object[] args = (Object[]) message.getBody();
  3. ClassLoader old = Thread.currentThread().getContextClassLoader();
  4. try {
  5. Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
  6. Object body = response.build(args);
  7. message.reset();
  8. message.setBody(body);
  9. } catch (RuntimeException e) {
  10. throw new ServiceRuntimeException(e);
  11. } finally {
  12. Thread.currentThread().setContextClassLoader(old);
  13. }
  14. return message;
  15. }

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

  1. public boolean handleMessage(SOAPMessageContext smc) {
  2. Boolean outbound = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
  3. WorkContext workContext = WorkContextCache.getThreadWorkContext();
  4. workContext = (WorkContext) (workContext == null ? smc.get(MetroConstants.WORK_CONTEXT) : workContext);
  5. if (workContext == null) {
  6. throw new ServiceRuntimeException("Work context not set");
  7. }
  8. if (outbound) {
  9. // reference proxy outbound or service invocation return
  10. Message msg = MessageCache.getMessage();
  11. if (msg.getWorkContext() == null) {
  12. // service invocation return
  13. msg.setBody(smc.getMessage());
  14. msg.setWorkContext(workContext);
  15. }
  16. delegateHandler.handleOutbound(msg, smc.getMessage());
  17. } else {
  18. // reference proxy invocation return or service invocation
  19. Message msg = MessageCache.getMessage();
  20. if (msg.getWorkContext() == null) {
  21. // reference proxy return
  22. msg.setBody(smc.getMessage());
  23. msg.setWorkContext(workContext);
  24. }
  25. delegateHandler.handleInbound(smc.getMessage(), msg);
  26. msg.reset();
  27. }
  28. return true;
  29. }

相关文章