Search in sources :

Example 1 with NotSupportedException

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpProxyHandler(io.netty.handler.proxy.HttpProxyHandler) Socks4ProxyHandler(io.netty.handler.proxy.Socks4ProxyHandler) NotSupportedException(com.zx.sms.common.NotSupportedException) ChannelPipeline(io.netty.channel.ChannelPipeline) Socks5ProxyHandler(io.netty.handler.proxy.Socks5ProxyHandler)

Example 2 with NotSupportedException

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 .");
        }
    }
}
Also used : CmppConnectResponseMessage(com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage) ByteBuf(io.netty.buffer.ByteBuf) NotSupportedException(com.zx.sms.common.NotSupportedException)

Example 3 with NotSupportedException

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 .");
        }
    }
}
Also used : CmppConnectResponseMessage(com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage) ByteBuf(io.netty.buffer.ByteBuf) NotSupportedException(com.zx.sms.common.NotSupportedException)

Aggregations

NotSupportedException (com.zx.sms.common.NotSupportedException)3 CmppConnectResponseMessage (com.zx.sms.codec.cmpp.msg.CmppConnectResponseMessage)2 ByteBuf (io.netty.buffer.ByteBuf)2 ChannelPipeline (io.netty.channel.ChannelPipeline)1 HttpProxyHandler (io.netty.handler.proxy.HttpProxyHandler)1 Socks4ProxyHandler (io.netty.handler.proxy.Socks4ProxyHandler)1 Socks5ProxyHandler (io.netty.handler.proxy.Socks5ProxyHandler)1 InetSocketAddress (java.net.InetSocketAddress)1