Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
Attach a sessionID to the URL request to be able to distinguish diffe…
Browse files Browse the repository at this point in the history
…rent users in the same IP ##5
  • Loading branch information
jordimas committed Mar 10, 2016
1 parent c755b0e commit c23571f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import android.util.Log;

Expand All @@ -48,6 +49,7 @@ public class LanguageToolRequest {
private static final String SERVER_URL = "https://languagetool.org:8081";
private static final String ENCODING = "UTF-8";
private static final String TAG = LanguageToolRequest.class.getSimpleName();
private static final String m_sessionId = GetSessionID();

private final LanguageToolParsing languageToolParsing = new LanguageToolParsing();
String[][] mAndroidToLTLangMap = new String[][]{
Expand All @@ -68,6 +70,13 @@ public LanguageToolRequest(String language) {
m_language = ConvertLanguage(language);
}

static private String GetSessionID() {
Random rand = new Random();
int MAX_NUM = 999999;
int id = rand.nextInt(MAX_NUM);
return Integer.toString(id);
}

private static String toString(InputStream inputStream) throws Exception {
StringBuilder outputBuilder = new StringBuilder();
try {
Expand Down Expand Up @@ -156,6 +165,8 @@ private String BuildURL() {
sb.append(SERVER_URL);
/* Parameter to allow languagetool.org to distingish the origin of the request */
sb.append(AddQueryParameter("?", "useragent", "androidspell"));
/* Parameter to help to track requests from the same IP */
sb.append(AddQueryParameter("&", "sessionID", m_sessionId));
return sb.toString();
}

Expand Down

0 comments on commit c23571f

Please sign in to comment.