Search in sources :

Example 96 with UniformInterfaceException

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

the class StramWebServicesTest method testInvalidAccept.

@Test
@SuppressWarnings("UnusedAssignment")
public void testInvalidAccept() throws JSONException, Exception {
    // suppress logging in jersey to get rid of expected stack traces from test log
    java.util.logging.Logger.getLogger("org.glassfish.grizzly.servlet.ServletHandler").setLevel(Level.OFF);
    java.util.logging.Logger.getLogger("com.sun.jersey.spi.container.ContainerResponse").setLevel(Level.OFF);
    WebResource r = resource();
    String responseStr = "";
    try {
        responseStr = r.path(StramWebServices.PATH).accept(MediaType.TEXT_PLAIN).get(String.class);
        fail("should have thrown exception on invalid accept");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertEquals(Status.INTERNAL_SERVER_ERROR, 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 97 with UniformInterfaceException

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

the class TestRMWebServicesNodes method testNodesQueryStateInvalid.

@Test
public void testNodesQueryStateInvalid() throws JSONException, Exception {
    WebResource r = resource();
    getNewRMNode("h1", 1234, 5120);
    getNewRMNode("h2", 1235, 5121);
    try {
        r.path("ws").path("v1").path("cluster").path("nodes").queryParam("states", "BOGUSSTATE").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception querying invalid state");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        WebServicesTestUtils.checkStringContains("exception message", "org.apache.hadoop.yarn.api.records.NodeState.BOGUSSTATE", message);
        WebServicesTestUtils.checkStringMatch("exception type", "IllegalArgumentException", type);
        WebServicesTestUtils.checkStringMatch("exception classname", "java.lang.IllegalArgumentException", classname);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 98 with UniformInterfaceException

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

the class TestRMWebServicesNodes method testNonexistNodeDefault.

// test that the exception output defaults to JSON
@Test
public void testNonexistNodeDefault() throws JSONException, Exception {
    getNewRMNode("h1", 1234, 5120);
    getNewRMNode("h2", 1235, 5121);
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("cluster").path("nodes").path("node_invalid:99").get(JSONObject.class);
        fail("should have thrown exception on non-existent nodeid");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        verifyNonexistNodeException(message, type, classname);
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 99 with UniformInterfaceException

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

the class TestRMWebServicesApps method testAppsQueryStatesInvalid.

@Test
public void testAppsQueryStatesInvalid() throws JSONException, Exception {
    rm.start();
    MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
    rm.submitApp(CONTAINER_MB);
    amNodeManager.nodeHeartbeat(true);
    WebResource r = resource();
    try {
        r.path("ws").path("v1").path("cluster").path("apps").queryParam("states", "INVALID_test").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception on invalid state query");
    } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
        assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
        JSONObject msg = response.getEntity(JSONObject.class);
        JSONObject exception = msg.getJSONObject("RemoteException");
        assertEquals("incorrect number of elements", 3, exception.length());
        String message = exception.getString("message");
        String type = exception.getString("exception");
        String classname = exception.getString("javaClassName");
        WebServicesTestUtils.checkStringContains("exception message", "Invalid application-state INVALID_test", message);
        WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type);
        WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
    } finally {
        rm.stop();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONObject(org.codehaus.jettison.json.JSONObject) MockNM(org.apache.hadoop.yarn.server.resourcemanager.MockNM) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 100 with UniformInterfaceException

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

the class TestRMWebServices method testInvalidUri.

@Test
public void testInvalidUri() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
        responseStr = r.path("ws").path("v1").path("cluster").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)172 WebResource (com.sun.jersey.api.client.WebResource)128 ClientResponse (com.sun.jersey.api.client.ClientResponse)74 Test (org.junit.Test)65 JSONObject (org.codehaus.jettison.json.JSONObject)45 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)34 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)20 SOSFailure (com.emc.storageos.vasa.fault.SOSFailure)18 ArrayList (java.util.ArrayList)17 LinkedList (java.util.LinkedList)16 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)14 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)14 IOException (java.io.IOException)12 Client (com.sun.jersey.api.client.Client)10 List (java.util.List)10 AnnisAttribute (annis.service.objects.AnnisAttribute)9 GenericType (com.sun.jersey.api.client.GenericType)8 Application (org.apache.hadoop.yarn.server.nodemanager.containermanager.application.Application)7 MockNM (org.apache.hadoop.yarn.server.resourcemanager.MockNM)7 JerseyTest (com.sun.jersey.test.framework.JerseyTest)6