Search in sources :

Example 36 with NotSerializableException

use of java.io.NotSerializableException in project geode by apache.

the class InternalDataSerializer method basicWriteObject.

public static void basicWriteObject(Object o, DataOutput out, boolean ensurePdxCompatibility) throws IOException {
    checkOut(out);
    final boolean isDebugEnabled_SERIALIZER = logger.isTraceEnabled(LogMarker.SERIALIZER);
    if (isDebugEnabled_SERIALIZER) {
        logger.trace(LogMarker.SERIALIZER, "basicWriteObject: {}", o);
    }
    // Handle special objects first
    if (o == null) {
        out.writeByte(NULL);
    } else if (o instanceof DataSerializableFixedID) {
        checkPdxCompatible(o, ensurePdxCompatibility);
        DataSerializableFixedID dsfid = (DataSerializableFixedID) o;
        writeDSFID(dsfid, out);
    } else if (autoSerialized(o, out)) {
    // all done
    } else if (o instanceof DataSerializable.Replaceable) {
        // do this first to fix bug 31609
        // do this before DataSerializable
        Object replacement = ((DataSerializable.Replaceable) o).replace();
        basicWriteObject(replacement, out, ensurePdxCompatibility);
    } else if (o instanceof PdxSerializable) {
        writePdx(out, GemFireCacheImpl.getForPdx("PDX registry is unavailable because the Cache has been closed."), o, null);
    } else if (o instanceof DataSerializable) {
        if (isDebugEnabled_SERIALIZER) {
            logger.trace(LogMarker.SERIALIZER, "Writing DataSerializable: {}", o);
        }
        checkPdxCompatible(o, ensurePdxCompatibility);
        Class c = o.getClass();
        // Is "c" a user class registered with an Instantiator?
        int classId = InternalInstantiator.getClassId(c);
        if (classId != 0) {
            writeUserDataSerializableHeader(classId, out);
        } else {
            out.writeByte(DATA_SERIALIZABLE);
            DataSerializer.writeClass(c, out);
        }
        DataSerializable ds = (DataSerializable) o;
        invokeToData(ds, out);
    } else if (o instanceof Sendable) {
        if (!(o instanceof PdxInstance) || o instanceof PdxInstanceEnum) {
            checkPdxCompatible(o, ensurePdxCompatibility);
        }
        ((Sendable) o).sendTo(out);
    } else if (writeWellKnownObject(o, out, ensurePdxCompatibility)) {
    // Nothing more to do...
    } else {
        checkPdxCompatible(o, ensurePdxCompatibility);
        if (logger.isTraceEnabled(LogMarker.DUMP_SERIALIZED)) {
            logger.trace(LogMarker.DUMP_SERIALIZED, "DataSerializer Serializing an instance of {}", o.getClass().getName());
        }
        /*
       * If the (internally known) ThreadLocal named "DataSerializer.DISALLOW_JAVA_SERIALIZATION" is
       * set, then an exception will be thrown if we try to do standard Java Serialization. This is
       * used to catch Java serialization early for the case where the data is being sent to a
       * non-Java client
       */
        if (disallowJavaSerialization() && o instanceof Serializable) {
            throw new NotSerializableException(LocalizedStrings.DataSerializer_0_IS_NOT_DATASERIALIZABLE_AND_JAVA_SERIALIZATION_IS_DISALLOWED.toLocalizedString(o.getClass().getName()));
        }
        writeSerializableObject(o, out);
    }
}
Also used : PdxInstanceEnum(org.apache.geode.pdx.internal.PdxInstanceEnum) Serializable(java.io.Serializable) DataSerializable(org.apache.geode.DataSerializable) PdxSerializable(org.apache.geode.pdx.PdxSerializable) NotSerializableException(java.io.NotSerializableException) PdxInstance(org.apache.geode.pdx.PdxInstance) ObjectStreamClass(java.io.ObjectStreamClass) DataSerializable(org.apache.geode.DataSerializable) PdxSerializable(org.apache.geode.pdx.PdxSerializable)

Example 37 with NotSerializableException

use of java.io.NotSerializableException in project ignite by apache.

the class OptimizedClassDescriptor method write.

/**
     * Writes object to stream.
     *
     * @param out Output stream.
     * @param obj Object.
     * @throws IOException In case of error.
     */
@SuppressWarnings("ForLoopReplaceableByForEach")
void write(OptimizedObjectOutputStream out, Object obj) throws IOException {
    out.write(type);
    switch(type) {
        case BYTE:
            out.writeByte((Byte) obj);
            break;
        case SHORT:
            out.writeShort((Short) obj);
            break;
        case INT:
            out.writeInt((Integer) obj);
            break;
        case LONG:
            out.writeLong((Long) obj);
            break;
        case FLOAT:
            out.writeFloat((Float) obj);
            break;
        case DOUBLE:
            out.writeDouble((Double) obj);
            break;
        case CHAR:
            out.writeChar((Character) obj);
            break;
        case BOOLEAN:
            out.writeBoolean((Boolean) obj);
            break;
        case BYTE_ARR:
            out.writeByteArray((byte[]) obj);
            break;
        case SHORT_ARR:
            out.writeShortArray((short[]) obj);
            break;
        case INT_ARR:
            out.writeIntArray((int[]) obj);
            break;
        case LONG_ARR:
            out.writeLongArray((long[]) obj);
            break;
        case FLOAT_ARR:
            out.writeFloatArray((float[]) obj);
            break;
        case DOUBLE_ARR:
            out.writeDoubleArray((double[]) obj);
            break;
        case CHAR_ARR:
            out.writeCharArray((char[]) obj);
            break;
        case BOOLEAN_ARR:
            out.writeBooleanArray((boolean[]) obj);
            break;
        case OBJ_ARR:
            OptimizedClassDescriptor compDesc = OptimizedMarshallerUtils.classDescriptor(clsMap, obj.getClass().getComponentType(), ctx, mapper);
            compDesc.writeTypeData(out);
            out.writeArray((Object[]) obj);
            break;
        case STR:
            out.writeString((String) obj);
            break;
        case UUID:
            out.writeUuid((UUID) obj);
            break;
        case PROPS:
            out.writeProperties((Properties) obj, dfltsFieldOff);
            break;
        case ARRAY_LIST:
            out.writeArrayList((ArrayList<?>) obj);
            break;
        case HASH_MAP:
            out.writeHashMap((HashMap<?, ?>) obj, loadFactorFieldOff, false);
            break;
        case HASH_SET:
            out.writeHashSet((HashSet<?>) obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
            break;
        case LINKED_LIST:
            out.writeLinkedList((LinkedList<?>) obj);
            break;
        case LINKED_HASH_MAP:
            out.writeLinkedHashMap((LinkedHashMap<?, ?>) obj, loadFactorFieldOff, accessOrderFieldOff, false);
            break;
        case LINKED_HASH_SET:
            out.writeLinkedHashSet((LinkedHashSet<?>) obj, HASH_SET_MAP_OFF, loadFactorFieldOff);
            break;
        case DATE:
            out.writeDate((Date) obj);
            break;
        case CLS:
            OptimizedClassDescriptor clsDesc = OptimizedMarshallerUtils.classDescriptor(clsMap, (Class<?>) obj, ctx, mapper);
            clsDesc.writeTypeData(out);
            break;
        case PROXY:
            out.writeInt(proxyIntfs.length);
            for (Class<?> intf : proxyIntfs) {
                OptimizedClassDescriptor intfDesc = OptimizedMarshallerUtils.classDescriptor(clsMap, intf, ctx, mapper);
                intfDesc.writeTypeData(out);
            }
            InvocationHandler ih = Proxy.getInvocationHandler(obj);
            assert ih != null;
            out.writeObject(ih);
            break;
        case ENUM:
            writeTypeData(out);
            out.writeInt(((Enum) obj).ordinal());
            break;
        case EXTERNALIZABLE:
            writeTypeData(out);
            out.writeShort(checksum);
            out.writeExternalizable(obj);
            break;
        case SERIALIZABLE:
            if (out.requireSerializable() && !isSerial)
                throw new NotSerializableException("Must implement java.io.Serializable or " + "set OptimizedMarshaller.setRequireSerializable() to false " + "(note that performance may degrade if object is not Serializable): " + name);
            writeTypeData(out);
            out.writeShort(checksum);
            out.writeSerializable(obj, writeObjMtds, serializableFields(obj.getClass(), obj, null));
            break;
        default:
            throw new IllegalStateException("Invalid class type: " + type);
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 38 with NotSerializableException

use of java.io.NotSerializableException in project tomee by apache.

the class SimplePassivater method passivate.

public void passivate(final Object primaryKey, final Object state) throws SystemException {
    try {
        final String filename = primaryKey.toString().replace(':', '=');
        final File sessionFile = new File(sessionDirectory, filename);
        logger.info("Passivating to file " + sessionFile);
        try (final OutputStream os = IO.write(sessionFile);
            final ObjectOutputStream oos = new ObjectOutputStream(os)) {
            // passivate just the bean instance
            oos.writeObject(state);
        } finally {
            sessionFile.deleteOnExit();
        }
    } catch (final NotSerializableException nse) {
        logger.error("Passivation failed ", nse);
        throw (SystemException) new SystemException("The type " + nse.getMessage() + " is not serializable as mandated by the EJB specification.").initCause(nse);
    } catch (final Exception t) {
        logger.error("Passivation failed ", t);
        throw new SystemException(t);
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException) OutputStream(java.io.OutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) File(java.io.File) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) SystemException(org.apache.openejb.SystemException)

Example 39 with NotSerializableException

use of java.io.NotSerializableException in project tika by apache.

the class ForkClient method sendObject.

/**
     * Serializes the object first into an in-memory buffer and then
     * writes it to the output stream with a preceding size integer.
     *
     * @param object object to be serialized
     * @param resources list of fork resources, used when adding proxies
     * @throws IOException if the object could not be serialized
     */
private void sendObject(Object object, List<ForkResource> resources) throws IOException, TikaException {
    int n = resources.size();
    if (object instanceof InputStream) {
        resources.add(new InputStreamResource((InputStream) object));
        object = new InputStreamProxy(n);
    } else if (object instanceof ContentHandler) {
        resources.add(new ContentHandlerResource((ContentHandler) object));
        object = new ContentHandlerProxy(n);
    } else if (object instanceof ClassLoader) {
        resources.add(new ClassLoaderResource((ClassLoader) object));
        object = new ClassLoaderProxy(n);
    }
    try {
        ForkObjectInputStream.sendObject(object, output);
    } catch (NotSerializableException nse) {
        // Build a more friendly error message for this
        throw new TikaException("Unable to serialize " + object.getClass().getSimpleName() + " to pass to the Forked Parser", nse);
    }
    waitForResponse(resources);
}
Also used : NotSerializableException(java.io.NotSerializableException) TikaException(org.apache.tika.exception.TikaException) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) ContentHandler(org.xml.sax.ContentHandler)

Aggregations

NotSerializableException (java.io.NotSerializableException)39 ObjectOutputStream (java.io.ObjectOutputStream)14 IOException (java.io.IOException)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ObjectInputStream (java.io.ObjectInputStream)9 Test (org.junit.Test)9 Person (com.alibaba.dubbo.common.model.Person)7 ObjectOutput (com.alibaba.dubbo.common.serialize.ObjectOutput)7 ArrayList (java.util.ArrayList)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Serializable (java.io.Serializable)6 HashMap (java.util.HashMap)5 InvalidClassException (java.io.InvalidClassException)4 OptionalDataException (java.io.OptionalDataException)4 StreamCorruptedException (java.io.StreamCorruptedException)4 List (java.util.List)4 CancelException (org.apache.geode.CancelException)4 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)4 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OMemoryInputStream (com.orientechnologies.orient.core.serialization.OMemoryInputStream)3