Search in sources :

Example 21 with NotSerializableException

use of java.io.NotSerializableException in project config by typesafehub.

the class SerializedConfigValue method writeExternal.

@Override
public void writeExternal(ObjectOutput out) throws IOException {
    if (((AbstractConfigValue) value).resolveStatus() != ResolveStatus.RESOLVED)
        throw new NotSerializableException("tried to serialize a value with unresolved substitutions, need to Config#resolve() first, see API docs");
    FieldOut field = new FieldOut(SerializedField.ROOT_VALUE);
    writeValue(field.data, value, null);
    writeField(out, field);
    field = new FieldOut(SerializedField.ROOT_WAS_CONFIG);
    field.data.writeBoolean(wasConfig);
    writeField(out, field);
    writeEndMarker(out);
}
Also used : NotSerializableException(java.io.NotSerializableException)

Example 22 with NotSerializableException

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

the class BaseEjbProxyHandler method copyObj.

/* change dereference to copy */
protected <T> T copyObj(final T object) throws IOException, ClassNotFoundException {
    // we can safely return them.
    if (object == null) {
        return null;
    }
    final Class ooc = object.getClass();
    if (ooc == int.class || ooc == String.class || ooc == long.class || ooc == boolean.class || ooc == byte.class || ooc == float.class || ooc == double.class || ooc == short.class || ooc == Long.class || ooc == Boolean.class || ooc == Byte.class || ooc == Character.class || ooc == Float.class || ooc == Double.class || ooc == Short.class || ooc == BigDecimal.class) {
        return object;
    }
    final ByteArrayOutputStream baos = new ByteArrayOutputStream(128);
    try {
        final ObjectOutputStream out = new ObjectOutputStream(baos);
        out.writeObject(object);
        out.close();
    } catch (final NotSerializableException e) {
        throw (IOException) new NotSerializableException(e.getMessage() + " : The EJB specification restricts remote interfaces to only serializable data types.  This can be disabled for in-vm use with the " + OPENEJB_LOCALCOPY + "=false system property.").initCause(e);
    }
    final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    final ObjectInputStream in = new EjbObjectInputStream(bais);
    final Object obj = in.readObject();
    return (T) obj;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) BigDecimal(java.math.BigDecimal) NotSerializableException(java.io.NotSerializableException) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 23 with NotSerializableException

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

the class ForkServer method call.

private void call(ClassLoader loader, Object object) throws Exception {
    Method method = getMethod(object, input.readUTF());
    Object[] args = new Object[method.getParameterTypes().length];
    for (int i = 0; i < args.length; i++) {
        args[i] = readObject(loader);
    }
    try {
        method.invoke(object, args);
        output.write(DONE);
    } catch (InvocationTargetException e) {
        output.write(ERROR);
        // Try to send the underlying Exception itself
        Throwable toSend = e.getCause();
        try {
            ForkObjectInputStream.sendObject(toSend, output);
        } catch (NotSerializableException nse) {
            // Need to build a serializable version of it
            TikaException te = new TikaException(toSend.getMessage());
            te.setStackTrace(toSend.getStackTrace());
            ForkObjectInputStream.sendObject(te, output);
        }
    }
}
Also used : NotSerializableException(java.io.NotSerializableException) TikaException(org.apache.tika.exception.TikaException) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 24 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);
        if (!sessionFile.exists() && !sessionFile.createNewFile()) {
            throw new Exception("Failed to create passivation file: " + sessionFile.getAbsolutePath());
        }
        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 25 with NotSerializableException

use of java.io.NotSerializableException in project hudson-2.x by hudson.

the class UserResponse method perform.

protected UserResponse<RSP, EXC> perform(Channel channel) throws EXC {
    try {
        ClassLoader cl = channel.importedClassLoaders.get(classLoaderProxy);
        RSP r = null;
        Channel oldc = Channel.setCurrent(channel);
        try {
            Object o;
            try {
                o = deserialize(channel, request, cl);
            } catch (ClassNotFoundException e) {
                throw new ClassNotFoundException("Failed to deserialize the Callable object. Perhaps you needed to implement DelegatingCallable?", e);
            }
            Callable<RSP, EXC> callable = (Callable<RSP, EXC>) o;
            if (channel.isRestricted && !(callable instanceof RPCRequest))
                // OTOH, we need to allow RPCRequest so that method invocations on exported objects will go through.
                throw new SecurityException("Execution of " + callable.toString() + " is prohibited because the channel is restricted");
            ClassLoader old = Thread.currentThread().getContextClassLoader();
            Thread.currentThread().setContextClassLoader(cl);
            // execute the service
            try {
                r = callable.call();
            } finally {
                Thread.currentThread().setContextClassLoader(old);
            }
        } finally {
            Channel.setCurrent(oldc);
        }
        return new UserResponse<RSP, EXC>(serialize(r, channel), false);
    } catch (Throwable e) {
        // propagate this to the calling process
        try {
            byte[] response;
            try {
                response = _serialize(e, channel);
            } catch (NotSerializableException x) {
                // perhaps the thrown runtime exception is of type we can't handle
                response = serialize(new ProxyException(e), channel);
            }
            return new UserResponse<RSP, EXC>(response, true);
        } catch (IOException x) {
            // throw it as a lower-level exception
            throw (EXC) x;
        }
    }
}
Also used : IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) RPCRequest(hudson.remoting.RemoteInvocationHandler.RPCRequest) IClassLoader(hudson.remoting.RemoteClassLoader.IClassLoader)

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