/** * 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; }
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; }
@Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); int lengthPos = out.writerIndex(); out.writeBytes(LENGTH_PLACEHOLDER); ChannelBufferByteOutput output = new ChannelBufferByteOutput(out); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); out.setInt(lengthPos, out.writerIndex() - lengthPos - 4); } }
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 protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); int lengthPos = out.writerIndex(); out.writeBytes(LENGTH_PLACEHOLDER); ChannelBufferByteOutput output = new ChannelBufferByteOutput(out); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); out.setInt(lengthPos, out.writerIndex() - lengthPos - 4); } }
@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 protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); int lengthPos = out.writerIndex(); out.writeBytes(LENGTH_PLACEHOLDER); ChannelBufferByteOutput output = new ChannelBufferByteOutput(out); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); out.setInt(lengthPos, out.writerIndex() - lengthPos - 4); } }
@Override public void objectToStream(Object object, DataOutput stream) throws Exception { int version = this.context.getCurrentVersion(); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try (DataOutputStream output = new DataOutputStream(bytes)) { this.versionSerializer.writeInt(output, version); try (Marshaller marshaller = this.context.createMarshaller(version)) { marshaller.start(Marshalling.createByteOutput(output)); marshaller.writeObject(object); marshaller.flush(); } } byte[] buffer = bytes.toByteArray(); IndexSerializer.VARIABLE.writeInt(stream, buffer.length); stream.write(buffer); }
@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 <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(); } } }
@Override protected void persistSerializedSessions(String deploymentName, Map<String, SessionEntry> serializedData) throws IOException { File file = new File(baseDir, deploymentName); FileOutputStream out = new FileOutputStream(file, false); try { Marshaller marshaller = createMarshaller(); try { marshaller.start(new OutputStreamByteOutput(out)); marshaller.writeObject(serializedData); marshaller.finish(); } finally { marshaller.close(); } } finally { IoUtils.safeClose(out); } }
@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(); }
byte[] getBytes() throws IOException { byte[] bytes = this.bytes; if (bytes != null) return bytes; if (this.object == null) return null; int version = this.context.getCurrentVersion(); ByteArrayOutputStream output = new ByteArrayOutputStream(); ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader()); try (SimpleDataOutput data = new SimpleDataOutput(Marshalling.createByteOutput(output))) { IndexSerializer.VARIABLE.writeInt(data, version); try (Marshaller marshaller = this.context.createMarshaller(version)) { marshaller.start(data); marshaller.writeObject(this.object); marshaller.finish(); return output.toByteArray(); } } finally { setThreadContextClassLoader(loader); } }
private static void doMarshall(HttpServerExchange exchange, Object result) throws IOException { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jndi-jbmar-value;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(exchange.getOutputStream()))); marshaller.writeObject(result); marshaller.finish(); }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); ChannelBufferByteOutput output = new ChannelBufferByteOutput(ctx.getChannel().getConfig().getBufferFactory(), 256); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); return output.getBuffer(); } }
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); } }
public static void sendException(HttpServerExchange exchange, int status, Throwable e) throws IOException { exchange.setStatusCode(status); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jbmar-exception;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); final Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); OutputStream outputStream = exchange.getOutputStream(); final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream)); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(e); marshaller.write(0); marshaller.finish(); marshaller.flush(); } }
protected void writeFailure(Exception reason) { try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.APPLICATION_EXCEPTION); os.writeShort(invId); if (version >= 3) os.writeByte(getEnlistmentStatus()); final Marshaller marshaller = marshallerFactory.createMarshaller(configuration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os))); marshaller.writeObject(reason); marshaller.writeByte(0); marshaller.finish(); } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB response write failed", e); } finally { invocations.removeKey(invId); } }
@Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { Marshaller marshaller = provider.getMarshaller(ctx); ChannelBufferByteOutput output = new ChannelBufferByteOutput( ctx.getChannel().getConfig().getBufferFactory(), estimatedLength); output.getBuffer().writeBytes(LENGTH_PLACEHOLDER); marshaller.start(output); marshaller.writeObject(msg); marshaller.finish(); marshaller.close(); ChannelBuffer encoded = output.getBuffer(); encoded.setInt(0, encoded.writerIndex() - 4); return encoded; }
public static void sendException(HttpServerExchange exchange, int status, Throwable e) { try { exchange.setStatusCode(status); exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/x-wf-jbmar-exception;version=1"); final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); final Marshaller marshaller = RIVER_MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); OutputStream outputStream = exchange.getOutputStream(); final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(e); marshaller.write(0); marshaller.finish(); marshaller.flush(); exchange.endExchange(); } catch (Exception ex) { HttpClientMessages.MESSAGES.failedToWriteException(ex); exchange.endExchange(); } } }