use of javax.ws.rs.core.MultivaluedHashMap in project jersey by jersey.
the class MediaTypeSelectionTest method testNoAcceptHeader.
@Test
public void testNoAcceptHeader() {
// This test is testing the situation when the client sends no Accept header to the server and it expects
// APPLICATION_OCTET_STREAM_TYPE to be returned. But when no Accept header is defined by the client api the
// HttpURLConnection (in HttpUrlConnector) always put there some default Accept header (like */*, text/plain, ...).
// To overwrite this behaviour we set Accept to empty String. This works fine as the server code handles empty
// Accept header like no Accept header.
final MultivaluedHashMap headers = new MultivaluedHashMap();
headers.add("Accept", "");
Response r = target("text/any").request().headers(headers).get();
assertEquals(200, r.getStatus());
assertEquals(MediaType.APPLICATION_OCTET_STREAM_TYPE, r.getMediaType());
}
use of javax.ws.rs.core.MultivaluedHashMap in project camel by apache.
the class TelegramServiceRestBotAPIAdapter method buildTextPart.
private Attachment buildTextPart(String name, String value) {
MultivaluedMap m = new MultivaluedHashMap<>();
m.putSingle("Content-Type", "text/plain");
m.putSingle("Content-Disposition", "form-data; name=\"" + escapeMimeName(name) + "\"");
Attachment a = new Attachment(m, value);
return a;
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class UserAuthenticationFilterEmbeddedTest method requestAccessTokenCustomAuth4Step2.
@Parameters({ "tokenPath", "userId", "userSecret", "audience", "RS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret" })
@Test(dependsOnMethods = "requestAccessTokenCustomAuth4Step1")
public void requestAccessTokenCustomAuth4Step2(final String tokenPath, final String userId, final String userSecret, final String audience, final String keyId, final String dnName, final String keyStoreFile, final String keyStoreSecret) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
tokenRequest.setScope("email read_stream manage_pages");
tokenRequest.setAuthUsername(clientId4);
tokenRequest.setAuthPassword(clientSecret4);
tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
tokenRequest.setCryptoProvider(cryptoProvider);
tokenRequest.setKeyId(keyId);
tokenRequest.setAudience(audience);
tokenRequest.addCustomParameter("uid", userId);
tokenRequest.addCustomParameter("pwd", userSecret);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestAccessTokenCustomAuth4Step2", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertTrue(!entity.equals(null), "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found");
} catch (Exception e) {
fail(e.getMessage(), e);
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class UserAuthenticationFilterEmbeddedTest method requestAccessTokenCustomAuth3Step2.
@Parameters({ "tokenPath", "userInum", "userEmail" })
@Test(dependsOnMethods = "requestAccessTokenCustomAuth3Step1")
public void requestAccessTokenCustomAuth3Step2(final String tokenPath, final String userInum, final String userEmail) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + tokenPath).request();
TokenRequest tokenRequest = new TokenRequest(GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS);
tokenRequest.setScope("email read_stream manage_pages");
tokenRequest.setAuthUsername(clientId3);
tokenRequest.setAuthPassword(clientSecret3);
tokenRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
tokenRequest.addCustomParameter("mail", userEmail);
tokenRequest.addCustomParameter("inum", userInum);
request.header("Authorization", "Basic " + tokenRequest.getEncodedCredentials());
request.header("Content-Type", MediaType.APPLICATION_FORM_URLENCODED);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(tokenRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestAccessTokenCustomAuth3Step2", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertTrue(!entity.equals(null), "Unexpected result: " + entity);
try {
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has("access_token"), "Unexpected result: access_token not found");
assertTrue(jsonObj.has("token_type"), "Unexpected result: token_type not found");
assertTrue(jsonObj.has("refresh_token"), "Unexpected result: refresh_token not found");
assertTrue(jsonObj.has("scope"), "Unexpected result: scope not found");
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
use of javax.ws.rs.core.MultivaluedHashMap in project oxAuth by GluuFederation.
the class UserInfoRestWebServiceEmbeddedTest method requestUserInfoHS384Step3.
@Parameters({ "userInfoPath" })
@Test(dependsOnMethods = "requestUserInfoHS384Step2")
public void requestUserInfoHS384Step3(final String userInfoPath) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + userInfoPath).request();
request.header("Authorization", "Bearer " + accessToken6);
UserInfoRequest userInfoRequest = new UserInfoRequest(null);
Response response = request.post(Entity.form(new MultivaluedHashMap<String, String>(userInfoRequest.getParameters())));
String entity = response.readEntity(String.class);
showResponse("requestUserInfoHS384Step3", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
assertTrue(response.getHeaderString("Cache-Control") != null && response.getHeaderString("Cache-Control").equals("no-store, private"), "Unexpected result: " + response.getHeaderString("Cache-Control"));
assertTrue(response.getHeaderString("Pragma") != null && response.getHeaderString("Pragma").equals("no-cache"), "Unexpected result: " + response.getHeaderString("Pragma"));
assertNotNull(entity, "Unexpected result: " + entity);
try {
Jwt jwt = Jwt.parse(entity);
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.SUBJECT_IDENTIFIER));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.NAME));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.EMAIL));
assertNotNull(jwt.getClaims().getClaimAsString(JwtClaimName.PICTURE));
} catch (InvalidJwtException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
Aggregations