private String serialize(final Serializable serializable) { if (serializable == null) { return null; } ByteArrayOutputStream out = new ByteArrayOutputStream(); try { final Marshaller marshaller = factory.createMarshaller(configuration); marshaller.start(new OutputStreamByteOutput(out)); marshaller.writeObject(serializable); marshaller.finish(); out.flush(); } catch (IOException e) { throw new RuntimeException(e); } return Base64.getEncoder().encodeToString(out.toByteArray()); }
@Override public void write(DataOutput output) throws IOException { output.writeByte(QUERY_NAMES); output.writeInt(correlationId); output.writeByte(OBJECT_NAME); Marshaller marshaller = prepareForMarshalling(output); marshaller.writeObject(name); marshaller.writeByte(QUERY_EXP); marshaller.writeObject(query); marshaller.close(); } });
/** {@inheritDoc} */ public void flush() throws IOException { marshaller.flush(); }
@Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); marshaller.start(new ChannelBufferByteOutput(out)); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); }
@Override public void write(DataOutput output) throws IOException { output.writeByte(SEND_NOTIFICATION); output.writeInt(0x00); output.writeByte(INTEGER); output.writeInt(listenerId); output.writeByte(NOTIFICATION); Marshaller marshaller = prepareForMarshalling(output); marshaller.writeObject(notification); marshaller.writeByte(OBJECT); marshaller.writeObject(handback); marshaller.finish(); } });
@Override public <R> byte[] marshal(Command<R, ? super C> command) throws IOException { int version = this.context.getCurrentVersion(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try (DataOutputStream output = new DataOutputStream(bytes)) { IndexSerializer.VARIABLE.writeInt(output, version); try (Marshaller marshaller = this.context.createMarshaller(version)) { marshaller.start(Marshalling.createByteOutput(output)); marshaller.writeObject(this.id); marshaller.writeObject(command); marshaller.flush(); } return bytes.toByteArray(); } } }
private void writeFailedResponse(final int invId, final Throwable e) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.APPLICATION_EXCEPTION); os.writeShort(invId); final Marshaller marshaller = marshallerFactory.createMarshaller(configuration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os))); marshaller.writeObject(new RequestSendFailedException(e.getMessage() + "@" + channel.getConnection().getPeerURI(), e)); marshaller.writeByte(0); marshaller.finish(); } catch (IOException e2) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB response write failed", e2); } }
@Override public void handleRequest(HttpServerExchange exchange) throws Exception { try { String timeoutString = exchange.getRequestHeaders().getFirst(TransactionConstants.TIMEOUT); if (timeoutString == null) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s is missing %s header", exchange, TransactionConstants.TIMEOUT); return; } final Integer timeout = Integer.parseInt(timeoutString); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, TransactionConstants.NEW_TRANSACTION.toString()); final LocalTransaction transaction = transactionContext.beginTransaction(timeout); final Xid xid = xidResolver.apply(transaction); final ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf()); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out))); marshaller.writeInt(xid.getFormatId()); marshaller.writeInt(xid.getGlobalTransactionId().length); marshaller.write(xid.getGlobalTransactionId()); marshaller.writeInt(xid.getBranchQualifier().length); marshaller.write(xid.getBranchQualifier()); marshaller.finish(); exchange.getResponseSender().send(ByteBuffer.wrap(out.toByteArray())); } catch (Exception e) { sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e); } } }
try (MessageOutputStream messageOutputStream = tracker.allocateMessage(invocation)) { messageOutputStream.writeByte(rebind ? Protocol.CMD_REBIND : Protocol.CMD_BIND); writeId(messageOutputStream, version, invocation.getIndex()); if (version == 1) { try (Marshaller marshaller = createMarshaller(messageOutputStream, configuration)) { marshaller.writeByte(Protocol.P_NAME); marshaller.writeObject(NamingUtils.toDecomposedCompositeName(name)); marshaller.writeByte(Protocol.P_OBJECT); marshaller.writeObject(obj); messageOutputStream.writeInt(authId); messageOutputStream.writeUTF(NamingUtils.toCompositeName(name).toString()); try (Marshaller marshaller = createMarshaller(messageOutputStream, configuration)) { marshaller.writeObject(obj);
/** * Serializes an object into a byte buffer. The object has to implement interface Serializable or Externalizable */ byte[] objectToByteBufferInternal(Object object) throws Exception { Marshaller marshaller = marshallerFactory.createMarshaller(this.marshallingConfig); ByteArrayOutputStream output = new ByteArrayOutputStream(); marshaller.start(Marshalling.createByteOutput(output)); marshaller.writeObject(object); marshaller.close(); return output.toByteArray(); }
public static Marshaller createMarshaller(MessageOutputStream os, MarshallingConfiguration configuration) throws IOException { final Marshaller marshaller = riverMarshallerFactory.createMarshaller(configuration); marshaller.start(new OutputStreamByteOutput(os) { @Override public void flush() throws IOException { //ignore flushes, all they do is wreck performance as you get a double flush when closing the marshaller //which results in two network packets being sent } }); return marshaller; }
/** * Creates and returns a {@link org.jboss.marshalling.Marshaller} which is ready to be used for marshalling. The * {@link org.jboss.marshalling.Marshaller#start(org.jboss.marshalling.ByteOutput)} will be invoked by this method, to use * the passed {@link java.io.DataOutput dataOutput}, before returning the marshaller. * * @param dataOutput The {@link java.io.DataOutput} to which the data will be marshalled * @return * @throws IOException */ protected org.jboss.marshalling.Marshaller prepareForMarshalling(final DataOutput dataOutput) throws IOException { final org.jboss.marshalling.Marshaller marshaller = this.getMarshaller(marshallerFactory); final OutputStream outputStream = new OutputStream() { @Override public void write(int b) throws IOException { final int byteToWrite = b & 0xff; dataOutput.write(byteToWrite); } }; final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream); // start the marshaller marshaller.start(byteOutput); return marshaller; }
mos.writeByte(messageId); writeId(mos, version, id); mos.writeByte(Protocol.SUCCESS); if (version == 1) { mos.writeByte(Protocol.P_LIST); mos.writeInt(resultList.size()); for (Binding binding : resultList) { if (binding.getObject() instanceof Context) { marshaller.writeByte(Protocol.P_CONTEXT); marshaller.writeUTF(binding.getName()); } else { marshaller.writeByte(Protocol.P_BINDING); marshaller.writeObject(binding);
public void writeClass(final Marshaller marshaller, final Class<?> clazz) throws IOException { marshaller.write(1); final Module module = Module.forClass(clazz); if (module == null) { marshaller.writeObject(null); } else { final ModuleIdentifier identifier = module.getIdentifier(); marshaller.writeObject(identifier.getName()); marshaller.writeObject(identifier.getSlot()); } final Class<?>[] interfaces = clazz.getInterfaces(); marshaller.writeInt(interfaces.length); for (Class<?> interfaze : interfaces) { marshaller.writeObject(interfaze.getName()); } } }
private void writeExceptionResponse(final Exception e, final int messageId, final int id) throws IOException { try (MessageOutputStream mos = messageTracker.openMessageUninterruptibly()) { mos.writeByte(messageId); writeId(mos, version, id); mos.writeByte(Protocol.FAILURE); mos.writeByte(Protocol.P_EXCEPTION); try (Marshaller marshaller = createMarshaller(mos, configuration)) { marshaller.writeObject(e); } } }
public void writeClass(final Marshaller marshaller, final Class<?> clazz) throws IOException { marshaller.write(0); final Module module = Module.forClass(clazz); if (module == null) { marshaller.writeObject(null); } else { final ModuleIdentifier identifier = module.getIdentifier(); marshaller.writeObject(identifier.getName()); marshaller.writeObject(identifier.getSlot()); } marshaller.writeObject(clazz.getName()); } }
/** * Construct a new instance that delegates to the given marshaller. * * @param marshaller the delegate marshaller * @throws java.io.IOException if an I/O error occurs * @throws SecurityException if the caller does not have permission to construct an instance of this class */ protected MarshallingObjectOutputStream(final Marshaller marshaller, final ByteOutput byteOutput) throws IOException, SecurityException { marshaller.start(byteOutput); this.marshaller = marshaller; }
/** {@inheritDoc} */ public final void close() throws IOException { marshaller.finish(); marshaller = null; }
/** {@inheritDoc} */ public void write(final byte[] buf) throws IOException { marshaller.write(buf, 0, buf.length); }
/** {@inheritDoc} */ public void write(final Marshaller marshaller) throws IOException { marshaller.writeByte(value); }