Search in sources :

Example 66 with LinkedHashMap

use of java.util.LinkedHashMap in project okhttp by square.

the class JavaApiConverterTest method createOkRequest_nonNullRequestHeaders.

@Test
public void createOkRequest_nonNullRequestHeaders() throws Exception {
    URI uri = new URI("https://foo/bar");
    Map<String, List<String>> javaRequestHeaders = new LinkedHashMap<>();
    javaRequestHeaders.put("Foo", Arrays.asList("Bar"));
    Request request = JavaApiConverter.createOkRequest(uri, "POST", javaRequestHeaders);
    assertTrue(request.isHttps());
    assertEquals(uri, request.url().uri());
    Headers okRequestHeaders = request.headers();
    assertEquals(1, okRequestHeaders.size());
    assertEquals("Bar", okRequestHeaders.get("Foo"));
    assertEquals("POST", request.method());
}
Also used : Headers(okhttp3.Headers) Request(okhttp3.Request) List(java.util.List) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 67 with LinkedHashMap

use of java.util.LinkedHashMap in project okhttp by square.

the class JavaApiConverterTest method createOkResponseForCacheGet_secure.

@Test
public void createOkResponseForCacheGet_secure() throws Exception {
    final String statusLine = "HTTP/1.1 200 Fantastic";
    final Principal localPrincipal = LOCAL_CERT.getSubjectX500Principal();
    final List<Certificate> localCertificates = Arrays.<Certificate>asList(LOCAL_CERT);
    final Principal serverPrincipal = SERVER_CERT.getSubjectX500Principal();
    final List<Certificate> serverCertificates = Arrays.<Certificate>asList(SERVER_CERT);
    URI uri = new URI("https://foo/bar");
    Request request = new Request.Builder().url(uri.toURL()).build();
    SecureCacheResponse cacheResponse = new SecureCacheResponse() {

        @Override
        public Map<String, List<String>> getHeaders() throws IOException {
            Map<String, List<String>> headers = new LinkedHashMap<>();
            headers.put(null, Collections.singletonList(statusLine));
            headers.put("xyzzy", Arrays.asList("bar", "baz"));
            return headers;
        }

        @Override
        public InputStream getBody() throws IOException {
            return new ByteArrayInputStream("HelloWorld".getBytes(StandardCharsets.UTF_8));
        }

        @Override
        public String getCipherSuite() {
            return "SSL_RSA_WITH_NULL_MD5";
        }

        @Override
        public List<Certificate> getLocalCertificateChain() {
            return localCertificates;
        }

        @Override
        public List<Certificate> getServerCertificateChain() throws SSLPeerUnverifiedException {
            return serverCertificates;
        }

        @Override
        public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
            return serverPrincipal;
        }

        @Override
        public Principal getLocalPrincipal() {
            return localPrincipal;
        }
    };
    Response response = JavaApiConverter.createOkResponseForCacheGet(request, cacheResponse);
    Request cacheRequest = response.request();
    assertEquals(request.url(), cacheRequest.url());
    assertEquals(request.method(), cacheRequest.method());
    assertEquals(0, request.headers().size());
    assertEquals(Protocol.HTTP_1_1, response.protocol());
    assertEquals(200, response.code());
    assertEquals("Fantastic", response.message());
    Headers okResponseHeaders = response.headers();
    assertEquals("baz", okResponseHeaders.get("xyzzy"));
    assertEquals("HelloWorld", response.body().string());
    Handshake handshake = response.handshake();
    assertNotNull(handshake);
    assertNotNullAndEquals(CipherSuite.TLS_RSA_WITH_NULL_MD5, handshake.cipherSuite());
    assertEquals(localPrincipal, handshake.localPrincipal());
    assertEquals(serverPrincipal, handshake.peerPrincipal());
    assertEquals(serverCertificates, handshake.peerCertificates());
    assertEquals(localCertificates, handshake.localCertificates());
}
Also used : SecureCacheResponse(java.net.SecureCacheResponse) Headers(okhttp3.Headers) Request(okhttp3.Request) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) CacheResponse(java.net.CacheResponse) Response(okhttp3.Response) SecureCacheResponse(java.net.SecureCacheResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) List(java.util.List) Principal(java.security.Principal) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate) Handshake(okhttp3.Handshake) Test(org.junit.Test)

Example 68 with LinkedHashMap

use of java.util.LinkedHashMap in project okhttp by square.

the class JavaApiConverterTest method createOkResponseForCacheGet_withMissingStatusLine.

/** Test for https://code.google.com/p/android/issues/detail?id=160522 */
@Test
public void createOkResponseForCacheGet_withMissingStatusLine() throws Exception {
    URI uri = new URI("http://foo/bar");
    Request request = new Request.Builder().url(uri.toURL()).build();
    CacheResponse cacheResponse = new CacheResponse() {

        @Override
        public Map<String, List<String>> getHeaders() throws IOException {
            Map<String, List<String>> headers = new LinkedHashMap<>();
            // Headers is deliberately missing an entry with a null key.
            headers.put("xyzzy", Arrays.asList("bar", "baz"));
            return headers;
        }

        @Override
        public InputStream getBody() throws IOException {
            // Should never be called
            return null;
        }
    };
    try {
        JavaApiConverter.createOkResponseForCacheGet(request, cacheResponse);
        fail();
    } catch (IOException expected) {
    }
}
Also used : CacheResponse(java.net.CacheResponse) SecureCacheResponse(java.net.SecureCacheResponse) Request(okhttp3.Request) List(java.util.List) IOException(java.io.IOException) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 69 with LinkedHashMap

use of java.util.LinkedHashMap in project okhttp by square.

the class JavaApiConverterTest method createOkResponseForCacheGet.

@Test
public void createOkResponseForCacheGet() throws Exception {
    final String statusLine = "HTTP/1.1 200 Fantastic";
    URI uri = new URI("http://foo/bar");
    Request request = new Request.Builder().url(uri.toURL()).build();
    CacheResponse cacheResponse = new CacheResponse() {

        @Override
        public Map<String, List<String>> getHeaders() throws IOException {
            Map<String, List<String>> headers = new LinkedHashMap<>();
            headers.put(null, Collections.singletonList(statusLine));
            headers.put("xyzzy", Arrays.asList("bar", "baz"));
            return headers;
        }

        @Override
        public InputStream getBody() throws IOException {
            return new ByteArrayInputStream("HelloWorld".getBytes(StandardCharsets.UTF_8));
        }
    };
    Response response = JavaApiConverter.createOkResponseForCacheGet(request, cacheResponse);
    Request cacheRequest = response.request();
    assertEquals(request.url(), cacheRequest.url());
    assertEquals(request.method(), cacheRequest.method());
    assertEquals(0, request.headers().size());
    assertEquals(Protocol.HTTP_1_1, response.protocol());
    assertEquals(200, response.code());
    assertEquals("Fantastic", response.message());
    Headers okResponseHeaders = response.headers();
    assertEquals("baz", okResponseHeaders.get("xyzzy"));
    assertEquals("HelloWorld", response.body().string());
    assertNull(response.handshake());
}
Also used : CacheResponse(java.net.CacheResponse) Response(okhttp3.Response) SecureCacheResponse(java.net.SecureCacheResponse) CacheResponse(java.net.CacheResponse) SecureCacheResponse(java.net.SecureCacheResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) Headers(okhttp3.Headers) Request(okhttp3.Request) List(java.util.List) URI(java.net.URI) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 70 with LinkedHashMap

use of java.util.LinkedHashMap in project CoreNLP by stanfordnlp.

the class CoreNLPServlet method outputVisualise.

public void outputVisualise(PrintWriter out, Annotation annotation) throws ServletException, IOException {
    // Note: A lot of the HTML generation in this method could/should be
    // done at a templating level, but as-of-yet I am not entirely sure how
    // this should be done in jsp. Also, a lot of the HTML is unnecessary
    // for the other outputs such as pretty print and XML.
    // Div for potential error messages when fetching the configuration.
    out.println("<div id=\"config_error\">");
    out.println("</div>");
    // Insert divs that will be used for each visualisation type.
    final int visualiserDivPxWidth = 700;
    Map<String, String> nameByAbbrv = new LinkedHashMap<>();
    nameByAbbrv.put("pos", "Part-of-Speech");
    nameByAbbrv.put("ner", "Named Entity Recognition");
    nameByAbbrv.put("coref", "Coreference");
    nameByAbbrv.put("basic_dep", "Basic Dependencies");
    //nameByAbbrv.put("collapsed_dep", "Collapsed dependencies");
    nameByAbbrv.put("collapsed_ccproc_dep", "Enhanced Dependencies");
    for (Map.Entry<String, String> entry : nameByAbbrv.entrySet()) {
        out.println("<h2>" + entry.getValue() + ":</h2>");
        out.println("<div id=\"" + entry.getKey() + "\" style=\"width:" + visualiserDivPxWidth + "px\">");
        out.println("    <div id=\"" + entry.getKey() + "_loading\">");
        out.println("        <p>Loading...</p>");
        out.println("    </div>");
        out.println("</div>");
        out.println("");
    }
    // Time to get the XML data into HTML.
    StringWriter xmlOutput = new StringWriter();
    pipeline.xmlPrint(annotation, xmlOutput);
    xmlOutput.flush();
    // Escape the XML to be embeddable into a Javascript string.
    String escapedXml = xmlOutput.toString().replaceAll("\\r\\n|\\r|\\n", "").replace("\"", "\\\"");
    // Inject the XML results into the HTML to be retrieved by the Javascript.
    out.println("<script type=\"text/javascript\">");
    out.println("// <![CDATA[");
    out.println("    stanfordXML = \"" + escapedXml + "\";");
    out.println("// ]]>");
    out.println("</script>");
    // Relative brat installation location to CoreNLP.
    final String bratLocation = "../brat";
    // Inject the location variable, we need it in Javascript mode.
    out.println("<script type=\"text/javascript\">");
    out.println("// <![CDATA[");
    out.println("    bratLocation = \"" + bratLocation + "\";");
    out.println("    webFontURLs = [\n" + "        '" + bratLocation + "/static/fonts/Astloch-Bold.ttf',\n" + "        '" + bratLocation + "/static/fonts/PT_Sans-Caption-Web-Regular.ttf',\n" + "        '" + bratLocation + "/static/fonts/Liberation_Sans-Regular.ttf'];");
    out.println("// ]]>");
    out.println("</script>");
    // Inject the brat stylesheet (removing this line breaks visualisation).
    out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + bratLocation + "/style-vis.css\"/>");
    // Include the Javascript libraries necessary to run brat.
    out.println("<script type=\"text/javascript\" src=\"" + bratLocation + "/client/lib/head.load.min.js\"></script>");
    // Main Javascript that hooks into all that we have introduced so far.
    out.println("<script type=\"text/javascript\" src=\"brat.js\"></script>");
    // Link to brat, I hope this is okay to have here...
    out.println("<h>Visualisation provided using the " + "<a href=\"http://brat.nlplab.org/\">brat " + "visualisation/annotation software</a>.</h>");
    out.println("<br/>");
}
Also used : StringWriter(java.io.StringWriter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)2398 Map (java.util.Map)691 ArrayList (java.util.ArrayList)675 HashMap (java.util.HashMap)439 Test (org.junit.Test)317 List (java.util.List)298 IOException (java.io.IOException)152 HashSet (java.util.HashSet)128 Set (java.util.Set)110 LinkedHashSet (java.util.LinkedHashSet)100 File (java.io.File)93 LinkedList (java.util.LinkedList)75 TreeMap (java.util.TreeMap)72 Node (org.apache.hadoop.hive.ql.lib.Node)70 NodeProcessor (org.apache.hadoop.hive.ql.lib.NodeProcessor)68 Rule (org.apache.hadoop.hive.ql.lib.Rule)68 GraphWalker (org.apache.hadoop.hive.ql.lib.GraphWalker)66 Dispatcher (org.apache.hadoop.hive.ql.lib.Dispatcher)65 Iterator (java.util.Iterator)64 DefaultRuleDispatcher (org.apache.hadoop.hive.ql.lib.DefaultRuleDispatcher)64