Java Code Examples for com.amazonaws.util.json.JSONObject#getJSONObject()

The following examples show how to use com.amazonaws.util.json.JSONObject#getJSONObject() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiGatewaySdkRamlApiImporter.java    From aws-apigateway-importer with Apache License 2.0 6 votes vote down vote up
private void createIntegrationResponses(Integration integration, JSONObject responses) {
    if (responses == null) {
        return;
    }

    final Iterator<String> keysIterator = responses.keys();

    while (keysIterator.hasNext()) {
        String key = keysIterator.next();

        try {
            String pattern = key.equals("default") ? null : key;
            JSONObject response = responses.getJSONObject(key);

            String status = (String) response.get("statusCode");

            PutIntegrationResponseInput input = new PutIntegrationResponseInput()
                    .withResponseParameters(jsonObjectToHashMapString(response.optJSONObject("responseParameters")))
                    .withResponseTemplates(jsonObjectToHashMapString(response.optJSONObject("responseTemplates")))
                    .withSelectionPattern(pattern);

            integration.putIntegrationResponse(input, status);
        } catch (JSONException e) {
        }
    }
}
 
Example 2
Source File: GeoDynamoDBServlet.java    From reinvent2013-mobile-photo-share with Apache License 2.0 5 votes vote down vote up
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
		IOException {
	try {
		StringBuffer buffer = new StringBuffer();
		String line = null;
		BufferedReader reader = request.getReader();

		while ((line = reader.readLine()) != null) {
			buffer.append(line);
		}

		JSONObject jsonObject = new JSONObject(buffer.toString());
		PrintWriter out = response.getWriter();

		String action = jsonObject.getString("action");
		log("action: " + action);
		JSONObject requestObject = jsonObject.getJSONObject("request");
		log("requestObject: " + requestObject);

		if (action.equalsIgnoreCase("put-point")) {
			putPoint(requestObject, out);
		} else if (action.equalsIgnoreCase("get-point")) {
			getPoint(requestObject, out);
		} else if (action.equalsIgnoreCase("query-rectangle")) {
			queryRectangle(requestObject, out);
		} else if (action.equalsIgnoreCase("query-radius")) {
			queryRadius(requestObject, out);
		} else if (action.equalsIgnoreCase("delete-point")) {
			deletePoint(requestObject, out);
		}
	} catch (Exception e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		log(sw.toString());
	}
}
 
Example 3
Source File: GeoDynamoDBServlet.java    From dynamodb-geo with Apache License 2.0 5 votes vote down vote up
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,
		IOException {
	try {
		StringBuffer buffer = new StringBuffer();
		String line = null;
		BufferedReader reader = request.getReader();

		while ((line = reader.readLine()) != null) {
			buffer.append(line);
		}

		JSONObject jsonObject = new JSONObject(buffer.toString());
		PrintWriter out = response.getWriter();

		String action = jsonObject.getString("action");
		log("action: " + action);
		JSONObject requestObject = jsonObject.getJSONObject("request");
		log("requestObject: " + requestObject);

		if (action.equalsIgnoreCase("put-point")) {
			putPoint(requestObject, out);
		} else if (action.equalsIgnoreCase("get-point")) {
			getPoint(requestObject, out);
		} else if (action.equalsIgnoreCase("update-point")) {
			updatePoint(requestObject, out);
		} else if (action.equalsIgnoreCase("query-rectangle")) {
			queryRectangle(requestObject, out);
		} else if (action.equalsIgnoreCase("query-radius")) {
			queryRadius(requestObject, out);
		} else if (action.equalsIgnoreCase("delete-point")) {
			deletePoint(requestObject, out);
		}
	} catch (Exception e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		log(sw.toString());
	}
}