use of javax.ws.rs.client.Client in project jersey by jersey.
the class ConstrainedToTest method testClientWithProviderInstances.
@Test
public void testClientWithProviderInstances() {
Client client = ClientBuilder.newClient(new ClientConfig(new ClientFilterConstrainedToServer(), new ClientFilterConstrainedToClient(), new ClientFilter()));
_testFilters(client);
}
use of javax.ws.rs.client.Client in project javaee7-samples by javaee-samples.
the class TestServlet method processRequest.
/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet TestServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet TestServlet at " + request.getContextPath() + "</h1>");
Client client = ClientBuilder.newClient();
client.register(ClientLoggingFilter.class).register(MyClientReaderInterceptor.class).register(MyClientWriterInterceptor.class);
WebTarget target = client.target("http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/webresources/fruits");
out.println(target.getUri() + "<br><br>");
out.println("GET request" + "<br><br>");
String result = target.request().get(String.class);
out.println("Received response (GET): " + result + "<br><br>");
System.out.println("**** POST request");
result = target.request().post(Entity.text("1"), String.class);
out.println("Received response (POST): " + result + "<br><br>");
out.println("Received response: " + result + "<br><br>");
out.println("<br><br>Check server log for client/server filter output, prints headers and entity body.");
out.println("</body>");
out.println("</html>");
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class MyResourceTest method setUp.
@Before
public void setUp() throws Exception {
// start the server
server = Main.startServer();
// create the client
Client c = ClientBuilder.newClient();
// uncomment the following line if you want to enable
// support for JSON in the client (you also have to uncomment
// dependency on jersey-media-json module in pom.xml and Main.startServer())
// --
// c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
target = c.target(Main.BASE_URI);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class AuthTest method testAuthPostWithClientFilter.
@Test
public void testAuthPostWithClientFilter() {
ClientConfig cc = new ClientConfig();
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
client.register(HttpAuthenticationFeature.basic("name", "password"));
WebTarget r = client.target(getBaseUri()).path("test/filter");
assertEquals("POST", r.request().post(Entity.text("POST"), String.class));
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method testLoggingFilterClientClass.
@Test
public void testLoggingFilterClientClass() {
Client client = client();
client.register(CustomLoggingFilter.class).property("foo", "bar");
CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
String s = target().path(ROOT_PATH).request().get(String.class);
assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
assertEquals(1, CustomLoggingFilter.preFilterCalled);
assertEquals(1, CustomLoggingFilter.postFilterCalled);
}
Aggregations