Search in sources :

Example 16 with HTTPMessageHeader

use of APJP.ANDROID.HTTP11.HTTPMessageHeader in project apjp by jvansteirteghem.

the class HTTPSServlet method doPost.

public void doPost(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
    try {
        httpServletResponse.setStatus(200);
        for (int i = 0; i < APJP_REMOTE_HTTPS_SERVER_RESPONSE_PROPERTY_KEY.length; i = i + 1) {
            if (APJP_REMOTE_HTTPS_SERVER_RESPONSE_PROPERTY_KEY[i].equalsIgnoreCase("") == false) {
                httpServletResponse.addHeader(APJP_REMOTE_HTTPS_SERVER_RESPONSE_PROPERTY_KEY[i], APJP_REMOTE_HTTPS_SERVER_RESPONSE_PROPERTY_VALUE[i]);
            }
        }
        SecretKeySpec secretKeySpec = new SecretKeySpec(APJP_KEY.getBytes(), "ARCFOUR");
        Cipher inputStreamCipher = Cipher.getInstance("ARCFOUR");
        inputStreamCipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
        CipherInputStream httpRequestInputStream = new CipherInputStream(httpServletRequest.getInputStream(), inputStreamCipher);
        Cipher outputStreamCipher = Cipher.getInstance("ARCFOUR");
        outputStreamCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
        CipherOutputStream httpResponseOutputStream = new CipherOutputStream(httpServletResponse.getOutputStream(), outputStreamCipher);
        HTTPRequestMessage httpRequestMessage1 = new HTTPRequestMessage(httpRequestInputStream);
        httpRequestMessage1.read();
        HTTPSRequest httpsRequest1 = new HTTPSRequest(httpRequestMessage1);
        httpsRequest1.open();
        try {
            HTTPResponseMessage httpResponseMessage1 = httpsRequest1.getHTTPResponseMessage();
            HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
            HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
            String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
            String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
            httpResponseOutputStream.write((httpResponseMessage1Header1Value1 + "\r\n").getBytes());
            for (int i = 1; i < httpResponseMessage1Headers1.length; i = i + 1) {
                httpResponseMessage1Header1 = httpResponseMessage1Headers1[i];
                httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
                httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
                httpResponseOutputStream.write((httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1 + "\r\n").getBytes());
            }
            httpResponseOutputStream.write(("\r\n").getBytes());
            httpResponseMessage1.read(httpResponseOutputStream);
        } catch (Exception e) {
            throw e;
        } finally {
            try {
                httpsRequest1.close();
            } catch (Exception e) {
            }
        }
    } catch (Exception e) {
        logger.log(Level.INFO, "EXCEPTION", e);
        httpServletResponse.setStatus(500);
    }
}
Also used : HTTPRequestMessage(APJP.HTTP11.HTTPRequestMessage) CipherOutputStream(javax.crypto.CipherOutputStream) HTTPSRequest(APJP.HTTP11.HTTPSRequest) CipherInputStream(javax.crypto.CipherInputStream) SecretKeySpec(javax.crypto.spec.SecretKeySpec) HTTPResponseMessage(APJP.HTTP11.HTTPResponseMessage) Cipher(javax.crypto.Cipher) HTTPMessageHeader(APJP.HTTP11.HTTPMessageHeader) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

HTTPMessageHeader (APJP.HTTP11.HTTPMessageHeader)9 HTTPMessageHeader (APJP.ANDROID.HTTP11.HTTPMessageHeader)7 InputStream (java.io.InputStream)6 OutputStream (java.io.OutputStream)6 HTTPRequestMessage (APJP.HTTP11.HTTPRequestMessage)5 HTTPResponseMessage (APJP.HTTP11.HTTPResponseMessage)4 HTTPRequestMessage (APJP.ANDROID.HTTP11.HTTPRequestMessage)3 HTTPResponseMessage (APJP.ANDROID.HTTP11.HTTPResponseMessage)2 HTTPRequest (APJP.HTTP11.HTTPRequest)2 HTTPSRequest (APJP.HTTP11.HTTPSRequest)2 IOException (java.io.IOException)2 InetSocketAddress (java.net.InetSocketAddress)2 Socket (java.net.Socket)2 Cipher (javax.crypto.Cipher)2 CipherInputStream (javax.crypto.CipherInputStream)2 CipherOutputStream (javax.crypto.CipherOutputStream)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 ServletException (javax.servlet.ServletException)2 HTTPRequest (APJP.ANDROID.HTTP11.HTTPRequest)1 HTTPRequests (APJP.ANDROID.HTTP11.HTTPRequests)1