Search in sources :

Example 51 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project ranger by apache.

the class JSONUtil method readMapToString.

public String readMapToString(Map<?, ?> map) {
    ObjectMapper mapper = new ObjectMapper();
    String jsonString = null;
    try {
        jsonString = mapper.writeValueAsString(map);
    } catch (JsonParseException e) {
        throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
    } catch (JsonMappingException e) {
        throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
    } catch (IOException e) {
        throw restErrorUtil.createRESTException("Invalid input data: " + e.getMessage(), MessageEnums.INVALID_INPUT_DATA);
    }
    return jsonString;
}
Also used : JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 52 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project wonderdog by infochimps-labs.

the class ElasticSearchStorage method putNext.

/**
 *       Here we handle both the delimited record case and the json case.
 */
@SuppressWarnings("unchecked")
@Override
public void putNext(Tuple t) throws IOException {
    UDFContext context = UDFContext.getUDFContext();
    Properties property = context.getUDFProperties(ResourceSchema.class);
    MapWritable record = new MapWritable();
    String isJson = property.getProperty(ES_IS_JSON);
    // Handle delimited records (ie. isJson == false)
    if (isJson != null && isJson.equals("false")) {
        String[] fieldNames = property.getProperty(PIG_ES_FIELD_NAMES).split(COMMA);
        for (int i = 0; i < t.size(); i++) {
            if (i < fieldNames.length) {
                try {
                    record.put(new Text(fieldNames[i]), new Text(t.get(i).toString()));
                } catch (NullPointerException e) {
                // LOG.info("Increment null field counter.");
                }
            }
        }
    } else {
        if (!t.isNull(0)) {
            String jsonData = t.get(0).toString();
            // parse json data and put into mapwritable record
            try {
                HashMap<String, Object> data = mapper.readValue(jsonData, HashMap.class);
                record = (MapWritable) toWritable(data);
            } catch (JsonParseException e) {
                e.printStackTrace();
            } catch (JsonMappingException e) {
                e.printStackTrace();
            }
        }
    }
    try {
        writer.write(NullWritable.get(), record);
    } catch (InterruptedException e) {
        throw new IOException(e);
    }
}
Also used : UDFContext(org.apache.pig.impl.util.UDFContext) IOException(java.io.IOException) Properties(java.util.Properties) JsonParseException(org.codehaus.jackson.JsonParseException) InterruptedException(java.lang.InterruptedException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 53 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project coprhd-controller by CoprHD.

the class KHRequests method postRequest.

/*
     * Send POST request to KittyHawk server, and handle redirect/cookies
     * 
     * @param resource webResource
     * 
     * @param ParamBase parameters for post
     * 
     * @throws VNXeException
     */
public ClientResponse postRequest(ParamBase param) throws VNXeException {
    _logger.debug("post data: " + _url);
    ObjectMapper mapper = new ObjectMapper();
    String parmString = null;
    if (param != null) {
        try {
            parmString = mapper.writeValueAsString(param);
            _logger.debug("Content of the post: {}", parmString);
        } catch (JsonGenerationException e) {
            _logger.error("Post request param is not valid. ", e);
            throw VNXeException.exceptions.vnxeCommandFailed("Post request param is not valid.", e);
        } catch (JsonMappingException e) {
            _logger.error("Post request param is not valid. ", e);
            throw VNXeException.exceptions.vnxeCommandFailed("Post request param is not valid.", e);
        } catch (IOException e) {
            _logger.error("Post request param is not valid. ", e);
            throw VNXeException.exceptions.vnxeCommandFailed("Post request param is not valid.", e);
        }
    }
    ClientResponse response = buildRequest(addQueryParameters(buildResource(_resource)).getRequestBuilder()).entity(parmString).post(ClientResponse.class);
    Status statusCode = response.getClientResponseStatus();
    if (statusCode == ClientResponse.Status.CREATED || statusCode == ClientResponse.Status.ACCEPTED || statusCode == ClientResponse.Status.OK || statusCode == ClientResponse.Status.NO_CONTENT) {
        return response;
    } else if (statusCode == ClientResponse.Status.UNAUTHORIZED) {
        authenticate();
        response = buildRequest(addQueryParameters(buildResource(_resource)).getRequestBuilder()).entity(parmString).post(ClientResponse.class);
        ;
        statusCode = response.getClientResponseStatus();
        if (statusCode == ClientResponse.Status.OK || statusCode == ClientResponse.Status.ACCEPTED || statusCode == ClientResponse.Status.NO_CONTENT || statusCode == ClientResponse.Status.CREATED) {
            return response;
        }
    }
    int redirectTimes = 1;
    // handle redirect
    while (response.getClientResponseStatus() == ClientResponse.Status.FOUND && redirectTimes < VNXeConstants.REDIRECT_MAX) {
        String code = response.getClientResponseStatus().toString();
        String data = response.getEntity(String.class);
        _logger.debug("Returned code: {}, returned data {}", code, data);
        WebResource newResource = handelRedirect(response);
        if (newResource != null) {
            response = buildRequest(newResource.getRequestBuilder()).entity(parmString).post(ClientResponse.class);
            redirectTimes++;
        } else {
            // could not find the redirect url, return
            _logger.error(String.format("The post request to: %s failed with: %s %s", _url, response.getClientResponseStatus().toString(), response.getEntity(String.class)));
            throw VNXeException.exceptions.unexpectedDataError("Got redirect status code, but could not get redirected URL");
        }
    }
    if (redirectTimes >= VNXeConstants.REDIRECT_MAX) {
        _logger.error("redirected too many times for the request {}", _url);
        throw VNXeException.exceptions.unexpectedDataError("Redirected too many times while sending the request for " + _url);
    }
    checkResponse(response, POST_REQUEST);
    return response;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Status(com.sun.jersey.api.client.ClientResponse.Status) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) WebResource(com.sun.jersey.api.client.WebResource) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 54 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project coprhd-controller by CoprHD.

the class KHRequests method postRequestSync.

public VNXeCommandResult postRequestSync(ParamBase param) {
    ClientResponse response = postRequest(param);
    if (response.getClientResponseStatus() == ClientResponse.Status.NO_CONTENT) {
        VNXeCommandResult result = new VNXeCommandResult();
        result.setSuccess(true);
        return result;
    }
    String resString = response.getEntity(String.class);
    _logger.debug("KH API returned: {} ", resString);
    JSONObject res;
    String objectString = null;
    VNXeCommandResult returnedObject = null;
    try {
        res = new JSONObject(resString);
        if (res != null) {
            JSONObject object = (JSONObject) res.get(VNXeConstants.CONTENT);
            if (object != null) {
                objectString = object.toString();
                ObjectMapper mapper = new ObjectMapper();
                try {
                    returnedObject = mapper.readValue(objectString, VNXeCommandResult.class);
                    returnedObject.setSuccess(true);
                } catch (JsonParseException e) {
                    _logger.error(String.format("unexpected data returned: %s", objectString), e);
                    throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", objectString), e);
                } catch (JsonMappingException e) {
                    _logger.error(String.format("unexpected data returned: %s", objectString), e);
                    throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", objectString), e);
                } catch (IOException e) {
                    _logger.error(String.format("unexpected data returned: %s", objectString), e);
                    throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", objectString), e);
                }
            }
        }
    } catch (JSONException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError(String.format("unexpected data returned: %s", objectString), e);
    }
    return returnedObject;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VNXeCommandResult(com.emc.storageos.vnxe.models.VNXeCommandResult) JSONObject(org.codehaus.jettison.json.JSONObject) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) JSONException(org.codehaus.jettison.json.JSONException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 55 with JsonMappingException

use of org.codehaus.jackson.map.JsonMappingException in project coprhd-controller by CoprHD.

the class KHRequests method postRequestAsync.

public VNXeCommandJob postRequestAsync(ParamBase param) {
    setAsyncMode();
    ClientResponse response = postRequest(param);
    VNXeCommandJob job;
    String resString = response.getEntity(String.class);
    ObjectMapper mapper = new ObjectMapper();
    try {
        job = mapper.readValue(resString, VNXeCommandJob.class);
    } catch (JsonParseException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError("unexpected data returned:" + resString, e);
    } catch (JsonMappingException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError("unexpected data returned:" + resString, e);
    } catch (IOException e) {
        _logger.error(String.format("unexpected data returned: %s from: %s", resString, _url), e);
        throw VNXeException.exceptions.unexpectedDataError("unexpected data returned:" + resString, e);
    }
    if (job != null) {
        _logger.info("submitted the job: " + job.getId());
    } else {
        _logger.warn("No job returned.");
    }
    return job;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonParseException(org.codehaus.jackson.JsonParseException) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

JsonMappingException (org.codehaus.jackson.map.JsonMappingException)88 IOException (java.io.IOException)79 JsonParseException (org.codehaus.jackson.JsonParseException)53 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)36 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)27 ArrayList (java.util.ArrayList)24 HashMap (java.util.HashMap)19 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)15 Response (javax.ws.rs.core.Response)13 Map (java.util.Map)11 List (java.util.List)10 GET (javax.ws.rs.GET)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 WebApplicationException (javax.ws.rs.WebApplicationException)10 TypeReference (org.codehaus.jackson.type.TypeReference)10 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 ClientResponse (com.sun.jersey.api.client.ClientResponse)6 StringWriter (java.io.StringWriter)5 Enterprise (com.itrus.portal.db.Enterprise)4