SSL - HTTPException:通信时HTTP响应'413:请求实体太大'

时间:2015-07-30 18:39:14

标签: java apache cxf webservice-client wildfly-8

我在Wildfly有一个web服务客户端试图上传一个大约400到500kb的小文件,它工作正常但是当我添加了客户端证书身份验证逻辑时,它抱怨

HTTPException: HTTP response '413: Request Entity Too Large' when communicating with 

我在这里缺少什么或为什么它会停止工作,如何修复它。 服务器使用xdoclet标记实现服务。客户端身份验证是在apache级别完成的,而不是应用程序代码。

以下是代码:

        String WS_URL = PropertiesLoader.getInstance().getMyServiceWsdlUrl();
        URL url = new URL(WS_URL);
        QName qname = new QName(PropertiesLoader.getInstance().getMyServiceNamespaceURI(), "MyService");

        //Service service = Service.create(url, qname);

        Service service = Service.create(qname);

        MyEndpoint myEndpointPort = service.getPort(MyEndpoint.class);
        //HACK: The underlying "JMess" changes our passed Endpoint URL with the hostname of the box (that we won't be able to find
        //      since everything is straight IP's...  So we update it again here... There has to be a better way...
        //((BindingProvider)myEndpointPort).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,WS_URL.replace("?wsdl",""));
        Map<String, Object> req_ctx = ((BindingProvider) myEndpointPort).getRequestContext();
        req_ctx.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, WS_URL.replace("?wsdl",""));
        BindingProvider bp = (BindingProvider) myEndpointPort;
        SOAPBinding binding = (SOAPBinding) bp.getBinding();

        // Adding Client Authentication
        System.setProperty("javax.net.ssl.trustStore", PropertiesLoader.getInstance().getServerTruststore());
        System.setProperty("javax.net.ssl.trustStorePassword", PropertiesLoader.getInstance().getServerTruststorePassword());
        System.setProperty("javax.net.ssl.keyStore", PropertiesLoader.getInstance().getServerKeystore());
        System.setProperty("javax.net.ssl.keyStorePassword", PropertiesLoader.getInstance().getServerKeystorePassword());
        System.setProperty("javax.net.debug", "SSL");

        Client client=ClientProxy.getClient(myEndpointPort);
        HTTPConduit conduit = (HTTPConduit)client.getConduit();
        TLSClientParameters tlsParams = new TLSClientParameters();

        // Disabling host name check
        tlsParams.setDisableCNCheck(true);

        // Setup Truststore 
        KeyStore keyStore = KeyStore.getInstance("JKS");
        File truststore = new File(PropertiesLoader.getInstance().getServerTruststore());
        keyStore.load(new FileInputStream(truststore), PropertiesLoader.getInstance().getServerTruststorePassword().toCharArray()); 

        // Setting trust manager(s)
        TrustManagerFactory trustFactory = 
            TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 
        trustFactory.init(keyStore); 
        TrustManager[] tm = trustFactory.getTrustManagers(); 
        tlsParams.setTrustManagers(tm);

        // Setup Keystore 
        truststore = new File(PropertiesLoader.getInstance().getServerKeystore());
        keyStore.load(new FileInputStream(truststore), PropertiesLoader.getInstance().getServerKeystorePassword().toCharArray());

        // Setting up key manager(s)
        KeyManagerFactory keyFactory = 
            KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());                         
        keyFactory.init(keyStore, PropertiesLoader.getInstance().getServerKeystorePassword().toCharArray()); 
        KeyManager[] km = keyFactory.getKeyManagers();                      
        tlsParams.setKeyManagers(km); 

        // Setting parameters
        conduit.setTlsClientParameters(tlsParams); 

1 个答案:

答案 0 :(得分:0)

这是apache中SSL Regeneration Buffer大小的问题。 修复是使用SSLRenegBufferSize指令增加缓冲区大小, 我把它设置为8MB。

<Location "/myws/feature/FeatureEndpoint">
    SSLVerifyClient optional_no_ca
    SSLRenegBufferSize 8388608
    SSLVerifyDepth 1
    SSLOptions +StdEnvVars
    SSLRequire %{SSL_CLIENT_S_DN_CN} eq "Client Certificate"
</Location>