use of org.mule.runtime.api.serialization.SerializationException in project mule by mulesoft.
the class AbstractSerializationProtocol method serialize.
/**
* {@inheritDoc}
*
* @throws IllegalArgumentException if object is not a {@link java.io.Serializable}
*/
@Override
public void serialize(Object object, OutputStream out) throws SerializationException {
try {
byte[] bytes = serialize(object);
out.write(bytes);
out.flush();
} catch (IOException e) {
throw new SerializationException("Could not write to output stream", e);
} finally {
closeQuietly(out);
}
}
use of org.mule.runtime.api.serialization.SerializationException in project mule by mulesoft.
the class AbstractSerializationProtocol method deserialize.
/**
* {@inheritDoc}
*/
@Override
public <T> T deserialize(InputStream inputStream, ClassLoader classLoader) throws SerializationException {
checkArgument(inputStream != null, "Cannot deserialize a null stream");
checkArgument(classLoader != null, "Cannot deserialize with a null classloader");
try {
return (T) postInitialize(doDeserialize(inputStream, classLoader));
} catch (Exception e) {
throw new SerializationException("Could not deserialize object", e);
} finally {
closeQuietly(inputStream);
}
}
use of org.mule.runtime.api.serialization.SerializationException in project mule by mulesoft.
the class CustomJavaSerializationProtocol method doSerialize.
/**
* {@inheritDoc}
*/
@Override
protected byte[] doSerialize(Object object) throws Exception {
// TODO: MULE-11939
if (object instanceof CursorStreamProvider) {
try (CursorStream cursor = ((CursorStreamProvider) object).openCursor()) {
object = toByteArray(cursor);
}
}
validateForSerialization(object);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream(512);
try (ObjectOutputStream out = new ArtifactClassLoaderObjectOutputStream(classLoaderRepository, outputStream)) {
out.writeObject(object);
} catch (IOException ex) {
throw new SerializationException("Cannot serialize object", ex);
}
return outputStream.toByteArray();
}
use of org.mule.runtime.api.serialization.SerializationException in project mule by mulesoft.
the class CustomJavaSerializationProtocol method doDeserialize.
/**
* {@inheritDoc}
*/
@Override
protected <T> T doDeserialize(InputStream inputStream, ClassLoader classLoader) throws Exception {
checkArgument(inputStream != null, "Cannot deserialize a null stream");
checkArgument(classLoader != null, "Cannot deserialize with a null classloader");
try (ObjectInputStream in = new ArtifactClassLoaderObjectInputStream(classLoaderRepository, inputStream)) {
Object obj = in.readObject();
return (T) obj;
} catch (Exception ex) {
throw new SerializationException("Cannot deserialize object", ex);
}
}
use of org.mule.runtime.api.serialization.SerializationException in project mule by mulesoft.
the class MessageChunkAggregator method getCorrelatorCallback.
@Override
protected EventCorrelatorCallback getCorrelatorCallback(MuleContext muleContext) {
return new CollectionCorrelatorCallback(muleContext, storePrefix) {
/**
* This method is invoked if the shouldAggregate method is called and returns true. Once this method returns an aggregated
* message the event group is removed from the router
*
* @param events the event group for this request
* @return an aggregated message
* @throws AggregationException if the aggregation fails. in this scenario the whole event
* group is removed and passed to the exception handler for this componenet
*/
@Override
public CoreEvent aggregateEvents(EventGroup events) throws AggregationException {
PrivilegedEvent[] collectedEvents;
try {
collectedEvents = events.toArray(false);
} catch (ObjectStoreException e) {
throw new AggregationException(events, MessageChunkAggregator.this, e);
}
CoreEvent firstEvent = collectedEvents[0];
Arrays.sort(collectedEvents, eventComparator);
ByteArrayOutputStream baos = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
try {
for (PrivilegedEvent event : collectedEvents) {
baos.write(event.getMessageAsBytes(muleContext));
}
final Message.Builder builder = Message.builder(firstEvent.getMessage());
// try to deserialize message, since ChunkingRouter might have serialized the object...
try {
builder.value(muleContext.getObjectSerializer().getInternalProtocol().deserialize(baos.toByteArray()));
} catch (SerializationException e) {
builder.value(baos.toByteArray());
}
// Use last event, that hasn't been completed yet, for continued processing.
return PrivilegedEvent.builder(collectedEvents[collectedEvents.length - 1]).message(builder.build()).session(getMergedSession(events.toArray())).build();
} catch (Exception e) {
throw new AggregationException(events, MessageChunkAggregator.this, e);
} finally {
closeQuietly(baos);
}
}
};
}
Aggregations