Search in sources :

Example 76 with UniformInterfaceException

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

the class PrivilegeRestTest method noJSONStringInPost.

private void noJSONStringInPost() throws Exception {
    Form form = new Form();
    form.add("subject", hashedTokenId);
    try {
        webClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
    } catch (UniformInterfaceException e) {
        validateUniformInterfaceException(e, 9, "noJSONStringInPost");
    }
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) Form(com.sun.jersey.api.representation.Form)

Example 77 with UniformInterfaceException

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

the class OAuthServiceUtils method getUUIDByTokenId.

public static String getUUIDByTokenId(String tokenId) throws OAuthServiceException {
    String uuid;
    MultivaluedMapImpl params = new MultivaluedMapImpl();
    params.add(SUBJECT_ID, tokenId);
    params.add("attributenames", UUID_SESSION_PROPERTY_NAME);
    String response;
    try {
        response = attributesResource.queryParams(params).get(String.class);
    } catch (UniformInterfaceException uie) {
        throw new OAuthServiceException("Get uuid failed", uie);
    }
    if (response == null) {
        return null;
    }
    int index = response.indexOf(USERDETAILS_NAME_KEY + "=" + UUID_SESSION_PROPERTY_NAME);
    index = response.indexOf(USERDETAILS_VALUE_KEY + "=", index);
    int startIdx = index + USERDETAILS_VALUE_KEY.length() + 1;
    int idx = response.indexOf(USERDETAILS_NAME_KEY + "=", startIdx);
    int endIdx;
    if (idx > 0) {
        endIdx = idx;
    } else {
        endIdx = response.length() - 1;
    }
    uuid = response.substring(startIdx, endIdx).trim();
    return uuid;
}
Also used : UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) OAuthServiceException(com.sun.identity.oauth.service.OAuthServiceException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl)

Example 78 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project apex-core by apache.

the class StramWebServicesTest method testInvalidUri.

@Test
@SuppressWarnings("UnusedAssignment")
public void testInvalidUri() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
        responseStr = r.path(StramWebServices.PATH).path("bogus").accept(MediaType.APPLICATION_JSON).get(String.class);
        fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
        StramTestSupport.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) JerseyTest(com.sun.jersey.test.framework.JerseyTest) Test(org.junit.Test)

Example 79 with UniformInterfaceException

use of com.sun.jersey.api.client.UniformInterfaceException in project apex-core by apache.

the class StramWebServicesTest method testInvalidUri2.

@Test
@SuppressWarnings("UnusedAssignment")
public void testInvalidUri2() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
        responseStr = r.path("ws").path("v2").path("invalid").accept(MediaType.APPLICATION_JSON).get(String.class);
        fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
        StramTestSupport.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) JerseyTest(com.sun.jersey.test.framework.JerseyTest) 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