private void beforeConsumerInvokeForSVC(Invocation invocation, TransactionRequestImpl request, TransactionResponseImpl response) { CompensableBeanRegistry beanRegistry = CompensableBeanRegistry.getInstance(); CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory(); TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor(); RemoteCoordinator compensableCoordinator = (RemoteCoordinator) beanFactory.getCompensableNativeParticipant(); Map<String, String> attachments = invocation.getAttachments(); attachments.put(RemoteCoordinator.class.getName(), compensableCoordinator.getIdentifier()); transactionInterceptor.beforeSendRequest(request); if (request.getTransactionContext() != null) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HessianOutput output = new HessianOutput(baos); try { output.writeObject(request.getTransactionContext()); } catch (IOException ex) { logger.error("Error occurred in remote call!", ex); throw new RemotingException(ex.getMessage()); } String transactionContextContent = ByteUtils.byteArrayToString(baos.toByteArray()); attachments.put(TransactionContext.class.getName(), transactionContextContent); } }
/** * @see com.taobao.notify.codec.Serializer#encodeObject(Object) */ @Override public byte[] encodeObject(final Object obj) throws IOException { ByteArrayOutputStream baos = null; HessianOutput output = null; try { baos = new ByteArrayOutputStream(1024); output = new HessianOutput(baos); output.startCall(); output.writeObject(obj); output.completeCall(); } catch (final IOException ex) { throw ex; } finally { if (output != null) { try { baos.close(); } catch (final IOException ex) { this.logger.error("Failed to close stream.", ex); } } } return baos != null ? baos.toByteArray() : null; }
public static byte[] serialize(Object obj) throws IOException { if (obj == null) throw new NullPointerException(); SerializerFactory serializerFactory = new SerializerFactory(); serializerFactory.addFactory(new BigDecimalSerializerFactory()); ByteArrayOutputStream os = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(os); ho.setSerializerFactory(serializerFactory); ho.writeObject(obj); return os.toByteArray(); }
out = new HessianOutput(osToUse);
@Override public void serialize(Object object, OutputStream outputStream) throws IOException { HessianOutput out = new HessianOutput(outputStream); out.setSerializerFactory(serializerFactory); out.writeObject(object); out.flush(); }
public static byte[] write(Object obj) { ByteArrayOutputStream os = new ByteArrayOutputStream(); HessianOutput ho = new HessianOutput(os); try { ho.writeObject(obj); return os.toByteArray(); } catch (IOException e) { throw new RuntimeException(e); } finally { try { ho.close(); os.close(); } catch (Exception ex) { } } }
/** * Client side of the handshake */ public static Response sendHandshake(Request request, Socket s) throws IOException { HessianInput input = new HessianInput(s.getInputStream()); HessianOutput output = new HessianOutput(s.getOutputStream()); output.findSerializerFactory().setAllowNonSerializable(true); output.writeObject(request); return (Response) input.readObject(); }
HessianCauchoOutput(OutputStream stream) { this.stream = stream; this.output = new HessianOutput(); output.setSerializerFactory(new JMXSerializerFactory()); output.init(stream); }
/** * Writes a complete method call. */ public void call(String method, Object []args) throws IOException { int length = args != null ? args.length : 0; startCall(method, length); for (int i = 0; i < length; i++) writeObject(args[i]); completeCall(); }
public AbstractHessianOutput getHessianOutput(OutputStream os) { AbstractHessianOutput out; if (_isHessian2Request) out = new Hessian2Output(os); else { HessianOutput out1 = new HessianOutput(os); out = out1; if (_isHessian2Reply) out1.setVersion(2); } out.setSerializerFactory(getSerializerFactory()); return out; }
writeString("code"); writeString(code); writeString("message"); writeString(message); writeString("detail"); writeObject(detail);
static public HessianOutput createHessianOutput(OutputStream out) { HessianOutput hout = new HessianOutput(out); hout.setSerializerFactory(_serializerFactory); return hout; }
public void writeObject(Object object) throws IOException { output.writeObject(object); }
/** * Creates a new Hessian output stream, initialized with an * underlying output stream. * * @param os the underlying output stream. */ public HessianOutput(OutputStream os) { init(os); }
public void completeCall() throws IOException { output.completeCall(); }
@Override protected void encode(ChannelHandlerContext ctx, Serializable msg, ByteBuf out) throws Exception { int startIdx = out.writerIndex(); ByteBufOutputStream bout = new ByteBufOutputStream(out); bout.write(LENGTH_PLACEHOLDER); // ObjectOutputStream oout = new CompactObjectOutputStream(bout); // oout.writeObject(msg); // oout.flush(); // oout.close(); HessianOutput hout = new HessianOutput(bout); hout.setSerializerFactory(SerializerFactoryUtil.getSerializerFactory()); hout.writeObject(msg); int endIdx = out.writerIndex(); out.setInt(startIdx, endIdx - startIdx - 4); } }
out = new HessianOutput(osToUse);
@Override public byte[] serialize(Object object) throws IOException { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); HessianOutput out = new HessianOutput(bytes); out.setSerializerFactory(serializerFactory); out.writeObject(object); out.flush(); return bytes.toByteArray(); }
person.setAge(j); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); HessianOutput hessianOutput = new HessianOutput(outputStream); hessianOutput.writeObject(person); hessianOutput.close(); ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); HessianInput hessianInput = new HessianInput(inputStream);
HessianOutput output = new HessianOutput(s.getOutputStream()); output.findSerializerFactory().setAllowNonSerializable(true); output.writeObject(response); return response.code == Code.OK ? new Player(request.name, Player.Role.valueOf(request.role), request.password) : null;