camel jetty header 과 다 한 문제 해결 방법

5993 단어 Camel
camel 에서 Jetty 구성 요 소 를 사용 하면 http 인터페이스의 호출 과 감청 을 완성 할 수 있 습 니 다. 그러나 호출 할 때 header 매개 변수 값 이 너무 크 면 이상 정 보 를 던 집 니 다. 기본 Jetty 구성 요소 header 값 의 크기 는 최대 8k 입 니 다. 다음 코드 를 통 해 수정 할 수 있 습 니 다.
package com.xiaoka.camel.springboot.example.component;

import org.apache.camel.RuntimeCamelException;
import org.apache.camel.component.jetty.CamelHttpClient;
import org.apache.camel.component.jetty.JettyHttpComponent;
import org.apache.camel.component.jetty.JettyHttpEndpoint;
import org.apache.camel.component.jetty9.CamelHttpClient9;
import org.apache.camel.component.jetty9.JettyHttpEndpoint9;
import org.apache.camel.support.IntrospectionSupport;
import org.eclipse.jetty.client.HttpClientTransport;
import org.eclipse.jetty.server.*;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liuchengbiao
 * @date 2019-06-03 14:56
 */

public class JettyComponentDemo extends JettyHttpComponent {

    private static final Logger LOG = LoggerFactory.getLogger(JettyComponentDemo.class);

    protected CamelHttpClient createCamelHttpClient(HttpClientTransport transport, SslContextFactory sslContextFactory) {
        return new CamelHttpClient9(transport, sslContextFactory);
    }

    protected JettyHttpEndpoint createEndpoint(URI endpointUri, URI httpUri) throws URISyntaxException {
        return new JettyHttpEndpoint9(this, endpointUri.toString(), httpUri);
    }

    protected AbstractConnector createConnectorJettyInternal(Server server,
                                                             JettyHttpEndpoint endpoint,
                                                             SslContextFactory sslcf) {
        try {
            String host = endpoint.getHttpUri().getHost();
            int port = endpoint.getPort();
            org.eclipse.jetty.server.HttpConfiguration httpConfig = new org.eclipse.jetty.server.HttpConfiguration();
            httpConfig.setSendServerVersion(endpoint.isSendServerVersion());
            httpConfig.setSendDateHeader(endpoint.isSendDateHeader());
            System.out.println("   ");
            if (requestBufferSize != null) {
                // Does not work
                //httpConfig.setRequestBufferSize(requestBufferSize);
            }
            if (requestHeaderSize != null) {
                httpConfig.setRequestHeaderSize(requestHeaderSize);
            }
            if (responseBufferSize != null) {
                httpConfig.setOutputBufferSize(responseBufferSize);
            }
            int size = 1024 * 1024 * 10;
            httpConfig.setRequestHeaderSize(size);
            httpConfig.setResponseHeaderSize(size);

            if (responseHeaderSize != null) {
                httpConfig.setResponseHeaderSize(responseHeaderSize);
            }
            if (useXForwardedForHeader) {
                httpConfig.addCustomizer(new ForwardedRequestCustomizer());
            }
            HttpConnectionFactory httpFactory = new org.eclipse.jetty.server.HttpConnectionFactory(httpConfig);

            ArrayList connectionFactories = new ArrayList<>();
            ServerConnector result = new org.eclipse.jetty.server.ServerConnector(server);
            if (sslcf != null) {
                httpConfig.addCustomizer(new org.eclipse.jetty.server.SecureRequestCustomizer());
                SslConnectionFactory scf = new org.eclipse.jetty.server.SslConnectionFactory(sslcf, "HTTP/1.1");
                connectionFactories.add(scf);
                // The protocol name can be "SSL" or "SSL-HTTP/1.1" depending on the version of Jetty
                result.setDefaultProtocol(scf.getProtocol());
            }
            connectionFactories.add(httpFactory);
            for (ConnectionFactory cf : connectionFactories) {
                result.addConnectionFactory(cf);
            }
            result.setPort(port);
            if (host != null) {
                result.setHost(host);
            }
            if (sslcf != null) {
                if (getSslSocketConnectorProperties() != null && "https".equals(endpoint.getProtocol())) {
                    // must copy the map otherwise it will be deleted
                    Map properties = new HashMap<>(getSslSocketConnectorProperties());
                    IntrospectionSupport.setProperties(sslcf, properties);
                    if (properties.size() > 0) {
                        throw new IllegalArgumentException("There are " + properties.size()
                                + " parameters that couldn't be set on the SocketConnector."
                                + " Check the uri if the parameters are spelt correctly and that they are properties of the SelectChannelConnector."
                                + " Unknown parameters=[" + properties + "]");
                    }
                }

                LOG.info("Connector on port: {} is using includeCipherSuites: {} excludeCipherSuites: {} includeProtocols: {} excludeProtocols: {}",
                        port, sslcf.getIncludeCipherSuites(), sslcf.getExcludeCipherSuites(), sslcf.getIncludeProtocols(), sslcf.getExcludeProtocols());
            }

            return result;
        } catch (Exception e) {
            throw RuntimeCamelException.wrapRuntimeCamelException(e);
        }
    }

}

 
@Bean("jetty")
public JettyComponentDemo nothing() {
    JettyComponentDemo jetty = new JettyComponentDemo();
    int size = 1024 * 1024 * 10;
    jetty.setRequestHeaderSize(size);
    jetty.setResponseHeaderSize(size);
    return jetty;
}

 
위 와 같은 수정 을 통 해 최대 header 값 을 10M 으로 전송 할 수 있 습 니 다.

좋은 웹페이지 즐겨찾기