Java Code Examples for com.sun.jersey.api.client.WebResource#accept()
The following examples show how to use
com.sun.jersey.api.client.WebResource#accept() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestHandler.java From Insights with Apache License 2.0 | 6 votes |
private static Builder getRequestBuilder(String url, JsonElement requestJson, Map<String, String> headers) { Client client = Client.create(); //client.addFilter(new LoggingFilter(System.out)); WebResource resource = client.resource(url); Builder requestBuilder = resource.accept(MediaType.APPLICATION_JSON); if(headers != null && headers.size() > 0){ for(Map.Entry<String, String> entry : headers.entrySet()){ requestBuilder = requestBuilder.header(entry.getKey(), entry.getValue()); } } requestBuilder = requestBuilder.type(MediaType.APPLICATION_JSON); if(requestJson != null){ requestBuilder = requestBuilder.entity(requestJson.toString()); } return requestBuilder; }
Example 2
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 6 votes |
@Override public void ensureBucketExists() { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}") .build(region, namespace, bucketName)); wr.accept(MediaType.APPLICATION_JSON_TYPE); ClientResponse rsp = wr.head(); if (rsp.getStatus() == 404) { CreateBucketDetails createBucketDetails = CreateBucketDetails.builder().name(bucketName).compartmentId(compartmentId).build(); wr = client.resource(UriBuilder.fromPath(endpoint + "/n/{arg1}/b/").build(region, namespace)); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { byte[] bytes = objectMapper.writeValueAsBytes(createBucketDetails); wr.post(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } } else if (rsp.getStatus() != 200) { throw new RuntimeException(rsp.toString()); } }
Example 3
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 6 votes |
@Override public <T extends Timestamped> T loadObject(ObjectType objectType, String objectKey) throws NotFoundException { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build( region, namespace, bucketName, buildOSSKey(objectType.group, objectKey, objectType.defaultMetadataFilename))); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { T obj = (T) wr.get(objectType.clazz); return obj; } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 404) { throw new NotFoundException("Object not found (key: " + objectKey + ")"); } throw e; } }
Example 4
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 6 votes |
@Override public void deleteObject(ObjectType objectType, String objectKey) { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build( region, namespace, bucketName, buildOSSKey(objectType.group, objectKey, objectType.defaultMetadataFilename))); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { wr.delete(); } catch (UniformInterfaceException e) { if (e.getResponse().getStatus() == 404) { return; } throw e; } updateLastModified(objectType); }
Example 5
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 6 votes |
@Override public <T extends Timestamped> void storeObject(ObjectType objectType, String objectKey, T item) { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build( region, namespace, bucketName, buildOSSKey(objectType.group, objectKey, objectType.defaultMetadataFilename))); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { byte[] bytes = objectMapper.writeValueAsBytes(item); wr.put(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } updateLastModified(objectType); }
Example 6
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 6 votes |
@Override public Map<String, Long> listObjectKeys(ObjectType objectType) { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o") .queryParam("prefix", objectType.group) .queryParam("fields", "name,timeCreated") .build(region, namespace, bucketName)); wr.accept(MediaType.APPLICATION_JSON_TYPE); ListObjects listObjects = wr.get(ListObjects.class); Map<String, Long> results = new HashMap<>(); for (ObjectSummary summary : listObjects.getObjects()) { if (summary.getName().endsWith(objectType.defaultMetadataFilename)) { results.put( buildObjectKey(objectType, summary.getName()), summary.getTimeCreated().getTime()); } } return results; }
Example 7
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 5 votes |
@Override public long getLastModified(ObjectType objectType) { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build(region, namespace, bucketName, objectType.group + "/last-modified.json")); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { LastModified lastModified = wr.get(LastModified.class); return lastModified.getLastModified(); } catch (Exception e) { return 0L; } }
Example 8
Source File: OracleStorageService.java From front50 with Apache License 2.0 | 5 votes |
private void updateLastModified(ObjectType objectType) { WebResource wr = client.resource( UriBuilder.fromPath(endpoint + "/n/{arg1}/b/{arg2}/o/{arg3}") .build(region, namespace, bucketName, objectType.group + "/last-modified.json")); wr.accept(MediaType.APPLICATION_JSON_TYPE); try { byte[] bytes = objectMapper.writeValueAsBytes(new LastModified()); wr.put(new String(bytes, StandardCharsets.UTF_8)); } catch (IOException e) { throw new RuntimeException(e); } }
Example 9
Source File: RequestJob.java From ingestion with Apache License 2.0 | 5 votes |
/** * Set an Application Type to the request depending on a parameter and its corresponding * {@code MediaType}. * * @param webResource Current target url. * @param applicationType ApplicationType to set. * @return */ public WebResource.Builder setApplicationType(WebResource webResource, String applicationType) { if ("TEXT".equals(applicationType)) { mediaType = MediaType.TEXT_PLAIN_TYPE; } else { mediaType = MediaType.APPLICATION_JSON_TYPE; } return webResource.accept(mediaType); }