use of org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor in project incubator-servicecomb-java-chassis by apache.
the class RestOperationMeta method createProduceProcessors.
// 为operation创建支持的多种produce processor
protected void createProduceProcessors() {
if (null == produces || produces.isEmpty()) {
for (ProduceProcessor processor : ProduceProcessorManager.INSTANCE.values()) {
this.produceProcessorMap.put(processor.getName(), processor);
}
} else {
for (String produce : produces) {
ProduceProcessor processor = ProduceProcessorManager.INSTANCE.findValue(produce);
if (processor == null) {
LOGGER.error("produce {} is not supported", produce);
continue;
}
this.produceProcessorMap.put(produce, processor);
}
if (produceProcessorMap.isEmpty()) {
produceProcessorMap.put(ProduceProcessorManager.DEFAULT_TYPE, ProduceProcessorManager.DEFAULT_PROCESSOR);
}
}
defaultProcessor = produceProcessorMap.values().stream().findFirst().get();
produceProcessorMap.putIfAbsent(MediaType.WILDCARD, defaultProcessor);
}
use of org.apache.servicecomb.common.rest.codec.produce.ProduceProcessor in project incubator-servicecomb-java-chassis by apache.
the class ServerRestArgsFilter method beforeSendResponse.
@Override
public void beforeSendResponse(Invocation invocation, HttpServletResponseEx responseEx) {
Response response = (Response) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_RESPONSE);
ProduceProcessor produceProcessor = (ProduceProcessor) responseEx.getAttribute(RestConst.INVOCATION_HANDLER_PROCESSOR);
Object body = response.getResult();
if (response.isFailed()) {
body = ((InvocationException) body).getErrorData();
}
try (BufferOutputStream output = new BufferOutputStream(Unpooled.compositeBuffer())) {
produceProcessor.encodeResponse(output, body);
responseEx.setBodyBuffer(output.getBuffer());
} catch (Throwable e) {
throw ExceptionFactory.convertProducerException(e);
}
}
Aggregations