Search in sources :

Example 1 with MessageHeader

use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.

the class NTLMTest method handleConnection.

static void handleConnection(Socket s, String[] resp, int start, int end) {
    try {
        OutputStream os = s.getOutputStream();
        for (int i = start; i < end; i++) {
            MessageHeader header = new MessageHeader(s.getInputStream());
            //System.out.println("Input :" + header);
            //System.out.println("Output:" + resp[i]);
            os.write(resp[i].getBytes("ASCII"));
        }
        s.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
}
Also used : MessageHeader(sun.net.www.MessageHeader)

Example 2 with MessageHeader

use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.

the class SimpleServer method run.

public void run() {
    try {
        sock = ss.accept();
        connectionCount++;
        InputStream is = sock.getInputStream();
        OutputStream os = sock.getOutputStream();
        MessageHeader headers = new MessageHeader(is);
        os.write(replyOK.getBytes("UTF-8"));
        headers = new MessageHeader(is);
        // If we get here then we received a second request.
        connectionCount++;
        os.write(replyOK.getBytes("UTF-8"));
        sock.close();
    } catch (Exception e) {
        //e.printStackTrace();
        if (sock != null && !sock.isClosed()) {
            try {
                sock.close();
            } catch (IOException ioe) {
            }
        }
    }
}
Also used : MessageHeader(sun.net.www.MessageHeader)

Example 3 with MessageHeader

use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.

the class RequestURIServer method run.

public void run() {
    try {
        Socket sock = ss.accept();
        InputStream is = sock.getInputStream();
        OutputStream os = sock.getOutputStream();
        MessageHeader headers = new MessageHeader(is);
        String requestLine = headers.getValue(0);
        int first = requestLine.indexOf(' ');
        int second = requestLine.lastIndexOf(' ');
        String URIString = requestLine.substring(first + 1, second);
        URI requestURI = new URI(URIString);
        if (requestURI.getFragment() != null)
            os.write(replyFAILED.getBytes("UTF-8"));
        else
            os.write(replyOK.getBytes("UTF-8"));
        sock.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : MessageHeader(sun.net.www.MessageHeader)

Example 4 with MessageHeader

use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.

the class NoNTLM method test.

/**
     * Test the http protocol handler with the given authentication schemes
     * in the WWW-Authenticate header.
     */
static void test(String... schemes) throws IOException {
    // the authentication scheme that the client is expected to choose
    String expected = null;
    for (String s : schemes) {
        if (expected == null) {
            expected = s;
        } else if (s.equals("Digest")) {
            expected = s;
        }
    }
    // server reply
    String reply = authReplyFor(schemes);
    System.out.println("====================================");
    System.out.println("Expect client to choose: " + expected);
    System.out.println(reply);
    try (ServerSocket ss = new ServerSocket(0)) {
        Client.start(ss.getLocalPort());
        // client <--- 401 ---- server
        try (Socket s = ss.accept()) {
            new MessageHeader().parseHeader(s.getInputStream());
            s.getOutputStream().write(reply.getBytes("US-ASCII"));
        }
        // client ---- GET ---> server
        // client <--- 200 ---- server
        String auth;
        try (Socket s = ss.accept()) {
            MessageHeader mh = new MessageHeader();
            mh.parseHeader(s.getInputStream());
            s.getOutputStream().write(OKAY.getBytes("US-ASCII"));
            auth = mh.findValue("Authorization");
        }
        // check Authorization header
        if (auth == null)
            throw new RuntimeException("Authorization header not found");
        System.out.println("Server received Authorization header: " + auth);
        String[] values = auth.split(" ");
        if (!values[0].equals(expected))
            throw new RuntimeException("Unexpected value");
    }
}
Also used : MessageHeader(sun.net.www.MessageHeader)

Example 5 with MessageHeader

use of sun.net.www.MessageHeader in project jdk8u_jdk by JetBrains.

the class HeaderCheckerProxyTunnelServer method processRequests.

/*
     * Processes the CONNECT request
     */
private void processRequests() throws IOException {
    InputStream in = clientSocket.getInputStream();
    MessageHeader mheader = new MessageHeader(in);
    String statusLine = mheader.getValue(0);
    if (statusLine.startsWith("CONNECT")) {
        // retrieve the host and port info from the status-line
        retrieveConnectInfo(statusLine);
        if (mheader.findValue("X-TestHeader") != null) {
            System.out.println("Proxy should not receive user defined headers for tunneled requests");
            failed = true;
        }
        // 6973030
        String value;
        if ((value = mheader.findValue("Proxy-Connection")) == null || !value.equals("keep-alive")) {
            System.out.println("Proxy-Connection:keep-alive not being sent");
            failed = true;
        }
        //This will allow the main thread to terminate without trying to perform the SSL handshake.
        send400();
        in.close();
        clientSocket.close();
        ss.close();
    } else {
        System.out.println("proxy server: processes only " + "CONNECT method requests, recieved: " + statusLine);
    }
}
Also used : MessageHeader(sun.net.www.MessageHeader)

Aggregations

MessageHeader (sun.net.www.MessageHeader)20 HeaderParser (sun.net.www.HeaderParser)2 MeteredStream (sun.net.www.MeteredStream)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 Iterator (java.util.Iterator)1 ProgressSource (sun.net.ProgressSource)1 FtpProtocolException (sun.net.ftp.FtpProtocolException)1