@SuppressWarnings({"unchecked", "unused"}) public final JSONObject innerMap() throws ParseException { final JSONObject json = new JSONObject(); String key; Object value; key = objectKey(); jj_consume_token(EQUALS); value = value(); json.put(key, value); key = null; value = null; label_1: while (true) { switch (jj_nt.kind) { case SLASH:; break; default: jj_la1[1] = jj_gen; break label_1; } jj_consume_token(SLASH); jj_consume_token(COMMA); key = objectKey(); jj_consume_token(EQUALS); value = value(); json.put(key, value); key = null; value = null; } { if (true) return json; } throw new Error("Missing return statement in function"); }
@SuppressWarnings({"unused", "unchecked"}) public final JSONObject object() throws ParseException { final JSONObject json = new JSONObject(); String key; Object value; key = objectKey(); jj_consume_token(EQUALS); value = value(); json.put(key, value); key = null; value = null; label_2: while (true) { if (jj_2_1(2)) {; } else { break label_2; } jj_consume_token(COMMA); key = objectKey(); jj_consume_token(EQUALS); value = value(); json.put(key, value); key = null; value = null; } { if (true) return json; } throw new Error("Missing return statement in function"); }
public void registrarUsuario() { String dato = ""; JSONParser parser = new JSONParser(); try { while (true) { dato = dis.readUTF(); String usuario = ""; String contraseña = ""; String contra = ""; if (dato.equals("Usuario")) { while (true) { usuario = dis.readUTF(); if (usuario != null) { JSONObject user = new JSONObject(); user.put(usuario, null); FileWriter escribir = new FileWriter("texto.txt"); BufferedWriter bw = new BufferedWriter(escribir); PrintWriter pw = new PrintWriter(bw); pw.write(user.toJSONString()); pw.close(); bw.close(); while (true) { contra = dis.readUTF(); if (contra.equals("Contraseña")) { while (true) { contraseña = dis.readUTF(); if (contraseña != null) { Object obj = parser.parse(new FileReader("texto.txt")); JSONObject asignaPass = (JSONObject) obj; asignaPass.put(usuario, contra); FileWriter escribir2 = new FileWriter("texto.txt"); BufferedWriter bw2 = new BufferedWriter(escribir2); PrintWriter pw2 = new PrintWriter(bw2); pw2.write(asignaPass.toJSONString()); bw2.newLine(); pw2.close(); bw2.close(); break; } } break; } } break; } } break; } } } catch (Exception e) { } }
/** * Sends command to retrieve phones list. * * @return is command successful. */ @SuppressWarnings("unchecked") private boolean getPhoneList() { JSONObject obj = new JSONObject(); try { obj.put("class", "phones"); obj.put("function", "getlist"); return send(obj); } catch (Exception e) { logger.error("Error retrieving phones"); return false; } }
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); try { Class.forName("com.mysql.jdbc.Driver").newInstance(); Connection con = DriverManager.getConnection(Utility.connection, Utility.username, Utility.password); String email = request.getParameter("email_id"); String number = ""; boolean exists = false; String user_name = ""; int user_id = -1; String str1 = "SELECT USER_ID,NAME,PHONE_NUMBER FROM USERS WHERE EMAIL_ID=?"; PreparedStatement prep1 = con.prepareStatement(str1); prep1.setString(1, email); ResultSet rs1 = prep1.executeQuery(); if (rs1.next()) { exists = true; user_id = rs1.getInt("USER_ID"); user_name = rs1.getString("NAME"); number = rs1.getString("PHONE_NUMBER"); } int verification = 0; JSONObject data = new JSONObject(); if (exists) { verification = (int) (Math.random() * 9535641 % 999999); System.out.println("Number " + number + "\nVerification: " + verification); SMSProvider.sendSMS( number, "Your One Time Verification Code for PeopleConnect Is " + verification); } data.put("user_name", user_name); data.put("user_id", user_id); data.put("verification_code", "" + verification); data.put("phone_number", number); String toSend = data.toJSONString(); out.print(toSend); System.out.println(toSend); } catch (Exception e) { e.printStackTrace(); } finally { out.close(); } }
/** * Send needed command for features. * * @param astid param from previous command. * @param xivoUserId param from previous command. * @return is command successful. */ @SuppressWarnings("unchecked") private boolean sendFeatures(String astid, String xivoUserId) { if (connection == null || astid == null || xivoUserId == null) return false; JSONObject obj = new JSONObject(); try { obj.put("class", "featuresget"); obj.put("userid", astid + "/" + xivoUserId); return send(obj); } catch (Exception e) { logger.error("Error send features get command", e); return false; } }
/** * Sends password command. * * @param sessionId the session id from previous command. * @param password the password to authorize. * @return is command successful. */ @SuppressWarnings("unchecked") private boolean authorize(String sessionId, String password) { if (connection == null || sessionId == null || password == null) return false; JSONObject obj = new JSONObject(); try { obj.put("class", "login_pass"); obj.put("hashedpassword", Sha1Crypto.encode(sessionId + ":" + password)); return send(obj); } catch (Exception e) { logger.error("Error login with password", e); return false; } }
/** * Performs a test by sending HTTP Gets to the URL, and records the number of bytes returned. Each * test results are documented and displayed in standard out with the following information: * * <p>URL - The source URL of the test REQ CNT - How many times this test has run START - The * start time of the last test run STOP - The stop time of the last test run THREAD - The thread * id handling this test case RESULT - The result of the test. Either the number of bytes returned * or an error message. */ private void doTest() { String result = ""; this.reqCount++; // Connect and run test steps Date startTime = new Date(); try { ClientResource client = new ClientResource(this.myURL); // place order JSONObject json = new JSONObject(); json.put("payment", "quarter"); json.put("action", "place-order"); client.post(new JsonRepresentation(json), MediaType.APPLICATION_JSON); // Get Gumball Count Representation result_string = client.get(); JSONObject json_count = new JSONObject(result_string.getText()); result = Integer.toString((int) json_count.get("count")); } catch (Exception e) { result = e.toString(); } finally { Date stopTime = new Date(); // Print Report of Result: System.out.println( "======================================\n" + "URL => " + this.myURL + "\n" + "REQ CNT => " + this.reqCount + "\n" + "START => " + startTime + "\n" + "STOP => " + stopTime + "\n" + "THREAD => " + Thread.currentThread().getName() + "\n" + "RESULT => " + result + "\n"); } }
/** * Sends login command. * * @param capalistParam param from previous command. * @return is command successful. */ @SuppressWarnings("unchecked") private boolean sendCapas(JSONArray capalistParam) { if (connection == null || capalistParam == null || capalistParam.isEmpty()) return false; JSONObject obj = new JSONObject(); try { obj.put("class", "login_capas"); obj.put("capaid", capalistParam.get(0)); obj.put("lastconnwins", "false"); obj.put("loginkind", "agent"); obj.put("state", ""); return send(obj); } catch (Exception e) { logger.error("Error login", e); return false; } }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, MongoException, DuplicateKeyException, UnknownHostException { // TODO Auto-generated method stub doGet(request, response); StringBuilder buffer = new StringBuilder(); BufferedReader reader = request.getReader(); String uname = request.getParameter("username"); String password = request.getParameter("password"); String email = request.getParameter("email"); System.out.println(uname + " " + password + " " + email); /*String line; while((line=reader.readLine())!=null){ buffer.append(line); } String data = buffer.toString(); System.out.println(data); data = "{\"p\":\"N\",\"c\":\"W\"}";*/ // System.out.println(data); // JSONObject params = (JSONObject)JSON.parse(data); JSONObject params = new JSONObject(); params.put("username", uname); params.put("password", password); BasicDBObject user1 = new BasicDBObject(params); for (Object key : params.keySet().toArray()) { user1.put(key.toString(), params.get(key)); } // System.out.println(user1.toJson()); MongoClientURI uri = new MongoClientURI("mongodb://*****:*****@ds035014.mongolab.com:35014/vikas2"); MongoClient client = new MongoClient(uri); DB db = client.getDB(uri.getDatabase()); DBCollection users = db.getCollection("users"); users.insert(user1); response.setHeader("Access-Control-Allow-Origin", "*"); response.setHeader("Access-Control-Allow-Methods", "POST"); response.setHeader("Access-Control-Allow-Headers", "Content-Type"); response.setHeader("Access-Control-Max-Age", "86400"); }
private JSONObject createNewUser(int gameId) { int userId; JSONObject jObj = new JSONObject(); JSONObject action = new JSONObject(); Random randomNum = new Random(); userId = randomNum.nextInt(max_users) + 1; while (userIds[userId] == true) { userId = randomNum.nextInt(max_users) + 1; } userIds[userId] = true; try { jObj.put("game", gameId); action.put("actionType", "gameStart"); action.put("actionNumber", 1); jObj.put("action", action); jObj.put("user", "u" + userId); } catch (JSONException e) { System.out.println("could not put"); } gameRecord.put(gameId, new GameInfo("u" + userId, userId)); return jObj; }
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { response.setContentType("text/plain"); PrintWriter writer = response.getWriter(); String q = request.getParameter("q"); if (q == null) { writer.println("ERROR: q has no value."); writer.close(); return; } ResultBundle[] results = Map.getResults(q.toLowerCase()); writer.println("STATUS: " + results.length + " results for the query " + q + "!"); for (ResultBundle rb : results) { JSONObject j = new JSONObject(); j.put("thumbnail", rb.getThumbnail()); j.put("title", rb.getTitle()); j.put("description", rb.getDescription()); j.put("url", rb.getUrl()); writer.println(j.toString()); } writer.close(); }
@RequestMapping( value = "/getCityApi", method = {RequestMethod.GET, RequestMethod.POST}) public String getCityApi( HttpServletRequest request, @RequestParam(value = "locationname") String locationname, ModelMap model) { Map<Object, Object> map = new HashMap<Object, Object>(); JSONArray jSONArray = new JSONArray(); try { String status = "active"; List<City> cityList = cityService.getCityApi(locationname, status); if (cityList != null && cityList.size() > 0) { for (int i = 0; i < cityList.size(); i++) { City city = (City) cityList.get(i); String cityName = (String) city.getCity(); String stateName = (String) city.getState(); int ID = (Integer) (city.getId()); JSONObject jSONObject = new JSONObject(); jSONObject.put("id", ID); jSONObject.put("text", cityName); jSONArray.put(jSONObject); } utilities.setSuccessResponse(response, jSONArray.toString()); } else { throw new ConstException(ConstException.ERR_CODE_NO_DATA, ConstException.ERR_MSG_NO_DATA); } } catch (Exception ex) { logger.error("getCity :" + ex.getMessage()); utilities.setErrResponse(ex, response); } model.addAttribute("model", jSONArray.toString()); return "home"; }
private JSONObject moveUser(int gameCount) { Random randomNum = new Random(); GameInfo gameInfo; JSONObject jObj = new JSONObject(); JSONObject action = new JSONObject(); JSONObject coords = new JSONObject(); int game; int xCoord; int yCoord; int addPoints; // Gets random number to denote which game to use action on game = getRandomGame(gameCount); xCoord = randomNum.nextInt(20) + 1; yCoord = randomNum.nextInt(20) + 1; addPoints = randomNum.nextInt(41) - 20; gameInfo = gameRecord.get(game); gameInfo.addPoints(addPoints); gameInfo.incrementCount(); try { jObj.put("game", game); coords.put("x", xCoord); coords.put("y", yCoord); action.put("actionType", "Move"); action.put("actionNumber", gameInfo.getCount()); action.put("location", coords); action.put("pointsAdded", addPoints); action.put("points", gameInfo.getPoints()); jObj.put("action", action); jObj.put("user", gameInfo.getUser()); } catch (JSONException e) { System.out.println("could not put"); } return jObj; }
private JSONObject endGame(int gameCount) { Random randomNum = new Random(); GameInfo gameInfo; JSONObject jObj = new JSONObject(); JSONObject action = new JSONObject(); int game; String status; game = getRandomGame(gameCount); gameInfo = gameRecord.get(game); gameInfo.incrementCount(); if (gameInfo.getCount() < 9) { return moveUser(gameCount); } if (gameInfo.getPoints() > 40 || gameInfo.getPoints() < -40) { status = "WIN"; } else { status = "LOSS"; } try { jObj.put("game", game); action.put("actionType", "gameEnd"); action.put("gameStatus", status); action.put("actionNumber", gameInfo.getCount()); action.put("points", gameInfo.getPoints()); jObj.put("action", action); jObj.put("user", gameInfo.getUser()); userIds[gameInfo.getId()] = false; gameRecord.remove(game); } catch (JSONException e) { System.out.println("could not put"); } return jObj; }
/** * Sends login command. * * @param username the username. * @return is command successful. */ @SuppressWarnings("unchecked") private boolean login(String username) { if (connection == null || username == null) return false; JSONObject obj = new JSONObject(); try { obj.put("class", "login_id"); obj.put("company", "Jitsi"); String os = "x11"; if (OSUtils.IS_WINDOWS) os = "win"; else if (OSUtils.IS_MAC) os = "mac"; obj.put("ident", username + "@" + os); obj.put("userid", username); obj.put("version", "9999"); obj.put("xivoversion", "1.1"); return send(obj); } catch (Exception e) { logger.error("Error login", e); return false; } }
/** * parses an answer object into the json exchange format for an answer * * @param answer the answer object that should be translated * @return json string in the exchange format between frontend and middleware */ public static String answerQuery(QueryAnswer answer) { JSONObject obj = new JSONObject(); obj.put("source", answer.source); // add chromosome attribute to json answer obj.put("chromosome", answer.chromosome); JSONObject from_to = new JSONObject(); from_to.put("from", answer.position[0]); from_to.put("to", answer.position[1]); obj.put("position", from_to); String response; if (answer.hasDetail) { JSONObject details = new JSONObject(); details.put("refseq", answer.refseq); // create json_array for found mutations JSONArray mutations_array = new JSONArray(); for (IntervalST.Mutation x : answer.mutations) { // json object for single mutation, that was found JSONObject mut = new JSONObject(); // name of mutation, need to convert from byte array to string mut.put("name", new String(x.b_RefName)); // json object for position of mutation's interval, with "to" and "from" as attributes JSONObject mut_pos = new JSONObject(); mut_pos.put("from", x.i_Low); mut_pos.put("to", x.i_High); mut.put("position", mut_pos); // json object for metadata JSONObject meta = new JSONObject(); // json object for gender JSONObject gender = new JSONObject(); // -1 for no filter on gender, 0 for male and 1 for female if (x.s_Gender == -1) { gender.put("m", true); gender.put("w", true); } else if (x.s_Gender == 0) { gender.put("m", true); gender.put("w", false); } else if (x.s_Gender == 1) { gender.put("m", false); gender.put("w", true); } else { gender = null; } meta.put("gender", gender); // add country meta.put("origin", IndexController.getCountry(x.s_Country)); // downloadtime meta.put("downloadtime", x.s_Date); // add metadata json object to mutation json object mut.put("metadata", meta); // add sequence of basis pairs, first need to convert integer to string if (answer.chromosome == 23) { mut.put("mutationseq", Chromosome_reader.retrieve_sequence(x.i_Low, x.i_High, "X")); } else if (answer.chromosome == 24) { mut.put("mutationseq", Chromosome_reader.retrieve_sequence(x.i_Low, x.i_High, "Y")); } else if (answer.chromosome == 25) { mut.put("mutationseq", Chromosome_reader.retrieve_sequence(x.i_Low, x.i_High, "MT")); } else { mut.put( "mutationseq", Chromosome_reader.retrieve_sequence(x.i_Low, x.i_High, answer.chromosome.toString())); } // add json object for mutation x to json array for all mutations that were found mutations_array.add(mut); } details.put("mutations", mutations_array); obj.put("details", details); StringWriter out = new StringWriter(); try { obj.writeJSONString(out); } catch (IOException e) { e.printStackTrace(); } response = out.toString(); } else { obj.put("details", null); // function to count occurrences of mutations in subintervals Integer[] counts = count_mutations(answer); JSONArray mutation_counts = new JSONArray(); for (int i = 0; i < counts.length; i++) { mutation_counts.add(counts[i]); } obj.put("graph", mutation_counts); StringWriter out = new StringWriter(); try { obj.writeJSONString(out); } catch (IOException e) { e.printStackTrace(); } response = out.toString(); } if (response != null) { return response; } else { return "Something went wrong while creating answer"; } }
private JSONObject specialMove(int gameCount) { Random randomNum = new Random(); GameInfo gameInfo; JSONObject jObj = new JSONObject(); JSONObject action = new JSONObject(); int game; int addPoints; int special; // Gets random number to denote which game to use action on game = getRandomGame(gameCount); gameInfo = gameRecord.get(game); // Checks if all specials are used if (gameInfo.checkSpecial()) { return moveUser(gameCount); } // Gets random number to denote which special move to use special = randomNum.nextInt(4); while (gameInfo.checkSpecialMove(special)) { special = randomNum.nextInt(4); } gameInfo.useSpecialMove(special); addPoints = randomNum.nextInt(41) - 20; gameInfo.addPoints(addPoints); gameInfo.incrementCount(); try { jObj.put("game", game); action.put("actionType", "specialMove"); action.put("actionNumber", gameInfo.getCount()); action.put("pointsAdded", addPoints); if (special == SHUFFLE) { action.put("move", "Shuffle"); } else if (special == CLEAR) { action.put("move", "Clear"); } else if (special == INVERT) { action.put("move", "Invert"); } else { action.put("move", "Rotate"); } action.put("points", gameInfo.getPoints()); jObj.put("action", action); jObj.put("user", gameInfo.getUser()); } catch (JSONException e) { System.out.println("could not put"); } return jObj; }
/** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ @SuppressWarnings("unchecked") protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("application/json"); response.setHeader("Cache-Control", "nocache"); response.setCharacterEncoding("utf-8"); PrintWriter out = response.getWriter(); StringWriter result = new StringWriter(); // get received JSON data from request BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream())); String postData = ""; if (br != null) { postData = br.readLine(); } try { JSONObject json = (JSONObject) new JSONParser().parse(postData); JSONObject resultObj = new JSONObject(); JSONArray list = new JSONArray(); List<Tracking> trackingList = new ArrayList<Tracking>(); // get the website list if (json.get("type").equals("websiteslist")) { trackingList = trackingDao.websiteList(pool); for (Tracking item : trackingList) { list.add(item.getWebsite()); } } // render report else if (json.get("type").equals("submit")) { if (json.get("criteria").equals("date")) { // render repoty by date trackingList = trackingDao.getListByDate(pool, json.get("date").toString()); } else if (json.get("criteria").equals("daterange")) { // render repoty by date range trackingList = trackingDao.getListByDateRange( pool, json.get("fromdate").toString(), json.get("todate").toString()); } else if (json.get("criteria").equals("website")) { // render repoty by website String website = (json.get("website") == null ? "" : json.get("website").toString()); trackingList = trackingDao.getListByWebsite(pool, website); } for (Tracking item : trackingList) { JSONObject trackingObj = new JSONObject(); trackingObj.put("date", item.getDate()); trackingObj.put("website", item.getWebsite()); trackingObj.put("visit", item.getVisit()); list.add(trackingObj); } } resultObj.put("result", list); resultObj.writeJSONString(result); // finally output the json string out.print(result.toString()); } catch (ParseException | SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
/** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub PrintWriter out = response.getWriter(); String id = request.getParameter("hashID"); JSONObject result = new JSONObject(); if (id != null && id.trim().isEmpty()) { response.setContentType("text/plain"); response.setStatus(400); out.println("Empty hash ID"); return; } Connection conn = null; Statement st = null; ResultSet rs = null; String password; try { // Read the SQL password from a file BufferedReader reader = null; try { InputStream inputStream = getClass().getClassLoader().getResourceAsStream("SQLpw.txt"); reader = new BufferedReader(new InputStreamReader(inputStream)); password = reader.readLine(); } catch (NullPointerException e) { e.getStackTrace(); password = ""; } // create a mysql database connection String myDriver = "com.mysql.jdbc.Driver"; String myUrl = "jdbc:mysql://localhost/lodstories"; Class.forName(myDriver); conn = DriverManager.getConnection(myUrl, "root", password); st = conn.createStatement(); rs = st.executeQuery("SELECT hash,title,author FROM hash_objects where id='" + id + "'"); if (!rs.next()) { response.setContentType("text/plain"); response.setStatus(400); out.println("Error retrieving hash object"); return; } result.put("hash", rs.getString("hash")); result.put("title", rs.getString("title")); result.put("author", rs.getString("author")); // result.put("path", rs.getString("path")); // result.put("rating", rs.getInt("rating")); // Update the lastAccessed field st.executeUpdate( "UPDATE hash_objects SET lastAccessed=CURRENT_TIMESTAMP() WHERE id='" + id + "'"); response.setContentType("application/json"); response.setCharacterEncoding("UTF-8"); out.println(result); } catch (ClassNotFoundException e) { System.err.println("Could not connect to driver!"); System.err.println(e.getMessage()); } catch (SQLException ex) { System.err.println( "SQLException: " + ex.getMessage() + ", SQLState: " + ex.getSQLState() + "VendorError: " + ex.getErrorCode()); } catch (JSONException ex) { ex.printStackTrace(); } finally { if (conn != null) { try { conn.close(); } catch (SQLException ex) { ex.printStackTrace(); } } if (st != null) { try { st.close(); } catch (SQLException ex) { ex.printStackTrace(); } } if (rs != null) { try { rs.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } }
/** * takes a query object and calls the appropriate sub component that answers the given query * * @param query the query that has to be answered * @return a string in the answer exchange format that will be sent to the frontend */ public static String handleQuery(Query query) { // interval search String answer; if (query.x_Search == null) { // check if necessary fields are given if (query.i_Start == -1 || query.i_End == -1) { // query.response_format = "Wrong interval given"; return "Wrong interval given"; } else if (query.s_Chromosome == -1) { // query.response_format = "No chromosome given"; return "No chromosome given"; } else if (query.s_Source == -1) { // query.response_format = "No source given"; return "No source given"; } // correct query format else { // Send query to IndexController // Translation from query to intervalst.query // needs to be unified /* short s_SourceNo=(short)0; if (query.source.equals("dbSNP")) { s_SourceNo = (short) 0; } if (query.source.equals("1000GenomesProject")){ s_SourceNo =(short) 1; } */ Query[] q_Query = {query}; QueryAnswer temp_answer = indexController.answerQuery(q_Query); answer = answerQuery(temp_answer); /* // byte temp = query.chromosome.get(); // byte[] b={temp}; //CRITICAL PART. change query format into intervallst.query . answerquery throws nullpointer byte[] b=new byte[0]; byte[] c=new byte[0]; int i=query.position[0]; int j=query.position[1]; IntervalST.Query intervalst_query=new IntervalST.Query(1,i,j,s_SourceNo,Integer.toString(query.chromosome).getBytes(),null,null); IntervalST.Query[] queries={intervalst_query}; IntervalST.Answer x_Result=indexController.answerQuery(queries); System.out.println("Length of AnswerList: "+x_Result.x_List.size()); if (query.hasDetail) { String sequence = Chromosome_reader.retrieve_sequence(i,j,Integer.toString(query.chromosome)); } return query; */ } } // gene name search else { // test for prefix query if (query.b_isPrefix) { /* // This needs to be replaced! String[] genenames = GeneTranslator.completeGeneName(query.search); */ String[] genenames = {"FOXP2", "FOXP4"}; JSONObject obj = new JSONObject(); obj.put("source", query.s_Source); obj.put("chromosome", query.s_Chromosome); JSONArray names = new JSONArray(); for (int i = 0; i < genenames.length; i++) { names.add(genenames[i]); } obj.put("prefix", names); StringWriter out = new StringWriter(); try { obj.writeJSONString(out); } catch (IOException e) { e.printStackTrace(); } answer = out.toString(); } else { if (query.x_Search == "getInitialSources") { System.out.println("getInitialSources"); return null; } else { String[] interval = GeneTranslator.translateToIntervall(query.x_Search); JSONObject pos_obj = new JSONObject(); JSONObject obj = new JSONObject(); pos_obj.put("from", Integer.valueOf(interval[0])); pos_obj.put("to", Integer.valueOf(interval[1])); obj.put("search", query.x_Search); obj.put("position", pos_obj); StringWriter out = new StringWriter(); try { obj.writeJSONString(out); } catch (IOException e) { e.printStackTrace(); } answer = out.toString(); } } } // queryID_pool.add(query.queryID); return answer; }