@Test
  public void testFragmentedUnmarshalling() throws IOException {
    MarshallerFactory marshallerFactory = createMarshallerFactory();
    MarshallingConfiguration configuration = createMarshallingConfig();

    DecoderEmbedder<Object> decoder =
        new DecoderEmbedder<Object>(createDecoder(marshallerFactory, configuration, 0));

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(Marshalling.createByteOutput(bout));
    marshaller.writeObject(testObject);
    marshaller.finish();
    marshaller.close();

    byte[] testBytes = bout.toByteArray();

    ChannelBuffer buffer = ChannelBuffers.wrappedBuffer(testBytes);
    ChannelBuffer slice = buffer.readSlice(2);

    decoder.offer(slice);
    decoder.offer(buffer);
    assertTrue(decoder.finish());

    String unmarshalled = (String) decoder.poll();

    Assert.assertEquals(testObject, unmarshalled);

    Assert.assertNull(decoder.poll());
  }
 @Override
 public void store(V obj) {
   File file = getFile(obj.getId());
   log.tracef("Storing state to %s", file);
   try {
     FileOutputStream outputStream = null;
     try {
       outputStream = FOSAction.open(file);
       SimpleDataOutput output = new SimpleDataOutput(Marshalling.createByteOutput(outputStream));
       int version = this.passivationManager.getCurrentMarshallingVersion();
       output.writeInt(version);
       MarshallingConfiguration config =
           this.passivationManager.getMarshallingConfiguration(version);
       Marshaller marshaller = this.marshallerFactory.createMarshaller(config);
       marshaller.start(output);
       try {
         marshaller.writeObject(obj);
         marshaller.finish();
         counter.incrementAndGet();
       } finally {
         marshaller.close();
       }
     } finally {
       safeClose(outputStream);
     }
   } catch (IOException e) {
     throw EjbMessages.MESSAGES.passivationFailed(e, obj.getId());
   }
 }
Esempio n. 3
0
 @Override
 public void writeObject(Marshaller output, Object object) throws IOException {
   output.write(id);
   // Write as an unsigned, variable length, integer to safe space
   UnsignedNumeric.writeUnsignedInt(output, foreignId);
   externalizer.writeObject(output, object);
 }
  private void writeFile(TimerImpl timer) {
    final File file = fileName(timer.getTimedObjectId(), timer.getId());

    // if the timer is expired or cancelled delete the file
    if (timer.getState() == TimerState.CANCELED || timer.getState() == TimerState.EXPIRED) {
      if (file.exists()) {
        file.delete();
      }
      return;
    }

    final TimerEntity entity;
    if (timer instanceof CalendarTimer) {
      entity = new CalendarTimerEntity((CalendarTimer) timer);
    } else {
      entity = new TimerEntity(timer);
    }

    FileOutputStream fileOutputStream = null;
    try {
      fileOutputStream = new FileOutputStream(file, false);
      final Marshaller marshaller = factory.createMarshaller(configuration);
      marshaller.start(new OutputStreamByteOutput(fileOutputStream));
      marshaller.writeObject(entity);
      marshaller.finish();
      fileOutputStream.flush();
      fileOutputStream.getFD().sync();
    } catch (FileNotFoundException e) {
      throw new RuntimeException(e);
    } catch (IOException e) {
      throw new RuntimeException(e);
    } finally {
      if (fileOutputStream != null) {
        try {
          fileOutputStream.close();
        } catch (IOException e) {
          ROOT_LOGGER.failToCloseFile(e);
        }
      }
    }
  }
Esempio n. 5
0
 @Override
 public boolean execute(ManagedServer server) throws Exception {
   assert Thread.holdsLock(ManagedServer.this); // Call under lock
   // Get the standalone boot updates
   final List<ModelNode> bootUpdates =
       Collections.emptyList(); // bootConfiguration.getBootUpdates();
   final Map<String, String> launchProperties =
       parseLaunchProperties(bootConfiguration.getServerLaunchCommand());
   final boolean useSubsystemEndpoint = bootConfiguration.isManagementSubsystemEndpoint();
   final ModelNode endpointConfig = bootConfiguration.getSubsystemEndpointConfiguration();
   // Send std.in
   final ServiceActivator hostControllerCommActivator =
       DomainServerCommunicationServices.create(
           endpointConfig,
           managementURI,
           serverName,
           serverProcessName,
           authKey,
           useSubsystemEndpoint);
   final ServerStartTask startTask =
       new ServerStartTask(
           hostControllerName,
           serverName,
           0,
           operationID,
           Collections.<ServiceActivator>singletonList(hostControllerCommActivator),
           bootUpdates,
           launchProperties);
   final Marshaller marshaller = MARSHALLER_FACTORY.createMarshaller(CONFIG);
   final OutputStream os = processControllerClient.sendStdin(serverProcessName);
   marshaller.start(Marshalling.createByteOutput(os));
   marshaller.writeObject(startTask);
   marshaller.finish();
   marshaller.close();
   os.close();
   return true;
 }
  private void writeSessionId(
      final ChannelAssociation channelAssociation,
      final short invocationId,
      final SessionID sessionID,
      final Affinity hardAffinity)
      throws IOException {
    final byte[] sessionIdBytes = sessionID.getEncodedForm();
    final DataOutputStream dataOutputStream;
    final MessageOutputStream messageOutputStream;
    try {
      messageOutputStream = channelAssociation.acquireChannelMessageOutputStream();
    } catch (Exception e) {
      throw EjbMessages.MESSAGES.failedToOpenMessageOutputStream(e);
    }
    dataOutputStream = new DataOutputStream(messageOutputStream);
    try {
      // write out header
      dataOutputStream.writeByte(HEADER_SESSION_OPEN_RESPONSE);
      // write out invocation id
      dataOutputStream.writeShort(invocationId);
      // session id byte length
      PackedInteger.writePackedInteger(dataOutputStream, sessionIdBytes.length);
      // write out the session id bytes
      dataOutputStream.write(sessionIdBytes);
      // now marshal the hard affinity associated with this session
      final Marshaller marshaller =
          this.prepareForMarshalling(this.marshallerFactory, dataOutputStream);
      marshaller.writeObject(hardAffinity);

      // finish marshalling
      marshaller.finish();

    } finally {
      channelAssociation.releaseChannelMessageOutputStream(messageOutputStream);
      dataOutputStream.close();
    }
  }
  @Test
  public void testTooBigObject() throws IOException {
    MarshallerFactory marshallerFactory = createMarshallerFactory();
    MarshallingConfiguration configuration = createMarshallingConfig();

    MarshallingDecoder mDecoder = createDecoder(marshallerFactory, configuration, 1);
    DecoderEmbedder<Object> decoder = new DecoderEmbedder<Object>(mDecoder);

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    Marshaller marshaller = marshallerFactory.createMarshaller(configuration);
    marshaller.start(Marshalling.createByteOutput(bout));
    marshaller.writeObject(testObject);
    marshaller.finish();
    marshaller.close();

    byte[] testBytes = bout.toByteArray();

    try {
      decoder.offer(ChannelBuffers.wrappedBuffer(testBytes));
      fail();
    } catch (CodecEmbedderException e) {
      assertEquals(TooLongFrameException.class, e.getCause().getClass());
    }
  }
 /** {@inheritDoc} */
 public void write(final Marshaller marshaller) throws IOException {
   marshaller.writeByte(value);
 }
Esempio n. 9
0
 @Override
 public void writeObject(Marshaller output, Object object) throws IOException {
   output.write(id);
   externalizer.writeObject(output, object);
 }
 public ObjectOutput startObjectOutput(OutputStream os, boolean isReentrant) throws IOException {
   org.jboss.marshalling.Marshaller marshaller = getMarshaller(isReentrant);
   marshaller.start(Marshalling.createByteOutput(os));
   return marshaller;
 }
Esempio n. 11
0
 @Override
 public void writeClass(final Marshaller marshaller, final Class<?> clazz) throws IOException {
   marshaller.write(bytes);
 }