use of javax.ws.rs.client.Client in project jersey by jersey.
the class AuthTest method testAuthDelete.
@Test
public void testAuthDelete() {
ClientConfig config = new ClientConfig();
config.property(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, new BasicAuthentication(getBaseUri(), "WallyWorld", "name", "password"));
config.connectorProvider(new JettyConnectorProvider());
Client client = ClientBuilder.newClient(config);
Response response = client.target(getBaseUri()).path(PATH).request().delete();
assertEquals(response.getStatus(), 204);
client.close();
}
use of javax.ws.rs.client.Client in project eureka by Netflix.
the class Jersey2ReplicationClient method createReplicationClient.
public static Jersey2ReplicationClient createReplicationClient(EurekaServerConfig config, ServerCodecs serverCodecs, String serviceUrl) {
String name = Jersey2ReplicationClient.class.getSimpleName() + ": " + serviceUrl + "apps/: ";
EurekaJersey2Client jerseyClient;
try {
String hostname;
try {
hostname = new URL(serviceUrl).getHost();
} catch (MalformedURLException e) {
hostname = serviceUrl;
}
String jerseyClientName = "Discovery-PeerNodeClient-" + hostname;
EurekaJersey2ClientImpl.EurekaJersey2ClientBuilder clientBuilder = new EurekaJersey2ClientImpl.EurekaJersey2ClientBuilder().withClientName(jerseyClientName).withUserAgent("Java-EurekaClient-Replication").withEncoderWrapper(serverCodecs.getFullJsonCodec()).withDecoderWrapper(serverCodecs.getFullJsonCodec()).withConnectionTimeout(config.getPeerNodeConnectTimeoutMs()).withReadTimeout(config.getPeerNodeReadTimeoutMs()).withMaxConnectionsPerHost(config.getPeerNodeTotalConnectionsPerHost()).withMaxTotalConnections(config.getPeerNodeTotalConnections()).withConnectionIdleTimeout(config.getPeerNodeConnectionIdleTimeoutSeconds());
if (serviceUrl.startsWith("https://") && "true".equals(System.getProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory"))) {
clientBuilder.withSystemSSLConfiguration();
}
jerseyClient = clientBuilder.build();
} catch (Throwable e) {
throw new RuntimeException("Cannot Create new Replica Node :" + name, e);
}
String ip = null;
try {
ip = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
logger.warn("Cannot find localhost ip", e);
}
Client jerseyApacheClient = jerseyClient.getClient();
jerseyApacheClient.register(new Jersey2DynamicGZIPContentEncodingFilter(config));
EurekaServerIdentity identity = new EurekaServerIdentity(ip);
jerseyApacheClient.register(new EurekaIdentityHeaderFilter(identity));
return new Jersey2ReplicationClient(jerseyClient, serviceUrl);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ExtendedWadlWebappOsgiTest method testWadlOptionsMethod.
@Test
public void testWadlOptionsMethod() throws Exception {
// TODO - temporary workaround
// This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
// class loader set
ClassLoader myClassLoader = this.getClass().getClassLoader();
for (Bundle bundle : bundleContext.getBundles()) {
if ("webapp".equals(bundle.getSymbolicName())) {
myClassLoader = bundle.loadClass("org.glassfish.jersey.examples.extendedwadl.resources.MyApplication").getClassLoader();
break;
}
}
Thread.currentThread().setContextClassLoader(myClassLoader);
// END of workaround; The entire block can be removed after grizzly is migrated to more recent version
final ResourceConfig resourceConfig = createResourceConfig();
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final Client client = ClientBuilder.newClient();
String wadl = client.target(baseUri).path("items").queryParam(WadlUtils.DETAILED_WADL_QUERY_PARAM, "true").request(MediaTypes.WADL_TYPE).options(String.class);
assertTrue("Generated wadl is of null length", !wadl.isEmpty());
assertTrue("Generated wadl doesn't contain the expected text", wadl.contains("This is a paragraph"));
checkWadl(wadl, baseUri);
server.shutdownNow();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class ExtendedWadlWebappOsgiTest method testExtendedWadl.
/**
* Test checks that the WADL generated using the WadlGenerator api doesn't
* contain the expected text.
*
* @throws java.lang.Exception in case of a test error.
*/
@Test
public void testExtendedWadl() throws Exception {
// TODO - temporary workaround
// This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
// class loader set
ClassLoader myClassLoader = this.getClass().getClassLoader();
for (Bundle bundle : bundleContext.getBundles()) {
if ("webapp".equals(bundle.getSymbolicName())) {
myClassLoader = bundle.loadClass("org.glassfish.jersey.examples.extendedwadl.resources.MyApplication").getClassLoader();
break;
}
}
Thread.currentThread().setContextClassLoader(myClassLoader);
// END of workaround - the entire block can be deleted after grizzly is updated to recent version
// List all the OSGi bundles
StringBuilder sb = new StringBuilder();
sb.append("-- Bundle list -- \n");
for (Bundle b : bundleContext.getBundles()) {
sb.append(String.format("%1$5s", "[" + b.getBundleId() + "]")).append(" ").append(String.format("%1$-70s", b.getSymbolicName())).append(" | ").append(String.format("%1$-20s", b.getVersion())).append(" |");
try {
b.start();
sb.append(" STARTED | ");
} catch (BundleException e) {
sb.append(" *FAILED* | ").append(e.getMessage());
}
sb.append(b.getLocation()).append("\n");
}
sb.append("-- \n\n");
LOGGER.fine(sb.toString());
final ResourceConfig resourceConfig = createResourceConfig();
final HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
final Client client = ClientBuilder.newClient();
final Response response = client.target(baseUri).path("application.wadl").request(MediaTypes.WADL_TYPE).buildGet().invoke();
String wadl = response.readEntity(String.class);
LOGGER.info("RESULT = " + wadl);
assertTrue("Generated wadl is of null length", !wadl.isEmpty());
assertTrue("Generated wadl doesn't contain the expected text", wadl.contains("This is a paragraph"));
assertFalse(wadl.contains("application.wadl/xsd0.xsd"));
server.shutdownNow();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method testLoggingFilterClientInstance.
@Test
@RunSeparately
public void testLoggingFilterClientInstance() {
Client client = client();
client.register(new CustomLoggingFilter()).property("foo", "bar");
CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
String s = target().path(App.ROOT_PATH).request().get(String.class);
assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
assertEquals(1, CustomLoggingFilter.preFilterCalled);
assertEquals(1, CustomLoggingFilter.postFilterCalled);
}
Aggregations