List of usage examples for org.json.simple JSONObject toJSONString
public String toJSONString()
From source file:com.dubture.symfony.core.index.SymfonyIndexingVisitorExtension.java
@Override public boolean visit(TypeDeclaration s) throws Exception { if (!isSymfonyResource) { return false; }/*from ww w . j av a2 s.c om*/ if (indexer == null) { indexer = SymfonyIndexer.getInstance(); } if (s instanceof ClassDeclaration) { currentClass = (ClassDeclaration) s; for (Object o : currentClass.getSuperClasses().getChilds()) { if (o instanceof FullyQualifiedReference) { FullyQualifiedReference superReference = (FullyQualifiedReference) o; String ns = getUseStatement(superReference.getName()); if (ns != null) { String fqcn = ns + "\\" + superReference.getName(); boolean isTestOrFixture = false; if (namespace != null && namespace.getName() != null) { isTestOrFixture = namespace.getName().contains("Test") || namespace.getName().contains("Fixtures"); } // we got a bundle definition, index it if (fqcn.equals(SymfonyCoreConstants.BUNDLE_FQCN) && !isTestOrFixture) { int length = (currentClass.sourceEnd() - currentClass.sourceEnd()); JSONObject meta = JsonUtils.createBundle(sourceModule, currentClass, namespace); ReferenceInfo info = new ReferenceInfo(ISymfonyModelElement.BUNDLE, currentClass.sourceStart(), length, currentClass.getName(), meta.toJSONString(), namespace.getName()); requestor.addReference(info); } } //TODO: Check against an implementation of Symfony\Component\DependencyInjection\ContainerAwareInterface // // see http://symfony.com/doc/current/cookbook/bundles/best_practices.html#controllers // and http://api.symfony.com/2.0/Symfony/Component/DependencyInjection/ContainerAwareInterface.html if (superReference.getName().equals(SymfonyCoreConstants.CONTROLLER_CLASS)) { inController = true; // the ControllerIndexer does the actual work of parsing the // the relevant elements inside the controller // which are then being collected in the endVisit() method //controllerIndexer = new TemplateVariableVisitor(useStatements, namespace, sourceModule); //currentClass.traverse(controllerIndexer); } } } } else if (s instanceof NamespaceDeclaration) { namespace = (NamespaceDeclaration) s; } return true; }
From source file:io.personium.client.ODataManager.java
/** * This method performs update operation using Request Body, Header and Etag value. * @param id ID value// ww w. j a va 2s . co m * @param body PUT Request Body * @param etag ETag value * @param headers PUT Request Headers * @throws DaoException DAO */ void internalUpdate(String id, JSONObject body, String etag, HashMap<String, String> headers) throws DaoException { String url = this.getUrl() + "('" + id + "')"; IRestAdapter rest = RestAdapterFactory.create(accessor); rest.put(url, body.toJSONString(), etag, headers, RestAdapter.CONTENT_TYPE_JSON); }
From source file:fi.aalto.drumbeat.apicalls.bimserver.BIMServerJSONApi.java
@SuppressWarnings("unchecked") private void login(String username, String password) { JSONObject login = new JSONObject(); JSONObject parameters = new JSONObject(); parameters.put("username", username); parameters.put("password", password); JSONObject request = new JSONObject(); request.put("interface", "Bimsie1AuthInterface"); request.put("method", "login"); request.put("parameters", parameters); login.put("request", request); System.out.println(login);/* ww w. j a v a 2 s. c o m*/ System.out.println("Result:"); JSONObject result = http(bimserver_api_url, login.toJSONString()); JSONObject response = (JSONObject) result.get("response"); if (response != null) { String login_result = (String) response.get("result"); if (login_result != null) { token = login_result; } else { JSONObject bs_exception = (JSONObject) response.get("exception"); if (bs_exception != null) { String bs_message = (String) bs_exception.get("message"); System.err.println("ERROR " + bs_message); } } } }
From source file:io.personium.core.rs.StatusResource.java
/** * GET???.//from ww w . j a v a2s . c o m * @return JAS-RS Response */ @SuppressWarnings("unchecked") @GET @Produces("application/json") public Response get() { StringBuilder sb = new StringBuilder(); // Properties props = PersoniumUnitConfig.getProperties(); JSONObject responseJson = new JSONObject(); JSONObject propertiesJson = new JSONObject(); for (String key : props.stringPropertyNames()) { String value = props.getProperty(key); propertiesJson.put(key, value); } responseJson.put("properties", propertiesJson); // Cell?/ //responseJson.put("service", checkServiceStatus()); // ElasticSearch Health EsClient client = EsModel.client(); JSONObject esJson = new JSONObject(); esJson.put("health", client.checkHealth()); responseJson.put("ElasticSearch", esJson); sb.append(responseJson.toJSONString()); return Response.status(HttpStatus.SC_OK).entity(sb.toString()).build(); }
From source file:be.iminds.aiolos.ui.DemoServlet.java
private void stopComponent(PrintWriter writer, String componentId, String version, String nodeId) { JSONObject result = new JSONObject(); PlatformManager platform = platformTracker.getService(); if (platform != null) { try {/*from ww w . j a va 2 s . co m*/ platform.stopComponent(new ComponentInfo(componentId, version, nodeId)); } catch (Exception e) { e.printStackTrace(); } } writer.write(result.toJSONString()); }
From source file:de.root1.kad.smartvisu.BackendServer.java
private Response handleLogin(IHTTPSession session) { Map<String, String> parms = session.getParms(); String user = parms.get(PARAM_USER); String pass = parms.get(PARAM_PASS); String device = parms.get(PARAM_DEVICE); log.info("login: user={}, pass={}, device={}", user, pass, device); JSONObject obj = new JSONObject(); obj.put(PARAM_VERSION, PROTOCOL_VERSION); String userSessionIdString = requireUserSession ? createUserSessionID(session).getId().toString() : "0"; obj.put(PARAM_SESSION, userSessionIdString); log.info("response: {}", obj.toJSONString()); Response response = new Response(obj.toJSONString()); response.addHeader("Access-Control-Allow-Origin", "*"); return response; }
From source file:com.imagelake.android.signin.Servlet_signin.java
protected void doPost(HttpServletRequest request, HttpServletResponse respose) throws IOException, ServletException { PrintWriter out = respose.getWriter(); try {/*from w w w.jav a2s. c o m*/ Date d = new Date(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); String date = sdf.format(d); SimpleDateFormat sdf2 = new SimpleDateFormat("hh:mm:ss"); String loginTime = sdf2.format(d); HttpSession ses = request.getSession(); un = request.getParameter("un"); pw = request.getParameter("pw"); if (un != null && pw != null) { User u = udi.searchSignIn(un, pw); if (u != null) { if (u.getState() == 1) { Userlogin userlogin = new Userlogin(); userlogin.setBrowser("Android"); userlogin.setIp_address(request.getRemoteHost()); userlogin.setSession_id(ses.getId()); userlogin.setStart_date(sdf.format(d)); userlogin.setStart_time(loginTime); userlogin.setCountry("Sri Lanka"); userlogin.setCode("LK"); userlogin.setUser_user_id(u.getUser_id()); userlogin.setState(1); int ok = uldi.insertLogin(userlogin); System.out.println("okkk " + ok); if (ok > 0) { JSONObject jo = new JSONObject(); jo.put("id", u.getUser_id()); jo.put("un", u.getUser_name()); jo.put("pw", u.getPassword()); jo.put("fn", u.getFirst_name()); jo.put("ln", u.getLast_name()); jo.put("em", u.getEmail()); jo.put("user_type", u.getUser_type()); jo.put("state", u.getState()); out.write("json=" + jo.toJSONString()); System.out.println("json" + jo.toJSONString()); } else { out.write("msg=Internal server error,Please try again later."); } } else { out.write("msg=Blocked by the admin"); } } else { out.write("msg=Incorrect user name or password"); } } else { out.write("msg=Please enter user details"); } } catch (Exception e) { e.printStackTrace(); out.write("msg=Internal server error,Please try again later."); } }
From source file:org.opencastproject.adminui.endpoint.UsersSettingsEndpointTest.java
@SuppressWarnings("unchecked") @Test/*from ww w .j av a2 s . co m*/ public void testPostSignatureExpectsOK() throws ParseException, IOException { String nameKey = "name"; String nameValue = "newsignature"; String fromNameKey = "from_name"; String fromNameValue = "FakeName"; String fromAddressKey = "from_address"; String fromAddressValue = "from@fake.com"; String textKey = "text"; String textValue = "ThisIstheSignatureText"; HashMap<String, String> parameters = new HashMap<String, String>(); parameters.put(nameKey, nameValue); parameters.put(fromNameKey, fromNameValue); parameters.put(fromAddressKey, fromAddressValue); parameters.put(textKey, textValue); JSONObject creator = new JSONObject(); creator.put("username", TestUserSettingsEndpoint.EXAMPLE_USERNAME); creator.put("email", TestUserSettingsEndpoint.EXAMPLE_EMAIL); creator.put("name", TestUserSettingsEndpoint.EXAMPLE_NAME); JSONObject actual = (JSONObject) parser.parse(given().formParam(nameKey, nameValue) .formParam(fromNameKey, fromNameValue).formParam(fromAddressKey, fromAddressValue) .formParam(textKey, textValue).log().all().expect().statusCode(HttpStatus.SC_OK) .contentType(ContentType.JSON).body(nameKey, equalTo(nameValue)).body("creator", equalTo(creator)) .body("signature", equalTo(textValue)).when().post(rt.host("/signature")).asString()); System.out.println(actual.toJSONString()); }
From source file:be.iminds.aiolos.ui.DemoServlet.java
private void migrateComponent(PrintWriter writer, String componentId, String version, String from, String to) { JSONObject result = new JSONObject(); PlatformManager platform = platformTracker.getService(); if (platform != null) { try {/*from ww w.j ava2 s . co m*/ platform.migrateComponent(new ComponentInfo(componentId, version, from), to); } catch (Exception e) { e.printStackTrace(); } } writer.write(result.toJSONString()); }
From source file:i5.las2peer.services.todolist.Todolist.java
/** * /* w w w. j a va 2 s . com*/ * getData * * * @return HttpResponse * */ @GET @Path("/data") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @ApiResponses(value = { @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "responseGetData") }) @ApiOperation(value = "getData", notes = "") public HttpResponse getData() { JSONObject dataJson = new JSONObject(); Connection conn = null; try { conn = dbm.getConnection(); PreparedStatement stmt = conn .prepareStatement("SELECT * FROM gamificationCAE.todolist ORDER BY id ASC"); ResultSet rs = stmt.executeQuery(); while (rs.next()) { dataJson.put(rs.getInt("id"), rs.getString("name")); } if (!dataJson.isEmpty()) { return new HttpResponse(dataJson.toJSONString(), HttpURLConnection.HTTP_OK); } return new HttpResponse("No data Found", HttpURLConnection.HTTP_OK); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); return new HttpResponse("Database connection error", HttpURLConnection.HTTP_INTERNAL_ERROR); } finally { try { conn.close(); } catch (SQLException e) { e.printStackTrace(); } } }