Examples of ContentResponse


Examples of org.eclipse.jetty.client.api.ContentResponse

        // Assume a FastCGI server is listening on localhost:9000

        HttpClient client = new HttpClient(new HttpClientTransportOverFCGI("/var/www/php-fcgi"), null);
        client.start();

        ContentResponse response = client.newRequest("localhost", 9000)
                .path("/index.php")
                .timeout(5, TimeUnit.SECONDS)
                .send();

        Assert.assertEquals(200, response.getStatus());

        Path responseFile = Paths.get(System.getProperty("java.io.tmpdir"), "fcgi_response.html");
        Files.write(responseFile, response.getContent(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

                Assert.assertEquals(forwardPath, req.getRequestURI());
                Assert.assertTrue(req.getQueryString().endsWith(path));
            }
        });

        ContentResponse response = client.newRequest("localhost", sslConnector.getLocalPort())
                .scheme("https")
                .path(path)
                .send();

        Assert.assertEquals(200, response.getStatus());
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

                if (req.getHeader("Via") != null)
                    resp.addHeader(PROXIED_HEADER, "true");
            }
        });

        ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
                .timeout(5, TimeUnit.SECONDS)
                .send();

        Assert.assertEquals("OK", response.getReason());
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

            }
        });

        byte[] content = new byte[1024];
        new Random().nextBytes(content);
        ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
                .method(HttpMethod.POST)
                .content(new BytesContentProvider(content))
                .timeout(5, TimeUnit.SECONDS)
                .send();

        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
        Assert.assertArrayEquals(content, response.getContent());
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

                    resp.addHeader(PROXIED_HEADER, "true");
            }
        });

        byte[] content = new byte[128 * 1024];
        ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
                .method(HttpMethod.POST)
                .content(new BytesContentProvider(content))
                .timeout(5, TimeUnit.SECONDS)
                .send();

        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

                    ++index;
                }
            }
        });

        ContentResponse response = client.newRequest("localhost", serverConnector.getLocalPort())
                .method(HttpMethod.POST)
                .content(new BytesContentProvider(content))
                .timeout(5, TimeUnit.SECONDS)
                .send();

        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getHeaders().containsKey(PROXIED_HEADER));
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

            {
                resp.getOutputStream().print(req.getQueryString());
            }
        });

        ContentResponse response = client.newRequest("http://localhost:" + serverConnector.getLocalPort() + "/?" + query)
                .timeout(5, TimeUnit.SECONDS)
                .send();
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals(query, response.getContentAsString());
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

                writer.write(req.getHeader("X-Forwarded-Host"));
                writer.flush();
            }
        });

        ContentResponse response = client.GET("http://localhost:" + serverConnector.getLocalPort());
        Assert.assertThat("Response expected to contain content of X-Forwarded-Host Header from the request",
                response.getContentAsString(),
                Matchers.equalTo("localhost:" + serverConnector.getLocalPort()));
    }
View Full Code Here

Examples of org.eclipse.jetty.client.api.ContentResponse

        prepareServer(new EmptyHttpServlet());
        int port = serverConnector.getLocalPort();
        proxyServlet.getWhiteListHosts().add("127.0.0.1:" + port);

        // Try with the wrong host
        ContentResponse response = client.newRequest("localhost", port)
                .timeout(5, TimeUnit.SECONDS)
                .send();
        Assert.assertEquals(403, response.getStatus());

        // Try again with the right host
        response = client.newRequest("127.0.0.1", port)
                .timeout(5, TimeUnit.SECONDS)
                .send();
        Assert.assertEquals(200, response.getStatus());
    }
View Full Code Here

Examples of org.gatein.pc.api.invocation.response.ContentResponse

                    charset = null;
                    transportHeaders = null;
                    content = null;
                } else {
                    //
                    ContentResponse piResponse = (ContentResponse) portletResponse;
                    ResponseProperties properties = piResponse.getProperties();
                    transportHeaders = properties != null ? properties.getTransportHeaders() : null;

                    // Look at status code if there is one and honour it
                    String status = transportHeaders != null ? transportHeaders.getValue(ResourceResponse.HTTP_STATUS_CODE)
                            : null;
                    if (status != null) {
                        try {
                            statusCode = Integer.parseInt(status);
                        } catch (NumberFormatException e) {
                            statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                        }
                    } else {
                        statusCode = HttpServletResponse.SC_OK;
                    }

                    //
                    contentType = piResponse.getContentType();
                    charset = piResponse.getEncoding();

                    //
                    log.trace("Try to get a resource of type: " + contentType + " for the portlet: "
                            + uiPortlet.getId());
                    if (piResponse.getChars() != null) {
                        content = piResponse.getChars();
                    } else if (piResponse.getBytes() != null) {
                        content = piResponse.getBytes();
                    } else {
                        content = null;
                    }
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.