public Consumer createConsumer(Processor processor) throws Exception { Consumer answer = new NettyConsumer(this, processor, configuration); configureConsumer(answer); return answer; }
public Exchange createExchange(ChannelHandlerContext ctx, Object message) throws Exception { Exchange exchange = createExchange(); updateMessageHeader(exchange.getIn(), ctx); NettyPayloadHelper.setIn(exchange, message); return exchange; }
protected void updateMessageHeader(Message in, ChannelHandlerContext ctx) { in.setHeader(NettyConstants.NETTY_CHANNEL_HANDLER_CONTEXT, ctx); in.setHeader(NettyConstants.NETTY_REMOTE_ADDRESS, ctx.channel().remoteAddress()); in.setHeader(NettyConstants.NETTY_LOCAL_ADDRESS, ctx.channel().localAddress()); if (configuration.isSsl()) { // setup the SslSession header SSLSession sslSession = getSSLSession(ctx); in.setHeader(NettyConstants.NETTY_SSL_SESSION, sslSession); // enrich headers with details from the client certificate if option is enabled if (configuration.isSslClientCertHeaders()) { enrichWithClientCertInformation(sslSession, in); } } }
@Override protected String createEndpointUri() { ObjectHelper.notNull(configuration, "configuration"); return "netty4:" + getConfiguration().getProtocol() + "://" + getConfiguration().getHost() + ":" + getConfiguration().getPort(); }
@Override protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { NettyConfiguration config; if (configuration != null) { config = configuration.copy(); } else { config = new NettyConfiguration(); } config = parseConfiguration(config, remaining, parameters); // merge any custom bootstrap configuration on the config NettyServerBootstrapConfiguration bootstrapConfiguration = resolveAndRemoveReferenceParameter(parameters, "bootstrapConfiguration", NettyServerBootstrapConfiguration.class); if (bootstrapConfiguration != null) { Map<String, Object> options = new HashMap<>(); if (IntrospectionSupport.getProperties(bootstrapConfiguration, options, null, false)) { IntrospectionSupport.setProperties(getCamelContext().getTypeConverter(), config, options); } } if (config.getSslContextParameters() == null) { config.setSslContextParameters(retrieveGlobalSslContextParameters()); } // validate config config.validateConfiguration(); NettyEndpoint nettyEndpoint = new NettyEndpoint(remaining, this, config); setProperties(nettyEndpoint.getConfiguration(), parameters); return nettyEndpoint; }
@Override protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { Object in = msg; if (LOG.isDebugEnabled()) { LOG.debug("Channel: {} received body: {}", ctx.channel(), in); } // create Exchange and let the consumer process it final Exchange exchange = consumer.getEndpoint().createExchange(ctx, msg); if (consumer.getConfiguration().isSync()) { exchange.setPattern(ExchangePattern.InOut); } // set the exchange charset property for converting if (consumer.getConfiguration().getCharsetName() != null) { exchange.setProperty(Exchange.CHARSET_NAME, IOHelper.normalizeCharset(consumer.getConfiguration().getCharsetName())); } if (consumer.getConfiguration().isReuseChannel()) { exchange.setProperty(NettyConstants.NETTY_CHANNEL, ctx.channel()); } // we want to handle the UoW consumer.createUoW(exchange); beforeProcess(exchange, ctx, msg); // process accordingly to endpoint configuration if (consumer.getEndpoint().isSynchronous()) { processSynchronously(exchange, ctx, msg); } else { processAsynchronously(exchange, ctx, msg); } }
public NettyProducer(NettyEndpoint nettyEndpoint, NettyConfiguration configuration) { super(nettyEndpoint); this.configuration = configuration; this.context = this.getEndpoint().getCamelContext(); this.noReplyLogger = new CamelLogger(LOG, configuration.getNoReplyLogLevel()); }
public Producer createProducer() throws Exception { Producer answer = new NettyProducer(this, configuration); if (isSynchronous()) { return new SynchronousDelegateProducer(answer); } else { return answer; } }
EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService(); addToPipeline("handler", channelPipeline, applicationExecutor, new ServerChannelHandler(consumer));
public static Object getIn(NettyEndpoint endpoint, Exchange exchange) { if (endpoint.getConfiguration().isTransferExchange()) { // we should transfer the entire exchange over the wire (includes in/out) return DefaultExchangeHolder.marshal(exchange, true, endpoint.getConfiguration().isAllowSerializedHeaders()); } else { if (endpoint.getConfiguration().isUseByteBuf()) { // Just leverage the type converter return exchange.getIn().getBody(ByteBuf.class); } else { // normal transfer using the body only return exchange.getIn().getBody(); } } }
public NettyConsumer(NettyEndpoint nettyEndpoint, Processor processor, NettyConfiguration configuration) { super(nettyEndpoint, processor); this.context = this.getEndpoint().getCamelContext(); this.configuration = configuration; setNettyServerBootstrapFactory(configuration.getNettyServerBootstrapFactory()); setExceptionHandler(new NettyConsumerExceptionHandler(this)); }
public static Object getOut(NettyEndpoint endpoint, Exchange exchange) { if (endpoint.getConfiguration().isTransferExchange()) { // we should transfer the entire exchange over the wire (includes in/out) return DefaultExchangeHolder.marshal(exchange); } else { // normal transfer using the body only return exchange.getOut().getBody(); } }
LOG.trace("Closing channel when complete at address: {}", getEndpoint().getConfiguration().getAddress());
/** * Gets the object we want to use as the response object for sending to netty. * * @param exchange the exchange * @return the object to use as response * @throws Exception is thrown if error getting the response body */ protected Object getResponseBody(Exchange exchange) throws Exception { // if there was an exception then use that as response body boolean exception = exchange.getException() != null && !consumer.getEndpoint().getConfiguration().isTransferExchange(); if (exception) { return exchange.getException(); } if (exchange.hasOut()) { return NettyPayloadHelper.getOut(consumer.getEndpoint(), exchange); } else { return NettyPayloadHelper.getIn(consumer.getEndpoint(), exchange); } }