Refine search
protected VerifyTokenResponse getVerifyTokenResponse(String accessToken) { VerifyTokenResponse verifyTokenResponse = null; if (cacheAccessTokens()) { verifyTokenResponse = cache.getVerifyToken(accessToken); if (verifyTokenResponse != null) { return verifyTokenResponse; } } if (verifyTokenResponse == null) { ClientResponse res = client.resource(String.format("%s?access_token=%s", authorizationServerUrl, accessToken)) .header(HttpHeaders.AUTHORIZATION, "Basic " + authorizationValue).accept("application/json") .get(ClientResponse.class); try { String responseString = res.getEntity(String.class); int statusCode = res.getClientResponseStatus().getStatusCode(); LOG.debug("Got verify token response (status: {}): '{}'", statusCode, responseString); if (statusCode == HttpServletResponse.SC_OK) { verifyTokenResponse = objectMapper.readValue(responseString, VerifyTokenResponse.class); } } catch (Exception e) { LOG.error("Exception in reading result from AuthorizationServer", e); // anti-pattern, but null case is explicitly handled } } if (isValidResponse(verifyTokenResponse) && cacheAccessTokens()) { cache.storeVerifyToken(accessToken, verifyTokenResponse); } return verifyTokenResponse; }
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); } }
if (ClientResponse.Status.NOT_FOUND.equals(e.getStatus())){ getLogger().debug("Existing flow was not found for {}@{}", new Object[]{rootProcessGroup.getId(), clusterName}); } else {
@Override public <T> T getEntity(Class<T> returnType) { if(response.getStatus() >= 400) { throw new OpenStackResponseException(response.getClientResponseStatus().getReasonPhrase(), response.getStatus()); } if(response.hasEntity() && returnType != null && Void.class != returnType) { return response.getEntity(returnType); } else { return null; } }
public AtlasServiceException(AtlasBaseClient.API api, ClientResponse response) { this(api, ClientResponse.Status.fromStatusCode(response.getStatus()), response.getEntity(String.class)); }
throw new ApiException(500, "unknown method type " + method); if (response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) { throw new ApiException(500, "No contents found"); } else if (response.getClientResponseStatus().getFamily() == Family.SUCCESSFUL) { if (response.getEntityInputStream() != null) { aiResponse.setInputStream(response.getEntityInputStream()); } else { } else { throw new ApiException( response.getClientResponseStatus().getStatusCode(), response.getEntity(String.class));
commonServices.drillHostname, commonServices.drillPort); if (response != null && response.getStatus() != 200) { LOG.info("Error in Drill: " + response.getStatus()); return Futures .immediateFailedCheckedFuture(new TransactionCommitFailedException( ErrorType.APPLICATION, "Error connecting drill", response .getClientResponseStatus() .toString())));
/** * Adds an Organization (account) to those managed by the DVCS Connector. */ @Nonnull public Organization addOrganizationForApprovedAccount(@Nonnull final String accountName, @Nonnull final String dvcsType, @Nonnull final String oauthKey, @Nonnull final String oauthSecret, @Nonnull final String hostUrl, final boolean autosync, final boolean smartcommitsOnNewRepos) { Organization organization = new Organization(NON_EXISTING_ORG_ID, hostUrl, accountName, dvcsType, autosync, CredentialFactory.create2LOCredential(oauthKey, oauthSecret), null, smartcommitsOnNewRepos, Collections.emptySet()); organization = createResource().path("organization").type(MediaType.APPLICATION_JSON_TYPE).post(Organization.class, organization); final ClientResponse response = createResource() .path("organization") .path("" + organization.getId()) .path("credential") .type(MediaType.APPLICATION_JSON_TYPE) .post(ClientResponse.class, ImmutableMap.of("key", oauthKey, "secret", oauthSecret)); switch (fromStatusCode(response.getStatus())) { case OK: return organization; default: throw new IllegalStateException("Unexpected response status actual: " + response.getStatus() + ", expected: " + OK.getStatusCode()); } }
@Test public void testAllowNonBrowserInteractionWithoutHeader() throws Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster") .path("info").accept("application/xml") .get(ClientResponse.class); assertTrue("Should have been accepted", response.getStatus() == Status.OK.getStatusCode()); assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString()); String xml = response.getEntity(String.class); verifyClusterInfoXML(xml); }
statusCode = response.getStatusInfo().getStatusCode(); responseHeaders = response.getHeaders(); if(response.getStatusInfo().getStatusCode() == ClientResponse.Status.NO_CONTENT.getStatusCode()) { return null; } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
private String negotiate(UniformInterfaceException u) { return negotiateHandler.negotiate(supportedContentType, u.getResponse().getHeaders(), u.getResponse().getStatus(), u.getResponse().getClientResponseStatus().getReasonPhrase()); }
private void handleException(Exception ex, String msg, boolean resourceNotFoundExpected) { final ClientResponse.Status status = ex instanceof UniformInterfaceException ? ((UniformInterfaceException)ex).getResponse().getClientResponseStatus() : null; if (status == NOT_FOUND && resourceNotFoundExpected || status == CONFLICT) { logger.debug(msg, ex); } else if (returnNoneOnExceptions) { if (status != null && status.getFamily() == Response.Status.Family.CLIENT_ERROR) { logger.info(msg, ex); } else { logger.error(msg, ex); } } else { throw ex instanceof RuntimeException ? (RuntimeException)ex : new RuntimeException(msg, ex); } }
private void logErrorMessage(ClientResponse response) throws IOException { LOG.error("Response status={}", response.getClientResponseStatus().toString()); LineIterator it = null; try { it = IOUtils.lineIterator(response.getEntityInputStream(), UTF8); while (it.hasNext()) { String line = it.nextLine(); LOG.error(line); } } finally { if (it != null) { it.close(); } } }
private static void verifyHttpResponse(Client client, URI uri, Status expectedStatus) { ClientResponse resp = client.resource(uri).accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(resp); assertEquals(resp.getStatusInfo().getStatusCode(), expectedStatus.getStatusCode()); }
@Test public void shouldAddCorsRequestHeaders() throws Exception { startServer( false ); HTTP.Builder requestBuilder = requestWithHeaders( "authDisabled", "authDisabled" ) .withHeaders( ACCESS_CONTROL_REQUEST_HEADERS, "Accept, X-Not-Accept" ); HTTP.Response response = runQuery( requestBuilder ); assertEquals( OK.getStatusCode(), response.status() ); assertCorsHeaderPresent( response ); assertEquals( "Accept, X-Not-Accept", response.header( ACCESS_CONTROL_ALLOW_HEADERS ) ); }
/** * Set the expected status of the response. The test will fail if the * response has a different status. Defaults to HTTP 200 OK. * * @param expectedStatus the expected response status */ public RESTRequestGenerator expectedStatus( final ClientResponse.Status expectedStatus ) { this.expectedResponseStatus = expectedStatus.getStatusCode(); return this; }
@Test public void shouldAddCorsHeaderWhenAuthEnabledAndIncorrectPassword() throws Exception { startServer( true ); HTTP.Response response = runQuery( "neo4j", "wrongPassword" ); assertEquals( UNAUTHORIZED.getStatusCode(), response.status() ); assertCorsHeaderPresent( response ); assertThat( response.content().toString(), containsString( "Neo.ClientError.Security.Unauthorized" ) ); }
private void testCorsAllowMethods( HttpMethod method, String origin ) throws Exception { HTTP.Builder requestBuilder = requestWithHeaders( "authDisabled", "authDisabled" ) .withHeaders( ACCESS_CONTROL_REQUEST_METHOD, method.toString() ); HTTP.Response response = runQuery( requestBuilder ); assertEquals( OK.getStatusCode(), response.status() ); assertCorsHeaderEquals( response, origin ); assertEquals( method, HttpMethod.valueOf( response.header( ACCESS_CONTROL_ALLOW_METHODS ) ) ); }
@Test @Graph( "Joe knows Sara" ) public void creating_a_relationship_to_a_nonexisting_end_node() { String jsonString = "{\"to\" : \"" + getDataUri() + "node/" + "999999\", \"type\" : \"LOVES\", \"data\" : {\"foo\" : \"bar\"}}"; gen.get().expectedStatus( Status.BAD_REQUEST.getStatusCode() ).payload( jsonString ).post( getNodeUri( getNode( "Joe" ) ) + "/relationships" ).entity(); }
@Test public void shouldAddCorsHeaderWhenAuthEnabledAndPasswordChangeRequired() throws Exception { startServer( true ); HTTP.Response response = runQuery( "neo4j", "neo4j" ); assertEquals( FORBIDDEN.getStatusCode(), response.status() ); assertCorsHeaderPresent( response ); assertThat( response.content().toString(), containsString( "password_change" ) ); }