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);
}
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;
}
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);
}
}
}
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);
}
}
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;
}
}
}
Aggregations