org.fabric3.spi.container.invocation.Message.setBody()方法的使用及代码示例

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

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

Message.setBody介绍

[英]Sets the body of the message.
[中]设置消息的正文。

代码示例

代码示例来源: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: com.carecon.fabric3/fabric3-system

  1. public Message invoke(Message msg) {
  2. Object body = msg.getBody();
  3. Object instance;
  4. try {
  5. instance = component.getInstance();
  6. } catch (Fabric3Exception e) {
  7. throw new InvocationRuntimeException(e);
  8. }
  9. try {
  10. msg.setBody(operation.invoke(instance, (Object[]) body));
  11. } catch (InvocationTargetException e) {
  12. msg.setBodyWithFault(e.getCause());
  13. } catch (IllegalAccessException e) {
  14. throw new InvocationRuntimeException(e);
  15. } finally {
  16. try {
  17. component.releaseInstance(instance);
  18. } catch (Fabric3Exception e) {
  19. throw new InvocationRuntimeException(e);
  20. }
  21. }
  22. return msg;
  23. }
  24. }

代码示例来源: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-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-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-pojo

  1. public Object newInstance() throws Fabric3Exception {
  2. ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  3. Thread.currentThread().setContextClassLoader(cl);
  4. try {
  5. // FABRIC-40: if a component invokes services from a setter, the message content will be over-written. Save so it can be restored after instance
  6. // injection.
  7. Message message = MessageCache.getMessage();
  8. Object content = message.getBody();
  9. Object instance = constructor.get();
  10. if (injectors != null) {
  11. for (Injector<Object> injector : injectors) {
  12. injector.inject(instance);
  13. }
  14. }
  15. // restore the original contents
  16. message.setBody(content);
  17. return instance;
  18. } finally {
  19. Thread.currentThread().setContextClassLoader(oldCl);
  20. }
  21. }

代码示例来源: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-pojo

  1. public Object newInstance() throws Fabric3Exception {
  2. ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  3. Thread.currentThread().setContextClassLoader(cl);
  4. try {
  5. // FABRIC-40: if a component invokes services from a setter, the message content will be over-written. Save so it can be restored after instance
  6. // injection.
  7. Message message = MessageCache.getMessage();
  8. Object content = message.getBody();
  9. Object instance = constructor.get();
  10. if (injectors != null) {
  11. for (Injector<Object> injector : injectors) {
  12. injector.inject(instance);
  13. }
  14. }
  15. // restore the original contents
  16. message.setBody(content);
  17. return instance;
  18. } finally {
  19. Thread.currentThread().setContextClassLoader(oldCl);
  20. }
  21. }

代码示例来源: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: 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 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-fabric

  1. private void transformInput(Message msg) {
  2. Object params = msg.getBody();
  3. // TODO handle null types
  4. if (params != null) {
  5. try {
  6. // Operations take 0..n parameters. A single parameter must be unwrapped from the invocation array and passed to a transformer.
  7. // In contrast, multiple parameter operations are passed as an array to the transformer.
  8. if (params.getClass().isArray() && ((Object[]) params).length == 1) {
  9. Object[] paramArray = (Object[]) params;
  10. paramArray[0] = inTransformer.transform(paramArray[0], inLoader);
  11. } else {
  12. // multiple parameters - pass the entire array to transform
  13. Object transformed = inTransformer.transform(params, inLoader);
  14. msg.setBody(transformed);
  15. }
  16. } catch (Fabric3Exception e) {
  17. throw new ServiceRuntimeException(e);
  18. }
  19. }
  20. }

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

  1. private void transformInput(Message msg) {
  2. Object params = msg.getBody();
  3. // TODO handle null types
  4. if (params != null) {
  5. try {
  6. // Operations take 0..n parameters. A single parameter must be unwrapped from the invocation array and passed to a transformer.
  7. // In contrast, multiple parameter operations are passed as an array to the transformer.
  8. if (params.getClass().isArray() && ((Object[]) params).length == 1) {
  9. Object[] paramArray = (Object[]) params;
  10. paramArray[0] = inTransformer.transform(paramArray[0], inLoader);
  11. } else {
  12. // multiple parameters - pass the entire array to transform
  13. Object transformed = inTransformer.transform(params, inLoader);
  14. msg.setBody(transformed);
  15. }
  16. } catch (Fabric3Exception e) {
  17. throw new ServiceRuntimeException(e);
  18. }
  19. }
  20. }

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

  1. public Message invoke(Message msg) {
  2. Object body = msg.getBody();
  3. if (body == null || !body.getClass().isArray()) {
  4. throw new ServiceRuntimeException("Invalid parameter type: " + body);
  5. }
  6. int length = Array.getLength(body);
  7. if (length != 1) {
  8. throw new ServiceRuntimeException("Invalid number of parameters: " + length);
  9. }
  10. Object element = Array.get(body, 0);
  11. if (!(element instanceof String)) {
  12. throw new ServiceRuntimeException("Parameter must be a string: " + element);
  13. }
  14. File file = new File(outputDirectory, (String) element);
  15. try {
  16. OutputStream stream = adapter.createOutputStream(file);
  17. msg.setBody(stream);
  18. return msg;
  19. } catch (IOException e) {
  20. throw new ServiceRuntimeException(e);
  21. }
  22. }

代码示例来源: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-binding-ws

  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-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. // invoke the service
  10. Message response = interceptor.invoke(request);
  11. Object responseBody = response.getBody();
  12. if (!(responseBody instanceof byte[])) {
  13. throw new ServiceRuntimeException("Return value not serialized");
  14. }
  15. // queue the response
  16. try {
  17. queue.put(new Response(clientId, (byte[]) responseBody));
  18. } catch (InterruptedException e) {
  19. Thread.interrupted();
  20. }
  21. } finally {
  22. request.reset();
  23. // context.reset();
  24. }
  25. }
  26. });

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

  1. public void run() {
  2. WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext();
  3. workContext.addCallbackReferences(stack);
  4. workContext.addHeaders(headers);
  5. workContext.setSubject(subject);
  6. Message message = MessageCache.getAndResetMessage();
  7. message.setBody(payload);
  8. message.setWorkContext(workContext);
  9. Message response = next.invoke(message);
  10. if (response.isFault()) {
  11. // log the exception
  12. monitor.onError((Throwable) response.getBody());
  13. }
  14. message.reset();
  15. workContext.reset();
  16. }

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

  1. public boolean onUpload(String fileName, String contentType, InputStream uploadData) throws Exception {
  2. Object[] args = new Object[]{fileName, uploadData};
  3. WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext();
  4. Message input = MessageCache.getAndResetMessage();
  5. try {
  6. // set the header value for the request context
  7. workContext.setHeader(FtpConstants.HEADER_CONTENT_TYPE, contentType);
  8. input.setWorkContext(workContext);
  9. input.setBody(args);
  10. Message response = getInterceptor().invoke(input);
  11. if (response.isFault()) {
  12. monitor.fileProcessingError(servicePath, (Throwable) response.getBody());
  13. input.reset();
  14. return false;
  15. }
  16. return true;
  17. } finally {
  18. input.reset();
  19. workContext.reset();
  20. }
  21. }

相关文章