StepObjectOutput(final Queue<Step> steps) throws IOException { super(SerializingCloner.this.bufferSize); this.steps = steps; super.start(Marshalling.createByteOutput(byteArrayOutputStream)); }
/** * Construct a new instance. */ public BytePipe() { final PipedOutputStream output = new PipedOutputStream(); final PipedInputStream input; try { input = new PipedInputStream(output); } catch (IOException e) { throw new IllegalStateException(e); } this.input = Marshalling.createByteInput(input); this.output = Marshalling.createByteOutput(output); }
/** * 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; }
final ByteOutput byteOutput = Marshalling.createByteOutput(outputStream);
@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 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(); } } }
if (object != null) { Marshaller marshaller = targetContext.createMarshaller(createMarshallingConfig(providerUri)); marshaller.start(Marshalling.createByteOutput(output)); marshaller.writeObject(object); marshaller.finish();
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); } }
@Override public void writeInvocationResult(Object result) { if(identifier != null) { cancellationFlags.remove(identifier); } try { exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, EjbHeaders.EJB_RESPONSE_VERSION_ONE.toString()); // if (output.getSessionAffinity() != null) { // exchange.getResponseCookies().put("JSESSIONID", new CookieImpl("JSESSIONID", output.getSessionAffinity()).setPath(WILDFLY_SERVICES)); // } final Marshaller marshaller = HttpServerHelper.RIVER_MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); OutputStream outputStream = exchange.getOutputStream(); final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream)); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(result); // TODO: Do we really need to send this back? PackedInteger.writePackedInteger(marshaller, contextData.size()); for(Map.Entry<String, Object> entry : contextData.entrySet()) { marshaller.writeObject(entry.getKey()); marshaller.writeObject(entry.getValue()); } marshaller.finish(); marshaller.flush(); exchange.endExchange(); } catch (Exception e) { HttpServerHelper.sendException(exchange, 500, e); } } }
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 = MARSHALLER_FACTORY.createMarshaller(marshallingConfiguration); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); final ByteOutput byteOutput = new NoFlushByteOutput(Marshalling.createByteOutput(outputStream)); // start the marshaller marshaller.start(byteOutput); marshaller.writeObject(e); marshaller.write(0); marshaller.finish(); marshaller.flush(); exchange.getResponseSender().send(ByteBuffer.wrap(outputStream.toByteArray())); } catch (IOException e1) { HttpRemoteTransactionMessages.MESSAGES.debugf(e, "Failed to write exception"); } } }
targetContext.sendRequest(cr, sslContext, authenticationConfiguration, output -> { Marshaller marshaller = targetContext.createMarshaller(HttpRemoteTransactionPeer.createMarshallingConf()); marshaller.start(Marshalling.createByteOutput(output)); marshaller.writeInt(id.getFormatId()); final byte[] gtid = id.getGlobalTransactionId();
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(); }
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); } } }
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); } }
final ByteArrayOutputStream out = new ByteArrayOutputStream(); Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(createMarshallingConf()); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(out))); marshaller.writeInt(recoveryList.length); for (int i = 0; i < recoveryList.length; ++i) {
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(); } } }
public void writeWrongViewType() { final String message = Logs.REMOTING.remoteMessageBadViewType(getEJBIdentifier()); try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { if (version >= 3) { os.writeByte(Protocol.BAD_VIEW_TYPE); os.writeShort(invId); os.writeUTF(message); } else { os.writeByte(Protocol.APPLICATION_EXCEPTION); os.writeShort(invId); final Marshaller marshaller = marshallerFactory.createMarshaller(configuration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os))); marshaller.writeObject(Logs.REMOTING.invalidViewTypeForInvocation(message)); 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); } }
void handleTxnRecoverRequest(final int invId, final MessageInputStream message) throws IOException { final String parentName = message.readUTF(); final int flags = message.readInt(); final Xid[] xids; try { xids = transactionServer.getTransactionService().getTransactionContext().getRecoveryInterface().recover(flags, parentName); } catch (XAException e) { writeFailedResponse(invId, e); return; } try (MessageOutputStream os = messageTracker.openMessageUninterruptibly()) { os.writeByte(Protocol.TXN_RECOVERY_RESPONSE); os.writeShort(invId); PackedInteger.writePackedInteger(os, xids.length); final Marshaller marshaller = marshallerFactory.createMarshaller(configuration); marshaller.start(new NoFlushByteOutput(Marshalling.createByteOutput(os))); for (Xid xid : xids) { marshaller.writeObject(new XidTransactionID(xid)); } marshaller.finish(); } catch (IOException e) { // nothing to do at this point; the client doesn't want the response Logs.REMOTING.trace("EJB transaction response write failed", e); } }