use of com.zx.sms.common.NotSupportedException in project SMSGate by Lihuanghe.
the class AbstractEndpointConnector method addProxyHandler.
protected void addProxyHandler(Channel ch, URI proxy) throws NotSupportedException {
if (proxy == null)
return;
String scheme = proxy.getScheme();
String userinfo = proxy.getUserInfo();
String host = proxy.getHost();
int port = proxy.getPort();
String username = null;
String pass = null;
if (userinfo != null && (!"".equals(userinfo))) {
int idx = userinfo.indexOf(":");
if (idx > 0) {
username = userinfo.substring(0, idx);
pass = userinfo.substring(idx + 1);
}
}
ChannelPipeline pipeline = ch.pipeline();
if ("HTTP".equalsIgnoreCase(scheme)) {
if (username == null) {
pipeline.addLast(new HttpProxyHandler(new InetSocketAddress(host, port)));
} else {
pipeline.addLast(new HttpProxyHandler(new InetSocketAddress(host, port), username, pass));
}
} else if ("SOCKS5".equalsIgnoreCase(scheme)) {
if (username == null) {
pipeline.addLast(new Socks5ProxyHandler(new InetSocketAddress(host, port)));
} else {
pipeline.addLast(new Socks5ProxyHandler(new InetSocketAddress(host, port), username, pass));
}
} else if ("SOCKS4".equalsIgnoreCase(scheme)) {
if (username == null) {
pipeline.addLast(new Socks4ProxyHandler(new InetSocketAddress(host, port)));
} else {
pipeline.addLast(new Socks4ProxyHandler(new InetSocketAddress(host, port), username));
}
} else {
throw new NotSupportedException("not support proxy protocol " + scheme);
}
}
use of com.zx.sms.common.NotSupportedException in project SMSGate by Lihuanghe.
the class CmppConnectResponseMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (commandId != packetType.getCommandId()) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
CmppConnectResponseMessage responseMessage = new CmppConnectResponseMessage(msg.getHeader());
byte[] body = msg.getBodyBuffer();
if (body.length == 21) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(msg.getBodyBuffer());
responseMessage.setStatus(bodyBuffer.readUnsignedInt());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, CmppConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
} else {
if (body.length == 18) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(body);
responseMessage.setStatus(bodyBuffer.readUnsignedByte());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, Cmpp20ConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
logger.warn("error CmppConnectResponseMessage body length. dump:{}", ByteBufUtil.hexDump(body));
} else {
throw new NotSupportedException("error cmpp CmppConnectResponseMessage data .");
}
}
}
use of com.zx.sms.common.NotSupportedException in project SMSGate by Lihuanghe.
the class Cmpp20ConnectResponseMessageCodec method decode.
@Override
protected void decode(ChannelHandlerContext ctx, Message msg, List<Object> out) throws Exception {
int commandId = msg.getHeader().getCommandId();
if (commandId != packetType.getCommandId()) {
// 不解析,交给下一个codec
out.add(msg);
return;
}
CmppConnectResponseMessage responseMessage = new CmppConnectResponseMessage(msg.getHeader());
byte[] body = msg.getBodyBuffer();
if (body.length == 18) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(body);
responseMessage.setStatus(bodyBuffer.readUnsignedByte());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, Cmpp20ConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
} else {
if (body.length == 21) {
ByteBuf bodyBuffer = Unpooled.wrappedBuffer(body);
responseMessage.setStatus(bodyBuffer.readUnsignedInt());
responseMessage.setAuthenticatorISMG(toArray(bodyBuffer, CmppConnectResponse.AUTHENTICATORISMG.getLength()));
responseMessage.setVersion(bodyBuffer.readUnsignedByte());
ReferenceCountUtil.release(bodyBuffer);
out.add(responseMessage);
logger.warn("error Cmpp20ConnectResponseMessageCodec body length. dump:{}", ByteBufUtil.hexDump(body));
} else {
throw new NotSupportedException("error cmpp CmppConnectResponseMessage data .");
}
}
}
Aggregations