Java Code Examples for org.jboss.resteasy.client.ClientRequest#setHttpMethod()
The following examples show how to use
org.jboss.resteasy.client.ClientRequest#setHttpMethod() .
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: RestEndPointMockerTest.java From zerocode with Apache License 2.0 | 6 votes |
@Test public void willMockASimpleGetEndPoint() throws Exception { final MockStep mockStep = mockSteps.getMocks().get(0); String jsonBodyRequest = mockStep.getResponse().get("body").toString(); WireMock.configureFor(9073); givenThat(get(urlEqualTo(mockStep.getUrl())) .willReturn(aResponse() .withStatus(mockStep.getResponse().get("status").asInt()) .withHeader("Content-Type", APPLICATION_JSON) .withBody(jsonBodyRequest))); ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor(); ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073" + mockStep.getUrl()); clientExecutor.setHttpMethod("GET"); ClientResponse serverResponse = clientExecutor.execute(); final String respBodyAsString = (String) serverResponse.getEntity(String.class); JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true); System.out.println("### zerocode: \n" + respBodyAsString); }
Example 2
Source File: JwtUtil.java From oxAuth with MIT License | 6 votes |
public static JSONObject getJSONWebKeys(String jwksUri, ClientExecutor executor) { log.debug("Retrieving jwks " + jwksUri + "..."); JSONObject jwks = null; try { if (!StringHelper.isEmpty(jwksUri)) { ClientRequest clientRequest = executor != null ? new ClientRequest(jwksUri, executor) : new ClientRequest(jwksUri); clientRequest.setHttpMethod(HttpMethod.GET); ClientResponse<String> clientResponse = clientRequest.get(String.class); int status = clientResponse.getStatus(); log.debug(String.format("Status: %n%d", status)); if (status == 200) { jwks = fromJson(clientResponse.getEntity(String.class)); log.debug(String.format("JWK: %s", jwks)); } } } catch (Exception ex) { log.error(ex.getMessage(), ex); } return jwks; }
Example 3
Source File: WireMockJsonContentTesting.java From zerocode with Apache License 2.0 | 5 votes |
@Test public void bioViaJson() throws Exception{ String jsonBodyRequest = "{\n" + " \"id\": \"303021\",\n" + " \"names\": [\n" + " {\n" + " \"firstName\": \"You First\",\n" + " \"lastName\": \"Me Last\"\n" + " }\n" + " ]\n" + "}"; givenThat(WireMock.get(urlEqualTo("/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default")) .willReturn(aResponse() .withStatus(200) .withHeader("Content-Type", APPLICATION_JSON) .withBody(jsonBodyRequest))); ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor(); ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default"); clientExecutor.setHttpMethod("GET"); ClientResponse serverResponse = clientExecutor.execute(); final String respBodyAsString = (String)serverResponse.getEntity(String.class); JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true); System.out.println("### bio response from mapping: \n" + respBodyAsString); }
Example 4
Source File: CIBARegisterParamsValidatorService.java From oxAuth with MIT License | 4 votes |
public boolean validateParams( BackchannelTokenDeliveryMode backchannelTokenDeliveryMode, String backchannelClientNotificationEndpoint, AsymmetricSignatureAlgorithm backchannelAuthenticationRequestSigningAlg, Boolean backchannelUserCodeParameter, List<GrantType> grantTypes, SubjectType subjectType, String sectorIdentifierUri, String jwks, String jwksUri) { try { // Not CIBA Registration if (backchannelTokenDeliveryMode == null && Strings.isBlank(backchannelClientNotificationEndpoint) && backchannelAuthenticationRequestSigningAlg == null) { return true; } // Required parameter. if (backchannelTokenDeliveryMode == null || !appConfiguration.getBackchannelTokenDeliveryModesSupported().contains(backchannelTokenDeliveryMode.getValue())) { return false; } // Required if the token delivery mode is set to ping or push. if ((backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == PUSH) && Strings.isBlank(backchannelClientNotificationEndpoint)) { return false; } // Grant type urn:openid:params:grant-type:ciba is required if the token delivery mode is set to ping or poll. if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) { if (!appConfiguration.getGrantTypesSupported().contains(CIBA) || !grantTypes.contains(CIBA)) { return false; } } // If the server does not support backchannel_user_code_parameter_supported, the default value is false. if (appConfiguration.getBackchannelUserCodeParameterSupported() == null || appConfiguration.getBackchannelUserCodeParameterSupported() == false) { backchannelUserCodeParameter = false; } if (subjectType != null && subjectType == SubjectType.PAIRWISE) { if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) { if (Strings.isBlank(jwks) && Strings.isBlank(jwksUri)) { return false; } } if (Strings.isNotBlank(sectorIdentifierUri)) { ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri); clientRequest.setHttpMethod(HttpMethod.GET); ClientResponse<String> clientResponse = clientRequest.get(String.class); int status = clientResponse.getStatus(); if (status != 200) { return false; } String entity = clientResponse.getEntity(String.class); JSONArray sectorIdentifierJsonArray = new JSONArray(entity); if (backchannelTokenDeliveryMode == PING || backchannelTokenDeliveryMode == POLL) { // If a sector_identifier_uri is explicitly provided, then the jwks_uri must be included in the list of // URIs pointed to by the sector_identifier_uri. if (!Strings.isBlank(jwksUri) && !Util.asList(sectorIdentifierJsonArray).contains(jwksUri)) { return false; } } else if (backchannelTokenDeliveryMode == PUSH) { // In case a sector_identifier_uri is explicitly provided, then the backchannel_client_notification_endpoint // must be included in the list of URIs pointed to by the sector_identifier_uri. if (!Util.asList(sectorIdentifierJsonArray).contains(backchannelClientNotificationEndpoint)) { return false; } } } } } catch (Exception e) { log.trace(e.getMessage(), e); return false; } return true; }
Example 5
Source File: RedirectionUriService.java From oxAuth with MIT License | 4 votes |
public String validateRedirectionUri(@NotNull Client client, String redirectionUri) { try { String sectorIdentifierUri = client.getSectorIdentifierUri(); String[] redirectUris = client.getRedirectUris(); if (StringUtils.isNotBlank(sectorIdentifierUri)) { ClientRequest clientRequest = new ClientRequest(sectorIdentifierUri); clientRequest.setHttpMethod(HttpMethod.GET); ClientResponse<String> clientResponse = clientRequest.get(String.class); int status = clientResponse.getStatus(); if (status == 200) { String entity = clientResponse.getEntity(String.class); JSONArray sectorIdentifierJsonArray = new JSONArray(entity); redirectUris = new String[sectorIdentifierJsonArray.length()]; for (int i = 0; i < sectorIdentifierJsonArray.length(); i++) { redirectUris[i] = sectorIdentifierJsonArray.getString(i); } } else { return null; } } if (StringUtils.isNotBlank(redirectionUri) && redirectUris != null) { log.debug("Validating redirection URI: clientIdentifier = {}, redirectionUri = {}, found = {}", client.getClientId(), redirectionUri, redirectUris.length); if (isUriEqual(redirectionUri, redirectUris)) { return redirectionUri; } } else { // Accept Request Without redirect_uri when One Registered if (redirectUris != null && redirectUris.length == 1) { return redirectUris[0]; } } } catch (Exception e) { return null; } return null; }
Example 6
Source File: JwtUtil.java From oxAuth with MIT License | 4 votes |
public static JSONObject getJsonKey(String jwksUri, String jwks, String keyId) { log.debug("Retrieving JWK Key..."); JSONObject jsonKey = null; try { if (StringHelper.isEmpty(jwks)) { ClientRequest clientRequest = new ClientRequest(jwksUri); clientRequest.setHttpMethod(HttpMethod.GET); ClientResponse<String> clientResponse = clientRequest.get(String.class); int status = clientResponse.getStatus(); log.debug(String.format("Status: %n%d", status)); if (status == 200) { jwks = clientResponse.getEntity(String.class); log.debug(String.format("JWK: %s", jwks)); } } if (StringHelper.isNotEmpty(jwks)) { JSONObject jsonObject = new JSONObject(jwks); JSONArray keys = jsonObject.getJSONArray(JSON_WEB_KEY_SET); if (keys.length() > 0) { if (StringHelper.isEmpty(keyId)) { jsonKey = keys.getJSONObject(0); } else { for (int i = 0; i < keys.length(); i++) { JSONObject kv = keys.getJSONObject(i); if (kv.getString(KEY_ID).equals(keyId)) { jsonKey = kv; break; } } } } } } catch (Exception ex) { log.error(ex.getMessage(), ex); } return jsonKey; }