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

The following examples show how to use com.amazonaws.util.json.JSONObject#getString() . 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: ParseReferrerBolt.java    From aws-big-data-blog with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(Tuple input,  BasicOutputCollector collector) {
    Record record = (Record)input.getValueByField(DefaultKinesisRecordScheme.FIELD_RECORD);
    ByteBuffer buffer = record.getData();
    String data = null; 
    try {
        data = decoder.decode(buffer).toString();
        JSONObject jsonObject = new JSONObject(data);

        String referrer = jsonObject.getString("referrer");

        int firstIndex = referrer.indexOf('.');
        int nextIndex = referrer.indexOf('.',firstIndex+1);
        collector.emit(new Values(referrer.substring(firstIndex+1,nextIndex)));

    } catch (CharacterCodingException|JSONException|IllegalStateException e) {
        LOG.error("Exception when decoding record ", e);
    }
}
 
Example 2
Source File: GeoDynamoDBServlet.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
private void queryRectangle(JSONObject requestObject, PrintWriter out) throws IOException, JSONException {
	GeoPoint minPoint = new GeoPoint(requestObject.getDouble("minLat"), requestObject.getDouble("minLng"));
	GeoPoint maxPoint = new GeoPoint(requestObject.getDouble("maxLat"), requestObject.getDouble("maxLng"));
	String filterUserId = requestObject.getString("filterUserId");

	List<String> attributesToGet = new ArrayList<String>();
	attributesToGet.add(config.getRangeKeyAttributeName());
	attributesToGet.add(config.getGeoJsonAttributeName());
	attributesToGet.add("title");
	attributesToGet.add("userId");

	QueryRectangleRequest queryRectangleRequest = new QueryRectangleRequest(minPoint, maxPoint);
	queryRectangleRequest.getQueryRequest().setAttributesToGet(attributesToGet);
	QueryRectangleResult queryRectangleResult = geoDataManager.queryRectangle(queryRectangleRequest);

	printGeoQueryResult(queryRectangleResult, out, filterUserId);
}
 
Example 3
Source File: GeoDynamoDBServlet.java    From reinvent2013-mobile-photo-share with Apache License 2.0 6 votes vote down vote up
private void queryRadius(JSONObject requestObject, PrintWriter out) throws IOException, JSONException {
	GeoPoint centerPoint = new GeoPoint(requestObject.getDouble("lat"), requestObject.getDouble("lng"));
	double radiusInMeter = requestObject.getDouble("radiusInMeter");
	String filterUserId = requestObject.getString("filterUserId");

	List<String> attributesToGet = new ArrayList<String>();
	attributesToGet.add(config.getRangeKeyAttributeName());
	attributesToGet.add(config.getGeoJsonAttributeName());
	attributesToGet.add("title");
	attributesToGet.add("userId");

	QueryRadiusRequest queryRadiusRequest = new QueryRadiusRequest(centerPoint, radiusInMeter);
	queryRadiusRequest.getQueryRequest().setAttributesToGet(attributesToGet);
	QueryRadiusResult queryRadiusResult = geoDataManager.queryRadius(queryRadiusRequest);

	printGeoQueryResult(queryRadiusResult, out, filterUserId);
}
 
Example 4
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 5
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());
	}
}
 
Example 6
Source File: GeoDynamoDBServlet.java    From dynamodb-geo with Apache License 2.0 5 votes vote down vote up
private void updatePoint(JSONObject requestObject, PrintWriter out) throws IOException, JSONException {
	GeoPoint geoPoint = new GeoPoint(requestObject.getDouble("lat"), requestObject.getDouble("lng"));
	AttributeValue rangeKeyAttributeValue = new AttributeValue().withS(requestObject.getString("rangeKey"));

	String schoolName = requestObject.getString("schoolName");
	AttributeValueUpdate schoolNameValueUpdate = null;

	String memo = requestObject.getString("memo");
	AttributeValueUpdate memoValueUpdate = null;

	if (schoolName == null || schoolName.equalsIgnoreCase("")) {
		schoolNameValueUpdate = new AttributeValueUpdate().withAction(AttributeAction.DELETE);
	} else {
		AttributeValue schoolNameAttributeValue = new AttributeValue().withS(schoolName);
		schoolNameValueUpdate = new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(
				schoolNameAttributeValue);
	}

	if (memo == null || memo.equalsIgnoreCase("")) {
		memoValueUpdate = new AttributeValueUpdate().withAction(AttributeAction.DELETE);
	} else {
		AttributeValue memoAttributeValue = new AttributeValue().withS(memo);
		memoValueUpdate = new AttributeValueUpdate().withAction(AttributeAction.PUT).withValue(memoAttributeValue);
	}

	UpdatePointRequest updatePointRequest = new UpdatePointRequest(geoPoint, rangeKeyAttributeValue);
	updatePointRequest.getUpdateItemRequest().addAttributeUpdatesEntry("schoolName", schoolNameValueUpdate);
	updatePointRequest.getUpdateItemRequest().addAttributeUpdatesEntry("memo", memoValueUpdate);

	UpdatePointResult updatePointResult = geoDataManager.updatePoint(updatePointRequest);

	printUpdatePointResult(updatePointResult, out);
}