List of usage examples for org.json.simple JSONValue writeJSONString
public static void writeJSONString(Object value, Writer out) throws IOException
From source file:org.mskcc.cbio.portal.servlet.GisticJSON.java
/** * * @param request//from ww w .java 2 s . co m * @param response * @throws ServletException * @throws IOException */ @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String cancer_study_id = request.getParameter(SELECTED_CANCER_STUDY); try { CancerStudy cancerStudy = DaoCancerStudy.getCancerStudyByStableId(cancer_study_id); if (log.isDebugEnabled()) { log.debug("cancerStudyId passed to GisticJSON: " + cancerStudy.getInternalId()); } ArrayList<Gistic> gistics = DaoGistic.getAllGisticByCancerStudyId(cancerStudy.getInternalId()); if (log.isDebugEnabled()) { log.debug("list of gistics associated with cancerStudy: " + gistics); } // Collections.sort(gistics, new sortMutsigByRank()); JSONArray gisticJSONArray = new JSONArray(); for (Gistic gistic : gistics) { Map map = Gistic_toMap(gistic); if (!map.isEmpty()) { gisticJSONArray.add(map); } } response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { JSONValue.writeJSONString(gisticJSONArray, out); } finally { out.close(); } } catch (DaoException e) { log.debug(e); throw new ServletException(e); } }
From source file:org.mskcc.cbio.portal.servlet.MutSigJSON.java
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String cancer_study_id = request.getParameter(SELECTED_CANCER_STUDY); JSONArray mutSigJSONArray = new JSONArray(); try {/*from w w w. ja v a 2 s.c o m*/ CancerStudy cancerStudy = DaoCancerStudy.getCancerStudyByStableId(cancer_study_id); if (log.isDebugEnabled()) { log.debug("cancerStudyId passed to MutSigJSON: " + cancerStudy.getInternalId()); } ArrayList<MutSig> mutSigList = DaoMutSig.getAllMutSig(cancerStudy.getInternalId()); if (log.isDebugEnabled()) { log.debug("no of mutsigs associated with cancerStudy: " + mutSigList.size() + "\n"); } Collections.sort(mutSigList, new sortMutsigByRank()); int i = 0; for (MutSig mutsig : mutSigList) { // log.debug("" + mutsig.toString() + " " + i++); Map map = MutSigtoMap(mutsig); // log.debug(map); if (!map.isEmpty()) { mutSigJSONArray.add(map); } } response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { JSONValue.writeJSONString(mutSigJSONArray, out); } finally { out.close(); } } catch (DaoException e) { throw new ServletException(e); } }
From source file:org.mskcc.cbio.portal.servlet.ProteinArraySignificanceTestJSON.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods. * @param request servlet request//from w w w .ja v a2 s . c o m * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { JSONArray table = new JSONArray(); String cancerStudyStableId = request.getParameter("cancer_study_id"); String heatMap = request.getParameter("heat_map"); String gene = request.getParameter("gene"); String alterationType = request.getParameter("alteration"); String antibodyType = request.getParameter("antibody"); String excludeAntibodyType = request.getParameter("exclude_antibody"); String strDataScale = request.getParameter("data_scale"); // TODO filtered heat map breaks the parsing, we need the raw parameter // (alternatively, we can change the parsing method) if (request instanceof XssRequestWrapper) { heatMap = ((XssRequestWrapper) request).getRawParameter("heat_map"); } double dataScale = strDataScale == null ? 0 : Double.parseDouble(strDataScale); Collection<String> antibodyTypes; if (antibodyType == null) { if (excludeAntibodyType == null) { antibodyTypes = null; // include all } else { try { antibodyTypes = GetProteinArrayData.getProteinArrayTypes(); antibodyTypes.removeAll(Arrays.asList(excludeAntibodyType.split(" "))); } catch (DaoException e) { throw new ServletException(e); } } } else { antibodyTypes = Arrays.asList(antibodyType.split(" ")); } String[] heatMapLines = heatMap.split("\r?\n"); String[] genes = heatMapLines[0].split("\t"); genes[0] = "Any"; Set<String> allCases = getAllCases(heatMapLines); Map<String, Set<String>>[] alteredCases = getAlteredCases(heatMapLines, genes, gene, alterationType); Map<String, ProteinArrayInfo> proteinArrays; Map<String, Map<String, Double>> proteinArrayData; try { int cancerStudyId = DaoCancerStudy.getCancerStudyByStableId(cancerStudyStableId).getInternalId(); proteinArrays = GetProteinArrayData.getProteinArrayInfo(cancerStudyId, null, antibodyTypes); proteinArrayData = GetProteinArrayData.getProteinArrayData(cancerStudyId, proteinArrays.keySet(), allCases); } catch (DaoException e) { throw new ServletException(e); } if (gene == null) { for (int i = 0; i < genes.length; i++) { export(table, genes[i], alteredCases[i], proteinArrays, proteinArrayData, dataScale); } } else { export(table, gene, alteredCases[0], proteinArrays, proteinArrayData, dataScale); } response.setContentType("application/json"); PrintWriter out = response.getWriter(); try { JSONValue.writeJSONString(table, out); } finally { out.close(); } }
From source file:org.test.router.TestRouteBuilder.java
@Override public void configure() { from("restlet:/user?restletMethod=POST").setBody(simple( "insert into user(firstName, lastName) values('${header.firstName}','${header.lastName}'); CALL IDENTITY();")) .to("jdbc:dataSource").setBody(simple("select * from user ORDER BY id desc LIMIT 1")) .to("jdbc:dataSource"); from("restlet:/user/{userId}?restletMethods=GET,PUT,DELETE").choice() .when(simple("${header.CamelHttpMethod} == 'GET'")) .setBody(simple("select * from user where id = ${header.userId}")) .when(simple("${header.CamelHttpMethod} == 'PUT'")) .setBody(simple(//from w ww . j a va 2s . com "update user set firstName='${header.firstName}', lastName='${header.lastName}' where id = ${header.userId}")) .when(simple("${header.CamelHttpMethod} == 'DELETE'")) .setBody(simple("delete from user where id = ${header.userId}")).otherwise().stop().end() .to("jdbc:dataSource"); from("restlet:/users").setBody(simple("select id, firstname, lastName from user")).to("jdbc:dataSource") .log("body ${body}").process(new Processor() { public void process(Exchange exchange) throws Exception { List payload = exchange.getIn().getBody(List.class); // HashMap<String, String> map = new HashMap<String, String>(); // map.put("hola", "holxax"); StringWriter out = new StringWriter(); JSONValue.writeJSONString(payload, out); String jsonText = out.toString(); // payload = payload.replace("", ""); // Log // do something with the payload and/or exchange here // exchange.getIn().setHeader("Access-Control-Allow-Origin", // "*"); // exchange.getIn().setHeader("xx",simple("x")); exchange.getIn().setBody(jsonText); // exchange.getIn().setHeader(CxfConstants.CAMEL_CXF_RS_USING_HTTP_API, // Boolean.FALSE); // // exchange.getIn().setHeader("Access-Control-Allow-Methods", // "DELETE PUT"); // exchange.getIn().setHeader("Access-Control-Allow-Credentials", // "false"); // exchange.getIn().setHeader(org.apache.camel.component.http.HttpProducer.HTTP_URI, // "*"); // org.apache.camel.component.http.HttpProducer.HTTP_URI Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class); Map<String, Object> attrs = request.getAttributes(); Series headers = (Series) attrs.get("org.restlet.http.headers"); headers.add("Access-Control-Allow-Origin", "*"); } }); }
From source file:sf.net.experimaestro.manager.json.JsonInteger.java
@Override public void write(Writer out) throws IOException { JSONValue.writeJSONString(value, out); }
From source file:sf.net.experimaestro.manager.json.JsonString.java
@Override public void write(Writer out) throws IOException { JSONValue.writeJSONString(string, out); }
From source file:synoptic.model.export.JsonExporter.java
/** * Export the JSON object representation of the partition graph pGraph to * the filename specified//from ww w. j a v a 2 s . c om * * @param baseFilename * The filename to which the JSON object should be written sans * file extension * @param graph * The partition graph to output */ public static <T extends INode<T>> void exportJsonObject(String baseFilename, IGraph<T> graph) { // The graph must be a partition graph assert graph instanceof PartitionGraph; PartitionGraph pGraph = (PartitionGraph) graph; Map<String, Object> finalModelMap = new LinkedHashMap<String, Object>(); // Add log to final model map List<Map<String, Object>> logListOfTraces = makeLogJSON(pGraph); finalModelMap.put("log", logListOfTraces); // Add partitions to final model map List<Map<String, Object>> partitionList = makePartitionsJSON(pGraph); finalModelMap.put("partitions", partitionList); // Add invariants to final model map List<Map<String, Object>> invariantList = makeInvariantsJSON(pGraph); finalModelMap.put("invariants", invariantList); // Output the final model map as a JSON object try { PrintWriter output = new PrintWriter(baseFilename + ".json"); JSONValue.writeJSONString(finalModelMap, output); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:uk.ac.susx.tag.method51.webapp.jetty.HelpfulHandler.java
protected void handleRequestException(RequestException e, String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { baseRequest.setHandled(true);//from w ww . ja va2s . c o m response.setStatus(e.status); response.setCharacterEncoding("utf-8"); response.setContentType("application/json"); JSONValue.writeJSONString(jsonObject("error", e.getMessage()), response.getWriter()); }