clientConfig = new DefaultClientConfig(); client = Client.create(clientConfig); resource = client.resource("http://localhost:8080"); // lets get the XML as a String String text = resource("foo").accept("application/xml").get(String.class);
/** * Creates a default task client */ public WorkflowClient() { this(new DefaultClientConfig(), new DefaultConductorClientConfiguration(), null); }
/** * Creates a default task client */ public TaskClient() { this(new DefaultClientConfig(), new DefaultConductorClientConfiguration(), null); }
/** * Creates a default metadata client */ public MetadataClient() { this(new DefaultClientConfig(), new DefaultConductorClientConfiguration(), null); }
private ClientConfig getClientConfig() { ClientConfig config = new DefaultClientConfig(); config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE); return config; }
protected ClientBase() { this(new DefaultClientConfig(), new DefaultConductorClientConfiguration(), null); }
ClientConfig cfg = new DefaultClientConfig(); cfg.getClasses().add(JacksonJsonProvider.class); Client client = Client.create(cfg);
/** * Create a new Client instance * */ public static com.sun.jersey.api.client.Client createClient() { ClientConfig cc = new DefaultClientConfig(); customizeClientConfiguration( cc ); return createClientInstance( cc ); }
@Override public Object call() throws Exception { ClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, password ) ); Class<?>[] parameterTypes = new Class<?>[] { Client.class, URI.class }; String factoryClassName = webServiceSpecification.getServiceClass().getName(); factoryClassName = factoryClassName.substring( 0, factoryClassName.lastIndexOf( "$" ) ); Class<?> factoryClass = Class.forName( factoryClassName ); Method method = factoryClass.getDeclaredMethod( webServiceSpecification.getServiceName(), parameterTypes ); T port = (T) method.invoke( null, new Object[] { client, new URI( baseUrl + "/plugin" ) } ); return port; } } );
HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); ClientConfig config = new DefaultClientConfig(); SSLContext ctx = SSLContext.getInstance("SSL"); ctx.init(null, myTrustManager, null); config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(hostnameVerifier, ctx)); Client client = Client.create(config);
public class Test { public static void main(String[] args) { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); WebResource service = client.resource(getBaseURI()); // Now do the MAP stuff MyHashMapObject<String, String> map = new MyHashMapObject<String, String>(); map.getMapProperty().put("a", "1"); map.getMapProperty().put("b", "2"); ClientResponse response = service.path("rest").path("hello2") .type(MediaType.APPLICATION_XML) .accept(MediaType.APPLICATION_XML) .post(ClientResponse.class, map); Map<String, String> myMap = response.getEntity(MyHashMapObject.class).getMapProperty(); for(Map.Entry<String, String> entry : myMap.entrySet()) System.out.format("Key: %s, Value: %s\n", entry.getKey(), entry.getValue()); } private static URI getBaseURI() { return UriBuilder.fromUri( "http://localhost:8080/org.nowaq.jersey.first").build(); } }
/** * Use REST API to authenticate provided credentials * * @throws Exception */ @VisibleForTesting void authenticateLoginCredentials() throws Exception { KettleClientEnvironment.init(); if ( client == null ) { ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); client = Client.create( clientConfig ); client.addFilter( new HTTPBasicAuthFilter( username, Encr.decryptPasswordOptionallyEncrypted( password ) ) ); } WebResource resource = client.resource( url + AUTHENTICATION + AdministerSecurityAction.NAME ); String response = resource.get( String.class ); if ( !response.equals( "true" ) ) { throw new Exception( Messages.getInstance().getString( "REPOSITORY_CLEANUP_UTIL.ERROR_0012.ACCESS_DENIED" ) ); } }
DefaultClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create( clientConfig ); WebResource resource = client.resource( endpoint ).path( "/status" );
private String getIp(String host, String token) throws ParseException { ClientConfig config = new DefaultClientConfig(); Client client = Client.create(config); String baseURI = getBaseURI(host);
DefaultClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create( clientConfig ); WebResource resource = client.resource( endpoint ).path( "/destroy" );
DefaultClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create( clientConfig ); WebResource resource = client.resource( endpoint ).path( "/reset" );
DefaultClientConfig clientConfig = new DefaultClientConfig(); Client client = Client.create( clientConfig ); WebResource resource = client.resource( endpoint ).path( "/stop" );
private static Client createClient() throws Exception { HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); ClientConfig config = new DefaultClientConfig(); SSLContext ctx = SSLContext.getInstance( "TLS" ); ctx.init( null, new TrustManager[]{new InsecureTrustManager()}, null ); config.getProperties().put( PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( hostnameVerifier, ctx ) ); return Client.create( config ); } }
/** * Create a Jersey HTTP client that is able to talk HTTPS and trusts all certificates. * * @return new client. */ private static Client createClient() { try { HostnameVerifier hostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier(); ClientConfig config = new DefaultClientConfig(); SSLContext ctx = SSLContext.getInstance( "TLS" ); ctx.init( null, new TrustManager[]{new InsecureTrustManager()}, null ); Map<String,Object> properties = config.getProperties(); properties.put( PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( hostnameVerifier, ctx ) ); properties.put( PROPERTY_FOLLOW_REDIRECTS, false ); return Client.create( config ); } catch ( Exception e ) { throw new RuntimeException( e ); } }
KettleClientEnvironment.init(); ClientConfig clientConfig = new DefaultClientConfig(); clientConfig.getFeatures().put( JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE ); Client client = Client.create( clientConfig );