private Object unmarshalIdentifier() throws IOException, ClassNotFoundException { final Object id; try { final byte[] idData = poaCurrent.get_object_id(); final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration); unmarshaller.start(new InputStreamByteInput(new ByteArrayInputStream(idData))); id = unmarshaller.readObject(); unmarshaller.finish(); } catch (NoContext noContext) { throw new RuntimeException(noContext); } return id; }
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()); }
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(); } }
final MarshallerFactory factory = Marshalling.getMarshallerFactory("river", DomainServerMain.class.getClassLoader()); final Unmarshaller unmarshaller; final ByteInput byteInput; try { Module.registerURLStreamHandlerFactoryModule(Module.getBootModuleLoader().loadModule(ModuleIdentifier.create("org.jboss.vfs"))); final MarshallingConfiguration configuration = new MarshallingConfiguration(); configuration.setVersion(2); configuration.setClassResolver(new SimpleClassResolver(DomainServerMain.class.getClassLoader())); unmarshaller = factory.createUnmarshaller(configuration); byteInput = Marshalling.createByteInput(initialInput); unmarshaller.start(byteInput); final ServerTask task = unmarshaller.readObject(ServerTask.class); unmarshaller.finish(); containerFuture = task.run(Arrays.<ServiceActivator>asList(new ServiceActivator() { @Override
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 final Object doOperation(HttpServerExchange exchange, String name) throws NamingException { ContentType contentType = ContentType.parse(exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE)); if (contentType == null || !contentType.getType().equals("application/x-wf-jndi-jbmar-value") || contentType.getVersion() != 1) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); exchange.endExchange(); return null; } final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); try (InputStream inputStream = exchange.getInputStream()) { Unmarshaller unmarshaller = MARSHALLER_FACTORY.createUnmarshaller(marshallingConfiguration); unmarshaller.start(new InputStreamByteInput(inputStream)); Object object = unmarshaller.readObject(); unmarshaller.finish(); doOperation(name, object); } catch (Exception e) { NamingException nm = new NamingException(e.getMessage()); nm.initCause(e); throw nm; } return null; }
private Object deserialize(final String info) throws IOException, ClassNotFoundException { byte[] data = Base64.getDecoder().decode(info.trim()); Unmarshaller unmarshaller = factory.createUnmarshaller(configuration); unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(data))); try { return unmarshaller.readObject(); } finally { unmarshaller.close(); } }
void handleInvocationRequest(final int invId, final InputStream input) throws IOException, ClassNotFoundException { final MarshallingConfiguration configuration = EJBServerChannel.this.configuration.clone(); final ServerClassResolver classResolver = new ServerClassResolver(); configuration.setClassResolver(classResolver); final Unmarshaller unmarshaller; final SecurityIdentity identity; if (version >= 3) { unmarshaller = marshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(input)); identifier = unmarshaller.readObject(EJBIdentifier.class); methodLocator = unmarshaller.readObject(EJBMethodLocator.class); int identityId = unmarshaller.readInt(); identity = identityId == 0 ? connection.getLocalIdentity() : connection.getLocalIdentity(identityId); unmarshaller = marshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(data)); String appName = unmarshaller.readObject(String.class); String moduleName = unmarshaller.readObject(String.class);
@Override protected void setState(InputStream is) throws IOException, ClassNotFoundException { MarshallingConfiguration config = new MarshallingConfiguration(); config.setClassResolver(new SimpleClassResolver(getStateTransferClassLoader())); Unmarshaller unmarshaller = marshallerFactory.createUnmarshaller(config); unmarshaller.start(Marshalling.createByteInput(is)); this.state = unmarshaller.readObject(Serializable.class); unmarshaller.close(); }
/** * Creates and returns a {@link Unmarshaller} * * * @param marshallerFactory The marshaller factory * @return * @throws IOException */ private Unmarshaller getUnMarshaller(final MarshallerFactory marshallerFactory, final ClassResolver classResolver) throws IOException { final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setVersion(2); marshallingConfiguration.setClassResolver(classResolver); return marshallerFactory.createUnmarshaller(marshallingConfiguration); }
final ReceivedTransaction txConfig; try { final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setObjectTable(HttpProtocolV1ObjectTable.INSTANCE); marshallingConfiguration.setVersion(2); Unmarshaller unmarshaller = HttpServerHelper.RIVER_MARSHALLER_FACTORY.createUnmarshaller(marshallingConfiguration); unmarshaller.start(new InputStreamByteInput(inputStream)); txConfig = readTransaction(unmarshaller); unmarshaller.finish();
@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); } } }
@Override public final void handleRequest(HttpServerExchange exchange) throws Exception { ContentType contentType = ContentType.parse(exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE)); if (contentType == null || contentType.getVersion() != 1 || !contentType.getType().equals(TransactionConstants.XID)) { exchange.setStatusCode(StatusCodes.BAD_REQUEST); HttpRemoteTransactionMessages.MESSAGES.debugf("Exchange %s has incorrect or missing content type", exchange); return; } try { Unmarshaller unmarshaller = MARSHALLER_FACTORY.createUnmarshaller(createMarshallingConf()); unmarshaller.start(new InputStreamByteInput(exchange.getInputStream())); int formatId = unmarshaller.readInt(); int len = unmarshaller.readInt(); byte[] globalId = new byte[len]; unmarshaller.readFully(globalId); len = unmarshaller.readInt(); byte[] branchId = new byte[len]; unmarshaller.readFully(branchId); SimpleXid simpleXid = new SimpleXid(formatId, globalId, branchId); unmarshaller.finish(); ImportResult<LocalTransaction> transaction = transactionContext.findOrImportTransaction(simpleXid, 0); transaction.getTransaction().performFunction((ExceptionBiFunction<ImportResult<LocalTransaction>, HttpServerExchange, Void, Exception>) (o, exchange2) -> { handleImpl(exchange2, o); return null; }, transaction, exchange); } catch (Exception e) { sendException(exchange, StatusCodes.INTERNAL_SERVER_ERROR, e); } }
public static Unmarshaller createUnmarshaller(MessageInputStream is, MarshallingConfiguration configuration) throws IOException { final Unmarshaller unmarshaller = riverMarshallerFactory.createUnmarshaller(configuration); unmarshaller.start(Marshalling.createByteInput(is)); return unmarshaller; }
/** * Creates and returns a {@link org.jboss.marshalling.Marshaller} * * @param marshallerFactory The marshaller factory * @return * @throws IOException */ private org.jboss.marshalling.Marshaller getMarshaller(final org.jboss.marshalling.MarshallerFactory marshallerFactory) throws IOException { final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); // TODO - Do we need an Object and Class table? marshallingConfiguration.setVersion(2); // TODO - Will need classloading server side to be in context of bean being called. return marshallerFactory.createMarshaller(marshallingConfiguration); }
@BeforeClass public void setUp() throws Exception { factory = (MarshallerFactory) Thread.currentThread().getContextClassLoader().loadClass("org.jboss.marshalling.river.RiverMarshallerFactory").newInstance(); MarshallingConfiguration configuration = new MarshallingConfiguration(); configuration.setClassResolver(new ContextClassResolver()); marshaller = factory.createMarshaller(configuration); unmarshaller = factory.createUnmarshaller(configuration); }
/** * Creates and returns a {@link org.jboss.marshalling.Marshaller} * * @param marshallerFactory The marshaller factory * @return * @throws IOException */ private org.jboss.marshalling.Marshaller getMarshaller(final org.jboss.marshalling.MarshallerFactory marshallerFactory) throws IOException { final MarshallingConfiguration marshallingConfiguration = new MarshallingConfiguration(); marshallingConfiguration.setClassTable(ProtocolV1ClassTable.INSTANCE); marshallingConfiguration.setObjectTable(ProtocolV1ObjectTable.INSTANCE); marshallingConfiguration.setVersion(2); marshallingConfiguration.setSerializedCreator(new SunReflectiveCreator()); return marshallerFactory.createMarshaller(marshallingConfiguration); }
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 public Unmarshaller getUnmarshaller(ChannelHandlerContext ctx) throws Exception { return factory.createUnmarshaller(config); }
@Override public Marshaller getMarshaller(ChannelHandlerContext ctx) throws Exception { return factory.createMarshaller(config); }