1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.waarp.commandexec.ssl.client;
21
22 import io.netty.channel.ChannelHandlerContext;
23 import org.waarp.commandexec.client.LocalExecClientHandler;
24 import org.waarp.commandexec.client.LocalExecClientInitializer;
25 import org.waarp.commandexec.utils.LocalExecDefaultResult;
26 import org.waarp.common.crypto.ssl.WaarpSslUtility;
27 import org.waarp.common.logging.WaarpLogger;
28 import org.waarp.common.logging.WaarpLoggerFactory;
29
30 import javax.net.ssl.SSLException;
31
32
33
34
35 public class LocalExecSslClientHandler extends LocalExecClientHandler {
36
37
38
39 private static final WaarpLogger logger =
40 WaarpLoggerFactory.getLogger(LocalExecSslClientHandler.class);
41
42
43
44
45 public LocalExecSslClientHandler(final LocalExecClientInitializer factory) {
46 super(factory);
47 }
48
49 @Override
50 public void channelRegistered(final ChannelHandlerContext ctx)
51 throws Exception {
52 WaarpSslUtility.addSslOpenedChannel(ctx.channel());
53 super.channelRegistered(ctx);
54 }
55
56 @Override
57 public void exceptionCaught(final ChannelHandlerContext ctx,
58 final Throwable cause) {
59 logger.warn("Unexpected exception from Outband while get information: " +
60 firstMessage, cause);
61 if (firstMessage) {
62 firstMessage = false;
63 result.set(LocalExecDefaultResult.BadTransmition);
64 result.setException((Exception) cause);
65 back = new StringBuilder("Error in LocalExec: ").append(
66 result.getException().getMessage()).append('\n');
67 } else {
68 if (cause instanceof SSLException) {
69
70 logger.warn("Ignore exception ?", cause);
71 return;
72 }
73 back.append("\nERROR while receiving answer: ");
74 result.setException((Exception) cause);
75 back.append(result.getException().getMessage()).append('\n');
76 }
77 actionBeforeClose(ctx.channel());
78 WaarpSslUtility.closingSslChannel(ctx.channel());
79 }
80 }