Package com.bluetangstudio.searchcloud.client.exception

Examples of com.bluetangstudio.searchcloud.client.exception.ServiceException


     * @return test data.
     */
    @DataProvider(name = "positive")
    public Object[][] getTestData() {
        return new Object[][] {
                new Object[] { new ServiceException("abc"),
                        "{\"code\":\"SERVICE_EXCEPTION\",\"message\":\"abc\",\"status\":\"INTERNAL_SERVER_ERROR\"}" },
                new Object[] { new InvalidRequestException("abc"),
                        "{\"code\":\"INVALID_REQUEST\",\"message\":\"abc\",\"status\":\"BAD_REQUEST\"}" },
                new Object[] { new QuerySyntaxException("abc"),
                        "{\"code\":\"INVALID_QUERY_SYNTAX\",\"message\":\"abc\",\"status\":\"BAD_REQUEST\"}" },
View Full Code Here


     */
    @Test(dataProvider = "positive")
    public void testReadFromJson(ServiceException expected, String input) throws IOException {
        ObjectMapper mapper = new ObjectMapper();

        ServiceException exception = mapper.readValue(input, ServiceException.class);

        Assert.assertNotNull(exception);
        Assert.assertEquals(exception.getClass(), expected.getClass());
        Assert.assertEquals(exception.getMessage(), expected.getMessage());
    }
View Full Code Here

            int statusCode = httpResponse.getStatusLine().getStatusCode();
            // 5xx server error.
            // 4xx client error.
            // 3xx redriections.
            if (statusCode >= HttpStatus.SC_MULTIPLE_CHOICES) {
                ServiceException se = exceptionHandler.handle(httpResponse);
                if (se != null) {
                    throw se;
                }
            } else if (statusCode >= HttpStatus.SC_OK) {
                return responseHandler.handle(httpResponse);
            }
            // 1xx. HTTP/1.1 extensions
            else if (statusCode >= HttpStatus.SC_CONTINUE) {
                throw new IllegalStateException(String.format("Unexpected status code: %d received.", statusCode));
            }
        } catch (IOException io) {
            httpRequest.abort();
            throw new ServiceException("client side error", io);
        } finally {
            if (httpResponse != null) {
                // consume all entity part so that the connection will be close.
                HttpEntity httpEntity = httpResponse.getEntity();
                if (httpEntity != null) {
View Full Code Here

    /** {@inheritDoc} */
    @SuppressWarnings("deprecation")
    @Override
    public ServiceException handle(HttpResponse httpResponse) {
        HttpEntity entity = httpResponse.getEntity();
        ServiceException ret = null;
        if (entity != null) {
            byte[] entityBody = null;
            try {
                entityBody = EntityUtils.toByteArray(entity);
                ret = SerializationUtils.fromJson(entityBody, ServiceException.class);
            } catch (IOException e) {
                ret = new ServiceException("Fail to deserialize Http Error into ServiceException! body "
                        + new String(entityBody), e);
            } finally {
                // close the connection explicitly.
                try {
                    if (entity != null) {
View Full Code Here

TOP

Related Classes of com.bluetangstudio.searchcloud.client.exception.ServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.