private Builder getWebResourceBuilder(URI URI, Object entity) { return client.resource(URI).type(MediaType.APPLICATION_JSON).entity(entity).accept(MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON); }
public void addCommitComment(Repository repository, Commit commit, String comment) { try { String path = String.format(COMMENT_PATH, repository.getOwner().getName(), repository.getName(), commit.getSha()); WebResource resource = client.resource(GITHUB_URL).path(path); ClientResponse response = resource.type(MediaType.APPLICATION_JSON_TYPE) .accept(MediaType.APPLICATION_JSON) .header("Authorization", authorizationHeader) .entity(new CommitComment(comment)) .post(ClientResponse.class); if (response.getStatus() < 200 || response.getStatus() >=300) { logger.warn("Commit comment failed: " + response.getClientResponseStatus().getReasonPhrase()); } } catch (UniformInterfaceException | ClientHandlerException e) { logger.warn("Comment failed", e); } }
@Test public void shouldUseXForwardedHostAndXForwardedProtoHeadersInCypherResponseRepresentations() { // when String jsonString = "{\"statements\" : [{ \"statement\": \"MATCH (n) RETURN n\", " + "\"resultDataContents\":[\"REST\"] }] }"; ClientResponse response = client.resource( getServerUri() + "db/data/transaction" ) .accept( APPLICATION_JSON ) .header( X_FORWARDED_HOST, "jimwebber.org:2354" ) .header( X_FORWARDED_PROTO, "https" ) .entity( jsonString, MediaType.APPLICATION_JSON_TYPE ) .post( ClientResponse.class ); // then String entity = response.getEntity( String.class ); assertTrue( entity.contains( "https://jimwebber.org:2354" ) ); assertFalse( entity.contains( getServerUri() ) ); }
@Override public Builder entity(Object entity, String type) { return getRequestBuilder().entity(entity, type); }
@Override public Builder entity(Object entity, MediaType type) { return getRequestBuilder().entity(entity, type); }
@Override public Builder entity(Object entity, String type) { return getRequestBuilder().entity(entity, type); }
@Override public Builder entity(Object entity) { return getRequestBuilder().entity(entity); }
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
public void executeTransaction(RecordTransactionBuilder builder) { ClientResponse response = client.resource(root) .path("update") .type(MediaType.APPLICATION_JSON_TYPE) .entity(builder.toJsonObject().toJson(), MediaType.APPLICATION_JSON_TYPE) .post(ClientResponse.class); if(response.getStatus() != 200) { throw new RuntimeException("Transaction failed with status code: " + response.getStatus() + " " + response.getEntity(String.class)); } }
@Override public Builder entity(Object entity, MediaType type) { return getRequestBuilder().entity(entity, type); }
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
private void verifySimpleAuthCreate(String mediaType, String contentType, String body) { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").queryParam("user.name", "testuser") .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); }
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertEquals(Status.OK, response.getClientResponseStatus()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
private void verifySimpleAuthCreate(String mediaType, String contentType, String body) { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").queryParam("user.name", "testuser") .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); assertEquals(Status.FORBIDDEN, response.getClientResponseStatus()); }
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
builder.entity(input.body);
public JaxRsResponse post( String path, String data, final MediaType mediaType ) { Builder builder = builder( path ); if ( data != null ) { builder = builder.entity( data, mediaType ); } else { builder = builder.type( mediaType ); } return JaxRsResponse.extractFrom( HTTP.sanityCheck( builder.post( ClientResponse.class ) ) ); }
public JaxRsResponse put( String path, String data ) { Builder builder = builder( path ); if ( data != null ) { builder = builder.entity( data, MediaType.APPLICATION_JSON_TYPE ); } return new JaxRsResponse( HTTP.sanityCheck( builder.put( ClientResponse.class ) ) ); }