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

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

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

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

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

public Message invoke(Message msg) {
    Object body = msg.getBody();
    Object instance;
    try {
      instance = component.getInstance();
    } catch (Fabric3Exception e) {
      throw new InvocationRuntimeException(e);
    }

    try {
      msg.setBody(operation.invoke(instance, (Object[]) body));
    } catch (InvocationTargetException e) {
      msg.setBodyWithFault(e.getCause());
    } catch (IllegalAccessException e) {
      throw new InvocationRuntimeException(e);
    } finally {
      try {
        component.releaseInstance(instance);
      } catch (Fabric3Exception e) {
        throw new InvocationRuntimeException(e);
      }
    }
    return msg;
  }
}

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

public Object newInstance() throws Fabric3Exception {
  ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  Thread.currentThread().setContextClassLoader(cl);
  try {
    // 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
    // injection.
    Message message = MessageCache.getMessage();
    Object content = message.getBody();
    Object instance = constructor.get();
    if (injectors != null) {
      for (Injector<Object> injector : injectors) {
        injector.inject(instance);
      }
    }
    // restore the original contents
    message.setBody(content);
    return instance;
  } finally {
    Thread.currentThread().setContextClassLoader(oldCl);
  }
}

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

public Object newInstance() throws Fabric3Exception {
  ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
  Thread.currentThread().setContextClassLoader(cl);
  try {
    // 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
    // injection.
    Message message = MessageCache.getMessage();
    Object content = message.getBody();
    Object instance = constructor.get();
    if (injectors != null) {
      for (Injector<Object> injector : injectors) {
        injector.inject(instance);
      }
    }
    // restore the original contents
    message.setBody(content);
    return instance;
  } finally {
    Thread.currentThread().setContextClassLoader(oldCl);
  }
}

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

private void transformInput(Message msg) {
  Object params = msg.getBody();
  // TODO handle null types
  if (params != null) {
    try {
      // Operations take 0..n parameters. A single parameter must be unwrapped from the invocation array and passed to a transformer.
      // In contrast, multiple parameter operations are passed as an array to the transformer.
      if (params.getClass().isArray() && ((Object[]) params).length == 1) {
        Object[] paramArray = (Object[]) params;
        paramArray[0] = inTransformer.transform(paramArray[0], inLoader);
      } else {
        // multiple parameters - pass the entire array to transform
        Object transformed = inTransformer.transform(params, inLoader);
        msg.setBody(transformed);
      }
    } catch (Fabric3Exception e) {
      throw new ServiceRuntimeException(e);
    }
  }
}

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

private void transformInput(Message msg) {
  Object params = msg.getBody();
  // TODO handle null types
  if (params != null) {
    try {
      // Operations take 0..n parameters. A single parameter must be unwrapped from the invocation array and passed to a transformer.
      // In contrast, multiple parameter operations are passed as an array to the transformer.
      if (params.getClass().isArray() && ((Object[]) params).length == 1) {
        Object[] paramArray = (Object[]) params;
        paramArray[0] = inTransformer.transform(paramArray[0], inLoader);
      } else {
        // multiple parameters - pass the entire array to transform
        Object transformed = inTransformer.transform(params, inLoader);
        msg.setBody(transformed);
      }
    } catch (Fabric3Exception e) {
      throw new ServiceRuntimeException(e);
    }
  }
}

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

public Message invoke(Message msg) {
  Object body = msg.getBody();
  if (body == null || !body.getClass().isArray()) {
    throw new ServiceRuntimeException("Invalid parameter type: " + body);
  }
  int length = Array.getLength(body);
  if (length != 1) {
    throw new ServiceRuntimeException("Invalid number of parameters: " + length);
  }
  Object element = Array.get(body, 0);
  if (!(element instanceof String)) {
    throw new ServiceRuntimeException("Parameter must be a string: " + element);
  }
  File file = new File(outputDirectory, (String) element);
  try {
    OutputStream stream = adapter.createOutputStream(file);
    msg.setBody(stream);
    return msg;
  } catch (IOException e) {
    throw new ServiceRuntimeException(e);
  }
}

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

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-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];
      // invoke the service
      Message response = interceptor.invoke(request);
      Object responseBody = response.getBody();
      if (!(responseBody instanceof byte[])) {
        throw new ServiceRuntimeException("Return value not serialized");
      }
      // queue the response
      try {
        queue.put(new Response(clientId, (byte[]) responseBody));
      } catch (InterruptedException e) {
        Thread.interrupted();
      }
    } finally {
      request.reset();
      //                    context.reset();
    }
  }
});

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

public void run() {
  WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext();
  workContext.addCallbackReferences(stack);
  workContext.addHeaders(headers);
  workContext.setSubject(subject);
  Message message = MessageCache.getAndResetMessage();
  message.setBody(payload);
  message.setWorkContext(workContext);
  Message response = next.invoke(message);
  if (response.isFault()) {
    // log the exception
    monitor.onError((Throwable) response.getBody());
  }
  message.reset();
  workContext.reset();
}

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

public boolean onUpload(String fileName, String contentType, InputStream uploadData) throws Exception {
  Object[] args = new Object[]{fileName, uploadData};
  WorkContext workContext = WorkContextCache.getAndResetThreadWorkContext();
  Message input = MessageCache.getAndResetMessage();
  try {
    // set the header value for the request context
    workContext.setHeader(FtpConstants.HEADER_CONTENT_TYPE, contentType);
    input.setWorkContext(workContext);
    input.setBody(args);
    Message response = getInterceptor().invoke(input);
    if (response.isFault()) {
      monitor.fileProcessingError(servicePath, (Throwable) response.getBody());
      input.reset();
      return false;
    }
    return true;
  } finally {
    input.reset();
    workContext.reset();
  }
}

相关文章