Example usage for org.apache.commons.lang3 SerializationUtils deserialize

List of usage examples for org.apache.commons.lang3 SerializationUtils deserialize

Introduction

In this page you can find the example usage for org.apache.commons.lang3 SerializationUtils deserialize.

Prototype

public static <T> T deserialize(final byte[] objectData) 

Source Link

Document

Deserializes a single Object from an array of bytes.

Usage

From source file:org.pascani.dsl.lib.infrastructure.NamespaceProxy.java

public Serializable setVariable(String variable, Serializable value) {
    RpcRequest request = new RpcRequest(RpcOperation.NAMESPACE_SET_VARIABLE, variable, value);
    byte[] response = makeActualCall(request, null);
    return SerializationUtils.deserialize(response);
}

From source file:org.pascani.dsl.lib.infrastructure.rabbitmq.RabbitMQConsumer.java

public void handleDelivery(final String consumerTag, final Envelope envelope, final BasicProperties props,
        final byte[] body) throws IOException {

    Event<?> event = (Event<?>) SerializationUtils.deserialize(body);
    internalDelegateHandling(event);//from   ww  w.j  a va  2  s .c o  m

    // Acknowledge the received message after it has been handled
    this.endPoint.channel().basicAck(envelope.getDeliveryTag(), false);
}

From source file:org.silverpeas.core.util.SerializationUtil.java

/**
 * <p>Deserializes a single {@code Object} from a string.</p>
 * @param <T> the type of the returned serializable object
 * @param objectStringData the serialized object, must not be null
 * @return the deserialized object/*from ww w .  j  a v  a 2s.  com*/
 * @throws IllegalArgumentException if {@code objectData} is {@code null}
 * @throws SerializationException (runtime) if the serialization fails
 */
@SuppressWarnings("unchecked")
public static <T extends Serializable> T deserializeFromString(String objectStringData) {
    if (objectStringData == null) {
        throw new IllegalArgumentException("data must exist");
    }
    return (T) SerializationUtils.deserialize(Base64.getDecoder().decode(objectStringData));
}

From source file:org.sinekartapdfa.utils.EncodingUtils.java

public static <T> T deserialize(Class<T> tClass, byte[] bytes) {
    return (T) SerializationUtils.deserialize(bytes);
}

From source file:org.spoutcraft.mod.protocol.codec.AddPrefabCodec.java

@Override
public AddPrefabMessage decode(Spoutcraft game, ByteBuf buffer) throws IOException {
    if (game.getSide().isServer()) {
        throw new IOException("The server is not allowed to receive prefabs");
    }/*from  www  .  j  av  a2 s .  com*/
    final String addonIdentifier = BufferUtil.readUTF8(buffer);
    final byte[] data = new byte[buffer.readableBytes()];
    buffer.readBytes(data);
    return new AddPrefabMessage(addonIdentifier, (Prefab) SerializationUtils.deserialize(data));
}

From source file:org.spoutcraft.mod.protocol.codec.DownloadLinkCodec.java

@Override
public DownloadLinkMessage decode(Spoutcraft game, ByteBuf buffer) throws IOException {
    if (game.getSide().isServer()) {
        throw new IOException("Server is not allowed to receive links!");
    }/*from   ww w . ja  v  a  2 s. co m*/
    final String addonIdentifier = BufferUtil.readUTF8(buffer);
    byte[] data = new byte[buffer.capacity() - buffer.readerIndex()];
    buffer.readBytes(data);
    final URL url = (URL) SerializationUtils.deserialize(data);
    return new DownloadLinkMessage(addonIdentifier, url);
}

From source file:org.thingsboard.server.service.cluster.discovery.ZkDiscoveryService.java

private boolean currentServerExists() {
    if (nodePath == null) {
        return false;
    }/*  ww w  .  j av  a  2 s. c  o  m*/
    try {
        ServerInstance self = this.serverInstance.getSelf();
        ServerAddress registeredServerAdress = null;
        registeredServerAdress = SerializationUtils.deserialize(client.getData().forPath(nodePath));
        if (self.getServerAddress() != null && self.getServerAddress().equals(registeredServerAdress)) {
            return true;
        }
    } catch (KeeperException.NoNodeException e) {
        log.info("ZK node does not exist: {}", nodePath);
    } catch (Exception e) {
        log.error("Couldn't check if ZK node exists", e);
    }
    return false;
}

From source file:org.thingsboard.server.service.cluster.discovery.ZkDiscoveryService.java

@Override
public List<ServerInstance> getOtherServers() {
    return cache.getCurrentData().stream().filter(cd -> !cd.getPath().equals(nodePath)).map(cd -> {
        try {//from  w  ww.  ja v  a  2 s .co  m
            return new ServerInstance((ServerAddress) SerializationUtils.deserialize(cd.getData()));
        } catch (NoSuchElementException e) {
            log.error("Failed to decode ZK node", e);
            throw new RuntimeException(e);
        }
    }).collect(Collectors.toList());
}

From source file:org.thingsboard.server.service.cluster.discovery.ZkDiscoveryService.java

@Override
public void childEvent(CuratorFramework curatorFramework, PathChildrenCacheEvent pathChildrenCacheEvent)
        throws Exception {
    if (stopped) {
        log.debug("Ignoring {}. Service is stopped.", pathChildrenCacheEvent);
        return;/*  w ww .  java2  s. c o  m*/
    }
    if (client.getState() != CuratorFrameworkState.STARTED) {
        log.debug("Ignoring {}, ZK client is not started, ZK client state [{}]", pathChildrenCacheEvent,
                client.getState());
        return;
    }
    ChildData data = pathChildrenCacheEvent.getData();
    if (data == null) {
        log.debug("Ignoring {} due to empty child data", pathChildrenCacheEvent);
        return;
    } else if (data.getData() == null) {
        log.debug("Ignoring {} due to empty child's data", pathChildrenCacheEvent);
        return;
    } else if (nodePath != null && nodePath.equals(data.getPath())) {
        if (pathChildrenCacheEvent.getType() == CHILD_REMOVED) {
            log.info("ZK node for current instance is somehow deleted.");
            publishCurrentServer();
        }
        log.debug("Ignoring event about current server {}", pathChildrenCacheEvent);
        return;
    }
    ServerInstance instance;
    try {
        ServerAddress serverAddress = SerializationUtils.deserialize(data.getData());
        instance = new ServerInstance(serverAddress);
    } catch (SerializationException e) {
        log.error("Failed to decode server instance for node {}", data.getPath(), e);
        throw e;
    }
    log.info("Processing [{}] event for [{}:{}]", pathChildrenCacheEvent.getType(), instance.getHost(),
            instance.getPort());
    switch (pathChildrenCacheEvent.getType()) {
    case CHILD_ADDED:
        routingService.onServerAdded(instance);
        tsSubService.onClusterUpdate();
        deviceStateService.onClusterUpdate();
        actorService.onServerAdded(instance);
        break;
    case CHILD_UPDATED:
        routingService.onServerUpdated(instance);
        actorService.onServerUpdated(instance);
        break;
    case CHILD_REMOVED:
        routingService.onServerRemoved(instance);
        tsSubService.onClusterUpdate();
        deviceStateService.onClusterUpdate();
        actorService.onServerRemoved(instance);
        break;
    default:
        break;
    }
}

From source file:org.wso2.carbon.identity.application.authentication.framework.handler.sequence.impl.GraphBasedSequenceHandlerCustomFunctionsTest.java

@Test
public void testHandleDynamicJavascriptSerialization() throws Exception {

    JsFunctionRegistry jsFunctionRegistrar = new JsFunctionRegistryImpl();
    FrameworkServiceDataHolder.getInstance().setJsFunctionRegistry(jsFunctionRegistrar);
    jsFunctionRegistrar.register(JsFunctionRegistry.Subsystem.SEQUENCE_HANDLER, "fn1",
            (Function<JsAuthenticationContext, String>) GraphBasedSequenceHandlerCustomFunctionsTest::customFunction1);

    ServiceProvider sp1 = getTestServiceProvider("js-sp-dynamic-1.xml");

    AuthenticationContext context = getAuthenticationContext(sp1);

    SequenceConfig sequenceConfig = configurationLoader.getSequenceConfig(context,
            Collections.<String, String[]>emptyMap(), sp1);
    context.setSequenceConfig(sequenceConfig);

    byte[] serialized = SerializationUtils.serialize(context);

    AuthenticationContext deseralizedContext = (AuthenticationContext) SerializationUtils
            .deserialize(serialized);/*from  ww  w  . j av a 2 s .com*/
    assertNotNull(deseralizedContext);

    HttpServletRequest req = mock(HttpServletRequest.class);
    addMockAttributes(req);

    HttpServletResponse resp = mock(HttpServletResponse.class);

    UserCoreUtil.setDomainInThreadLocal("test_domain");

    graphBasedSequenceHandler.handle(req, resp, deseralizedContext);

    List<AuthHistory> authHistories = deseralizedContext.getAuthenticationStepHistory();
    assertNotNull(authHistories);
    assertEquals(3, authHistories.size());
    assertEquals(authHistories.get(0).getAuthenticatorName(), "BasicMockAuthenticator");
    assertEquals(authHistories.get(1).getAuthenticatorName(), "HwkMockAuthenticator");
    assertEquals(authHistories.get(2).getAuthenticatorName(), "FptMockAuthenticator");
}