Не получаю ответа от сервера исключений ни каких. Не знаю уже что делать, помогите люди добрые! 1 хендлер
public class KeysKeeperHandler extends ChannelInboundHandlerAdapter {
private Cache cache;
public KeysKeeperHandler(Cache cache) {
this.cache = cache;
}
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
Packet packet = (Packet)msg;
Responce responce = new Responce();
if (!packet.getKey().isEmpty() && packet.getValue() != null){
try {
this.cache.addItem(packet.getKey(),packet.getValue());
responce.setStatusCode(200);
} catch (Exception e){
e.printStackTrace();
}catch (OutOfMemoryError e){
this.cache.saveRelease();
}
}
if(!packet.getKey().isEmpty() && packet.getValue() == null){
responce.setBody(this.cache.getItem(packet.getKey()));
}
final ChannelFuture f = ctx.write(responce);
f.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture future) {
assert f == future;
ctx.close();
}
});
}
public static byte[] objectToByteArray(Object obj) throws Exception
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
try
{
oos.writeObject(obj);
return baos.toByteArray();
}
catch (Exception e)
{
throw e;
}
finally
{
oos.close();
baos.close();
}
}
@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
cause.printStackTrace();
ctx.close();
}
}
2 хендлер
public class TrafficEncoder extends MessageToByteEncoder<Responce>{
@Override
protected void encode(ChannelHandlerContext ctx, Responce msg, ByteBuf out) throws Exception {
out.writeBytes(objectToByteArray(msg));
}
public static byte[] objectToByteArray(Object obj) throws Exception {
try(ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(obj);
return baos.toByteArray();
}
}
}
Апостиль в Лос-Анджелесе без лишних нервов и бумажной волокиты
Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости