public void close() throws IOException, IllegalStateException { unmarshaller.finish(); unmarshaller = null; }
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; }
public Object deSerialize(final String data) throws SQLException { if (data == null) { return null; } InputStream in = new ByteArrayInputStream(Base64.getDecoder().decode(data)); try { final Unmarshaller unmarshaller = factory.createUnmarshaller(configuration); unmarshaller.start(new InputStreamByteInput(in)); Object ret = unmarshaller.readObject(); unmarshaller.finish(); return ret; } catch (IOException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } finally { safeClose(in); } }
@Override public Map<String, PersistentSession> loadSessionAttributes(String deploymentName, final ClassLoader classLoader) { try { Unmarshaller unmarshaller = createUnmarshaller(); try { long time = System.currentTimeMillis(); Map<String, SessionEntry> data = loadSerializedSessions(deploymentName); if (data != null) { Map<String, PersistentSession> ret = new HashMap<String, PersistentSession>(); for (Map.Entry<String, SessionEntry> sessionEntry : data.entrySet()) { if (sessionEntry.getValue().expiry.getTime() > time) { Map<String, Object> session = new HashMap<String, Object>(); for (Map.Entry<String, byte[]> sessionAttribute : sessionEntry.getValue().data.entrySet()) { unmarshaller.start(new ByteBufferInput(ByteBuffer.wrap(sessionAttribute.getValue()))); session.put(sessionAttribute.getKey(), unmarshaller.readObject()); unmarshaller.finish(); } ret.put(sessionEntry.getKey(), new PersistentSession(sessionEntry.getValue().expiry, session)); } } return ret; } } finally { unmarshaller.close(); } } catch (Exception e) { UndertowServletLogger.ROOT_LOGGER.failedtoLoadPersistentSessions(e); } return null; }
@Override protected Map<String, SessionEntry> loadSerializedSessions(String deploymentName) throws IOException { File file = new File(baseDir, deploymentName); if (!file.exists()) { return null; } FileInputStream in = new FileInputStream(file); try { Unmarshaller unMarshaller = createUnmarshaller(); try { try { unMarshaller.start(new InputStreamByteInput(in)); return (Map<String, SessionEntry>) unMarshaller.readObject(); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } finally { unMarshaller.finish(); } } finally { unMarshaller.close(); } } finally { IoUtils.safeClose(in); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); out.add(obj); } catch (LimitingByteInput.TooBigObjectException ignored) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(frame); try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); out.add(obj); } catch (LimitingByteInput.TooBigObjectException ignored) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(frame); try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); out.add(obj); } catch (LimitingByteInput.TooBigObjectException ignored) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
@Override protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception { ByteBuf frame = (ByteBuf) super.decode(ctx, in); if (frame == null) { return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(frame); try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
@Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer) throws Exception { ChannelBuffer frame = (ChannelBuffer) super.decode(ctx, channel, buffer); if (frame == null) { return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(frame); try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not // enough bytes are readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
/** * {@inheritDoc} * @see org.wildfly.clustering.marshalling.spi.MarshalledValue#get(java.lang.Object) */ @SuppressWarnings("unchecked") @Override public synchronized T get(MarshallingContext context) throws IOException, ClassNotFoundException { if (this.object == null) { this.context = context; if (this.bytes != null) { ByteArrayInputStream input = new ByteArrayInputStream(this.bytes); ClassLoader loader = setThreadContextClassLoader(this.context.getClassLoader()); try (SimpleDataInput data = new SimpleDataInput(Marshalling.createByteInput(input))) { int version = IndexSerializer.VARIABLE.readInt(data); try (Unmarshaller unmarshaller = context.createUnmarshaller(version)) { unmarshaller.start(data); this.object = (T) unmarshaller.readObject(); unmarshaller.finish(); this.bytes = null; // Free up memory } } finally { setThreadContextClassLoader(loader); } } } return this.object; }
@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; }
unmarshaller.finish(); } catch (IOException | ClassNotFoundException ex) { throw new EJBException("Failed to read response", ex);
static XAException readAppException(final EJBClientChannel channel, final BlockingInvocation.Response response) throws XAException { Exception e; try (final Unmarshaller unmarshaller = channel.createUnmarshaller()) { try (MessageInputStream inputStream = response.getInputStream()) { unmarshaller.start(Marshalling.createByteInput(inputStream)); e = unmarshaller.readObject(Exception.class); unmarshaller.finish(); // The version is probably < 3 else we would not be here // drain off attachments so the server doesn't complain while (inputStream.read() != -1) { inputStream.skip(Long.MAX_VALUE); } } } catch (IOException | ClassNotFoundException e1) { throw new XAException(XAException.XAER_RMERR); } if (e == null) { throw new XAException(XAException.XAER_RMFAIL); } try { throw e; } catch (RuntimeException | XAException e1) { throw e1; } catch (Exception e1) { final XAException xae = new XAException(XAException.XAER_RMERR); xae.initCause(e1); return xae; } }
@Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer, VoidEnum state) throws Exception { if (discardingTooLongFrame) { buffer.skipBytes(actualReadableBytes()); checkpoint(); return null; } Unmarshaller unmarshaller = provider.getUnmarshaller(ctx); ByteInput input = new ChannelBufferByteInput(buffer); if (maxObjectSize != Integer.MAX_VALUE) { input = new LimitingByteInput(input, maxObjectSize); } try { unmarshaller.start(input); Object obj = unmarshaller.readObject(); unmarshaller.finish(); return obj; } catch (LimitingByteInput.TooBigObjectException e) { discardingTooLongFrame = true; throw new TooLongFrameException(); } finally { // Call close in a finally block as the ReplayingDecoder will throw an Error if not enough bytes are // readable. This helps to be sure that we do not leak resource unmarshaller.close(); } }
static SystemException readAppException(final EJBClientChannel channel, final BlockingInvocation.Response response) throws SystemException { Exception e; try (final Unmarshaller unmarshaller = channel.createUnmarshaller()) { try (MessageInputStream inputStream = response.getInputStream()) { unmarshaller.start(Marshalling.createByteInput(inputStream)); e = unmarshaller.readObject(Exception.class); unmarshaller.finish(); // The version is probably < 3 else we would not be here // drain off attachments so the server doesn't complain while (inputStream.read() != -1) { inputStream.skip(Long.MAX_VALUE); } } } catch (IOException | ClassNotFoundException e1) { throw new SystemException(); } if (e == null) { throw new SystemException(); } try { throw e; } catch (RuntimeException | SystemException e1) { throw e1; } catch (Exception e1) { final SystemException e2 = new SystemException(); e2.initCause(e1); return e2; } }
xids[i ++] = unmarshaller.readObject(XidTransactionID.class).getXid(); unmarshaller.finish(); return xids;
@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); } }