@Override public String toString(SoaHeader bean) { return bean == null ? "null" : bean.toString(); }
@Override public String toString(SoaHeader bean) { return bean == null ? "null" : bean.toString(); }
@Override public void doFilter(FilterChain chain) throws TException { final SoaHeader soaHeader = (SoaHeader) chain.getAttribute(StubFilterChain.ATTR_KEY_HEADER); final Object request = chain.getAttribute(StubFilterChain.ATTR_KEY_REQUEST); LOGGER.info("{} {} {} request header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), soaHeader.toString(), request.toString()); try { chain.doFilter(); } finally { Object response = chain.getAttribute(StubFilterChain.ATTR_KEY_RESPONSE); if (response != null) LOGGER.info("{} {} {} response header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), soaHeader.toString(), formatToString(response.toString())); } }
private void writeErrorMessage(ChannelHandlerContext ctx, ByteBuf outputBuf, TransactionContext context, SoaHeader soaHeader, TSoaTransport outputSoaTransport, TSoaServiceProtocol outputProtocol, SoaException e) { if (outputProtocol != null) { try { if (outputBuf.writerIndex() > 0) outputBuf.writerIndex(Integer.BYTES); soaHeader.setRespCode(Optional.ofNullable(e.getCode())); soaHeader.setRespMessage(Optional.ofNullable(e.getMsg())); outputProtocol.writeMessageBegin(new TMessage(soaHeader.getServiceName() + ":" + soaHeader.getMethodName(), TMessageType.REPLY, context.getSeqid())); outputProtocol.writeMessageEnd(); outputSoaTransport.flush(); ctx.writeAndFlush(outputBuf); LOGGER.info("{} {} {} response header:{} body:{null}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), soaHeader.toString()); } catch (Throwable e1) { LOGGER.error(e1.getMessage(), e1); } } } }
/** * 异步处理,当返回结果被complete时调用 * * @param context * @param soaProcessFunction * @param result * @param out * @param future */ private void AsyncAccept(Context context, SoaProcessFunction<I, Object, Object, ? extends TBeanSerializer<Object>, ? extends TBeanSerializer<Object>> soaProcessFunction, Object result, TProtocol out, CompletableFuture future) { try { TransactionContext.Factory.setCurrentInstance((TransactionContext) context); SoaHeader soaHeader = context.getHeader(); LOGGER.info("{} {} {} {} response header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getResSerializer().toString(result))); soaHeader.setRespCode(Optional.of("0000")); soaHeader.setRespMessage(Optional.of("成功")); out.writeMessageBegin(new TMessage(soaHeader.getMethodName(), TMessageType.CALL, context.getSeqid())); soaProcessFunction.getResSerializer().write(result, out); out.writeMessageEnd(); /** * 通知外层handler处理结果 */ future.complete(context); } catch (TException e) { e.printStackTrace(); } }
/** * 异步处理,当返回结果被complete时调用 * * @param context * @param soaProcessFunction * @param result * @param out * @param future */ private void AsyncAccept(Context context, SoaProcessFunction<I, Object, Object, ? extends TCommonBeanSerializer<Object>, ? extends TCommonBeanSerializer<Object>> soaProcessFunction, Object result, TProtocol out, CompletableFuture future) { try { TransactionContext.Factory.setCurrentInstance((TransactionContext) context); SoaHeader soaHeader = context.getHeader(); LOGGER.info("{} {} {} {} response header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getResSerializer().toString(result))); soaHeader.setRespCode(Optional.of("0000")); soaHeader.setRespMessage(Optional.of("成功")); out.writeMessageBegin(new TMessage(soaHeader.getMethodName(), TMessageType.CALL, context.getSeqid())); soaProcessFunction.getResSerializer().write(result, out); out.writeMessageEnd(); /** * 通知外层handler处理结果 */ future.complete(context); } catch (TException e) { e.printStackTrace(); } }
/** * 异步处理,当返回结果被complete时调用 * * @param context * @param soaProcessFunction * @param result * @param out * @param future */ private void AsyncAccept(Context context, SoaProcessFunction<I, Object, Object, ? extends TBeanSerializer<Object>, ? extends TBeanSerializer<Object>> soaProcessFunction, Object result, TProtocol out, CompletableFuture future) { try { TransactionContext.Factory.setCurrentInstance((TransactionContext) context); SoaHeader soaHeader = context.getHeader(); LOGGER.info("{} {} {} {} response header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getResSerializer().toString(result))); soaHeader.setRespCode(Optional.of("0000")); soaHeader.setRespMessage(Optional.of("成功")); out.writeMessageBegin(new TMessage(soaHeader.getMethodName(), TMessageType.CALL, context.getSeqid())); soaProcessFunction.getResSerializer().write(result, out); out.writeMessageEnd(); /** * 通知外层handler处理结果 */ future.complete(context); } catch (TException e) { e.printStackTrace(); } }
LOGGER.info("{} {} {} {} request header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getReqSerializer().toString(args))); long startTime = System.currentTimeMillis(); try { result = soaProcessFunction.getResult(iface, args); LOGGER.info("{} {} {} {} response header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getResSerializer().toString(result))); } finally { chain.setAttribute(ContainerFilterChain.ATTR_KEY_I_PROCESSTIME, System.currentTimeMillis() - startTime);
LOGGER.info("{} {} {} {} request header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getReqSerializer().toString(args))); long startTime = System.currentTimeMillis();
LOGGER.info("{} {} {} {} request header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getReqSerializer().toString(args))); long startTime = System.currentTimeMillis();
LOGGER.info("{} {} {} {} request header:{} body:{}", soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid(), soaHeader.toString(), formatToString(soaProcessFunction.getReqSerializer().toString(args))); long startTime = System.currentTimeMillis();
LogUtil.logDebug(SoaBaseProcessor.class,soaHeader,"{} {} {} {} request header:{} body:{}",soaHeader.getServiceName(), soaHeader.getVersionName(), soaHeader.getMethodName(), context.getSeqid().toString(), soaHeader.toString(), formatToString(soaProcessFunction.getReqSerializer().toString(args)));