Search in sources :

Example 1 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class AbstractOp method sendMessage.

/**
   * New implementations of AbstractOp should override this method if the implementation should be
   * excluded from client authentication. e.g. PingOp#sendMessage(Connection cnx)
   * 
   * @see AbstractOp#needsUserId()
   * @see AbstractOp#processSecureBytes(Connection, Message)
   * @see ServerConnection#updateAndGetSecurityPart()
   */
protected void sendMessage(Connection cnx) throws Exception {
    if (cnx.getServer().getRequiresCredentials()) {
        // Security is enabled on client as well as on server
        getMessage().setMessageHasSecurePartFlag();
        long userId = -1;
        if (UserAttributes.userAttributes.get() == null) {
            // single user mode
            userId = cnx.getServer().getUserId();
        } else {
            // multi user mode
            Object id = UserAttributes.userAttributes.get().getServerToId().get(cnx.getServer());
            if (id == null) {
                // the retryCount is exhausted. Fix for Bug 41501
                throw new ServerConnectivityException("Connection error while authenticating user");
            }
            userId = (Long) id;
        }
        HeapDataOutputStream hdos = new HeapDataOutputStream(Version.CURRENT);
        try {
            hdos.writeLong(cnx.getConnectionID());
            hdos.writeLong(userId);
            getMessage().setSecurePart(((ConnectionImpl) cnx).getHandShake().encryptBytes(hdos.toByteArray()));
        } finally {
            hdos.close();
        }
    }
    getMessage().send(false);
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream)

Example 2 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class EventID method initializeAndGetDSEventIdentity.

private static byte[] initializeAndGetDSEventIdentity(DistributedSystem sys) {
    if (sys == null) {
        // DistributedSystem is required now before handshaking -Kirk
        throw new IllegalStateException(LocalizedStrings.ClientProxyMembershipID_ATTEMPTING_TO_HANDSHAKE_WITH_CACHESERVER_BEFORE_CREATING_DISTRIBUTEDSYSTEM_AND_CACHE.toLocalizedString());
    }
    if (EventID.system != sys) {
        // DS already exists... make sure it's for current DS connection
        EventID.systemMemberId = sys.getDistributedMember();
        try {
            HeapDataOutputStream hdos = new HeapDataOutputStream(256, Version.CURRENT);
            ((InternalDistributedMember) EventID.systemMemberId).writeEssentialData(hdos);
            client_side_event_identity = hdos.toByteArray();
        } catch (IOException ioe) {
            throw new InternalGemFireException(LocalizedStrings.ClientProxyMembershipID_UNABLE_TO_SERIALIZE_IDENTITY.toLocalizedString(), ioe);
        }
        EventID.system = sys;
    }
    return EventID.client_side_event_identity;
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalGemFireException(org.apache.geode.InternalGemFireException) HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) IOException(java.io.IOException)

Example 3 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class GraphReader method readGraphs.

public GraphSet readGraphs(Filter filter, boolean areGemfireLogs) throws IOException {
    GraphSet graphs = new GraphSet();
    if (areGemfireLogs) {
        // TODO - probably don't need to go all the way
        // to a binary format here, but this is quick and easy.
        HeapDataOutputStream out = new HeapDataOutputStream(Version.CURRENT);
        GemfireLogConverter.convertFiles(out, files);
        InputStreamReader reader = new InputStreamReader(out.getInputStream());
        reader.addToGraphs(graphs, filter);
    } else {
        for (File file : files) {
            FileInputStream fis = new FileInputStream(file);
            InputStreamReader reader = new InputStreamReader(fis);
            reader.addToGraphs(graphs, filter);
        }
    }
    graphs.readingDone();
    return graphs;
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) File(java.io.File) GraphSet(org.apache.geode.internal.sequencelog.model.GraphSet) FileInputStream(java.io.FileInputStream)

Example 4 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class PdxToJSON method getJSON.

public String getJSON() {
    JsonFactory jf = new JsonFactory();
    // OutputStream os = new ByteArrayOutputStream();
    HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
    try {
        JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
        enableDisableJSONGeneratorFeature(jg);
        getJSONString(jg, m_pdxInstance);
        jg.close();
        return new String(hdos.toByteArray());
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    } finally {
        hdos.close();
    }
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Example 5 with HeapDataOutputStream

use of org.apache.geode.internal.HeapDataOutputStream in project geode by apache.

the class PdxToJSON method getJSONByteArray.

public byte[] getJSONByteArray() {
    JsonFactory jf = new JsonFactory();
    HeapDataOutputStream hdos = new HeapDataOutputStream(org.apache.geode.internal.Version.CURRENT);
    try {
        JsonGenerator jg = jf.createJsonGenerator(hdos, JsonEncoding.UTF8);
        enableDisableJSONGeneratorFeature(jg);
        getJSONString(jg, m_pdxInstance);
        jg.close();
        return hdos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    } finally {
        hdos.close();
    }
}
Also used : HeapDataOutputStream(org.apache.geode.internal.HeapDataOutputStream) JsonFactory(com.fasterxml.jackson.core.JsonFactory) JsonGenerator(com.fasterxml.jackson.core.JsonGenerator) IOException(java.io.IOException)

Aggregations

HeapDataOutputStream (org.apache.geode.internal.HeapDataOutputStream)134 Test (org.junit.Test)55 IOException (java.io.IOException)40 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)36 SerializationTest (org.apache.geode.test.junit.categories.SerializationTest)33 DataInputStream (java.io.DataInputStream)29 ByteArrayInputStream (java.io.ByteArrayInputStream)23 UnitTest (org.apache.geode.test.junit.categories.UnitTest)15 DiskAccessException (org.apache.geode.cache.DiskAccessException)12 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)11 PdxSerializerObject (org.apache.geode.internal.PdxSerializerObject)10 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)8 Version (org.apache.geode.internal.Version)8 DataInput (java.io.DataInput)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7 OutputStream (java.io.OutputStream)6 Properties (java.util.Properties)6 ByteBuffer (java.nio.ByteBuffer)5 HashMap (java.util.HashMap)5 InternalGemFireException (org.apache.geode.InternalGemFireException)5