use of com.alibaba.rsocket.encoding.EncodingException in project alibaba-rsocket-broker by alibaba.
the class ObjectEncodingHandlerCborImpl method encodingParams.
@Override
public ByteBuf encodingParams(@Nullable Object[] args) throws EncodingException {
if (isArrayEmpty(args)) {
return EMPTY_BUFFER;
}
ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream bos = new ByteBufOutputStream(byteBuf);
objectMapper.writeValue((OutputStream) bos, args[0]);
return byteBuf;
} catch (Exception e) {
ReferenceCountUtil.safeRelease(byteBuf);
throw new EncodingException(RsocketErrorCode.message("RST-700500", Arrays.toString(args), "Bytebuf"), e);
}
}
use of com.alibaba.rsocket.encoding.EncodingException in project alibaba-rsocket-broker by alibaba.
the class ObjectEncodingHandlerCborImpl method encodingResult.
@Override
@NotNull
public ByteBuf encodingResult(@Nullable Object result) throws EncodingException {
if (result != null) {
ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream bos = new ByteBufOutputStream(byteBuf);
objectMapper.writeValue((OutputStream) bos, result);
return byteBuf;
} catch (Exception e) {
ReferenceCountUtil.safeRelease(byteBuf);
throw new EncodingException(RsocketErrorCode.message("RST-700500", result.toString(), "Bytebuf"), e);
}
}
return EMPTY_BUFFER;
}
use of com.alibaba.rsocket.encoding.EncodingException in project alibaba-rsocket-broker by alibaba.
the class ObjectEncodingHandlerHessianImpl method encode.
public static ByteBuf encode(Object obj) throws EncodingException {
ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer();
try {
ByteBufOutputStream bos = new ByteBufOutputStream(byteBuf);
HessianSerializerOutput output = new HessianSerializerOutput(bos);
output.writeObject(obj);
output.flush();
return byteBuf;
} catch (Exception e) {
ReferenceCountUtil.safeRelease(byteBuf);
throw new EncodingException(RsocketErrorCode.message("RST-700500", obj.getClass().getName(), "byte[]"), e);
}
}
use of com.alibaba.rsocket.encoding.EncodingException in project alibaba-rsocket-broker by alibaba.
the class ObjectEncodingHandlerJsonImpl method encodingResult.
@Override
@NotNull
public ByteBuf encodingResult(@Nullable Object result) throws EncodingException {
if (result == null) {
return EMPTY_BUFFER;
}
ByteBuf byteBuf = PooledByteBufAllocator.DEFAULT.buffer();
try {
if (ktJson && KotlinSerializerSupport.isKotlinSerializable(result.getClass())) {
return Unpooled.wrappedBuffer(KotlinSerializerSupport.encodeAsJson(result));
} else {
ByteBufOutputStream bos = new ByteBufOutputStream(byteBuf);
JsonUtils.objectMapper.writeValue((OutputStream) bos, result);
return byteBuf;
}
} catch (Exception e) {
ReferenceCountUtil.safeRelease(byteBuf);
throw new EncodingException(RsocketErrorCode.message("RST-700500", result.getClass().getCanonicalName(), "ByteBuf"), e);
}
}
use of com.alibaba.rsocket.encoding.EncodingException in project alibaba-rsocket-broker by alibaba.
the class ObjectEncodingHandlerSerializationImpl method byteBufToObject.
private Object byteBufToObject(ByteBuf data) throws EncodingException {
try {
ObjectInputStream inputStream = new ObjectInputStream(new ByteBufInputStream(data));
Object object = inputStream.readObject();
inputStream.close();
return object;
} catch (Exception e) {
throw new EncodingException(RsocketErrorCode.message("RST-700501", "byte[]", "Object"), e);
}
}
Aggregations