Search in sources :

Example 66 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.

the class RestTest method missingResourceTest.

@Test
public void missingResourceTest() throws Exception {
    Form params = new Form();
    params.add("subject", hashedUserTokenId);
    params.add("action", "GET");
    params.add("env", ATTR_NAME + "=" + ATTR_VAL);
    params.add("realm", REALM);
    try {
        entitlementClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("application/json").get(String.class);
        throw new Exception("RESTTest.missingResourceTest: no exception thrown.");
    } catch (UniformInterfaceException e) {
        int errorCode = e.getResponse().getStatus();
        if (errorCode != 400) {
            throw new Exception("RESTTest.missingResourceTest: incorrect error code");
        }
        String json = e.getResponse().getEntity(String.class);
        JSONObject jo = new JSONObject(json);
        if (jo.optInt("statusCode") != 420) {
            throw new Exception("RESTTest.missingResourceTest() failed, status code not 420");
        }
        if (jo.optJSONObject("body") != null) {
            throw new Exception("RESTTest.missingResourceTest() failed, body not empty");
        }
    }
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.json.JSONObject) Form(com.sun.jersey.api.representation.Form) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Test(org.testng.annotations.Test)

Example 67 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.

the class RestTest method missingActionTest.

@Test
public void missingActionTest() throws Exception {
    Form params = new Form();
    params.add("subject", hashedUserTokenId);
    params.add("resource", RESOURCE_NAME + "/index.html");
    params.add("env", ATTR_NAME + "=" + ATTR_VAL);
    params.add("realm", REALM);
    try {
        decisionClient.queryParams(params).header(RestServiceManager.SUBJECT_HEADER_NAME, userTokenIdHeader).cookie(cookie).accept("text/plain").get(String.class);
        throw new Exception("RESTTest.missingActionTest: no exception thrown.");
    } catch (UniformInterfaceException e) {
        int errorCode = e.getResponse().getStatus();
        if (errorCode != 400) {
            throw new Exception("RESTTest.missingActionTest: incorrect error code");
        }
    }
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Form(com.sun.jersey.api.representation.Form) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Test(org.testng.annotations.Test)

Example 68 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.

the class OAuthServiceUtils method isTokenValid.

public static boolean isTokenValid(String tokenId) throws OAuthServiceException {
    boolean result = false;
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add(TOKEN_ID, tokenId);
    String response;
    try {
        response = tokenValidationResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Validate token failed", uie);
    }
    // ensure response is in expected format
    if (response.startsWith("boolean=true")) {
        result = true;
    }
    return result;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 69 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.

the class OAuthServiceUtils method authenticate.

public static String authenticate(String username, String password, boolean appAuth) throws OAuthServiceException {
    MultivaluedMap params = new MultivaluedMapImpl();
    params.add(AUTHN_USERNAME, username);
    params.add(AUTHN_PASSWORD, password);
    if (appAuth) {
        params.add("uri", "module=application");
    }
    String response;
    try {
        response = authenticateResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Authentication failed", uie);
    }
    // ensure response is in expected format
    if (!response.startsWith(ATTRIBUTE_TOKEN_ID_KEY + "=")) {
        return null;
    }
    String tokenId = response.substring(9);
    tokenId = tokenId.substring(0, tokenId.length() - 1);
    return tokenId;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 70 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project hadoop by apache.

the class TestHsWebServices method testInvalidUri.

@Test
public void testInvalidUri() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
        responseStr = r.path("ws").path("v1").path("history").path("bogus").accept(MediaType.APPLICATION_JSON).get(String.class);
        fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
        WebServicesTestUtils.checkStringMatch("error string exists and shouldn't", "", responseStr);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Aggregations

UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)79 ClientResponse (com.sun.jersey.api.client.ClientResponse)67 WebResource (com.sun.jersey.api.client.WebResource)66 Test (org.junit.Test)62 JSONObject (org.codehaus.jettison.json.JSONObject)44 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)14 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)14 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)9 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)8 Form (com.sun.jersey.api.representation.Form)7 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)4 StringReader (java.io.StringReader)4 DocumentBuilder (javax.xml.parsers.DocumentBuilder)4 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)4 JSONObject (org.json.JSONObject)4 Document (org.w3c.dom.Document)4 Element (org.w3c.dom.Element)4 NodeList (org.w3c.dom.NodeList)4 InputSource (org.xml.sax.InputSource)4 OAuthServiceException (com.sun.identity.oauth.service.OAuthServiceException)3