List of usage examples for java.io PrintWriter print
public void print(Object obj)
From source file:com.att.api.immn.controller.CreateSubscriptionController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); final List<String> events = new LinkedList<String>(); JSONObject jresponse = new JSONObject(); try {/*from ww w . ja va 2 s .c o m*/ if (session.getAttribute("subscriptionId") != null) { throw new RESTException("You must first delete your existing subscription."); } if (request.getParameter("subscriptionText") != null) { events.add("TEXT"); } if (request.getParameter("subscriptionMms") != null) { events.add("MMS"); } if (events.size() == 0) { throw new RESTException("You must select at least one of Text or MMS."); } final OAuthToken token = (OAuthToken) session.getAttribute("token"); final String fqdn = appConfig.getApiFQDN(); final WebhooksService srvc = new WebhooksService(fqdn, token); final String channelId = appConfig.getProperty("channelId"); final Integer expiresIn = Integer.valueOf(appConfig.getProperty("expiresIn")); final String callbackData = request.getParameter("callbackData"); final CreateSubscriptionArgs args = new CreateSubscriptionArgs(channelId, events.toArray(new String[events.size()]), callbackData, expiresIn); final CreateSubscriptionResponse createResponse = srvc.createNotificationSubscription(args); session.setAttribute("subscriptionId", createResponse.getSubscription().getSubscriptionId()); session.setAttribute("subscriptionExpiry", DateUtil.xtimestamp() + createResponse.getSubscription().getExpiresIn()); jresponse.put("success", true).put("text", "Subscription created."); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:com.att.api.immn.controller.GetDeltaController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); final String msgState = request.getParameter("msgState"); JSONObject jresponse = new JSONObject(); try {// w w w. j av a 2 s . c o m final DeltaResponse deltaResponse = srvc.getDelta(msgState); final JSONArray tables = new JSONArray(); for (final Delta delta : deltaResponse.getDeltas()) { final JSONArray values = new JSONArray(); for (final DeltaChange dc : delta.getAdds()) { values.put(new JSONArray().put("Add").put(dc.getMessageId()).put(dc.isFavorite()) .put(dc.isUnread())); } for (final DeltaChange dc : delta.getDeletes()) { values.put(new JSONArray().put("Delete").put(dc.getMessageId()).put(dc.isFavorite()) .put(dc.isUnread())); } for (final DeltaChange dc : delta.getUpdates()) { values.put(new JSONArray().put("Update").put(dc.getMessageId()).put(dc.isFavorite()) .put(dc.isUnread())); } tables.put(new JSONObject() .put("caption", "Delta Type: " + delta.getType()).put("headers", new JSONArray() .put("Delta Operation").put("MessageId").put("Favorite").put("Unread")) .put("values", values)); } jresponse.put("success", true).put("tables", tables); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:com.att.api.immn.controller.UpdateSubscriptionController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); final List<String> events = new LinkedList<String>(); JSONObject jresponse = new JSONObject(); try {//from w ww . j av a 2 s . c o m if (session.getAttribute("subscriptionId") == null) { throw new RESTException("You must first create a subscription."); } if (request.getParameter("updateSubscriptionText") != null) { events.add("TEXT"); } if (request.getParameter("updateSubscriptionMms") != null) { events.add("MMS"); } if (events.size() == 0) { throw new RESTException("You must select at least one of Text or MMS."); } final OAuthToken token = (OAuthToken) session.getAttribute("token"); final String subscriptionId = (String) session.getAttribute("subscriptionId"); final String fqdn = appConfig.getApiFQDN(); final WebhooksService srvc = new WebhooksService(fqdn, token); final String channelId = appConfig.getProperty("channelId"); final Integer expiresIn = Integer.valueOf(appConfig.getProperty("expiresIn")); final String callbackData = request.getParameter("callbackData"); final UpdateSubscriptionArgs args = new UpdateSubscriptionArgs(channelId, subscriptionId, events.toArray(new String[events.size()]), callbackData, expiresIn); final UpdateSubscriptionResponse updateResponse = srvc.updateNotificationSubscription(args); session.setAttribute("subscriptionExpiry", DateUtil.xtimestamp() + updateResponse.getSubscription().getExpiresIn()); jresponse.put("success", true).put("text", "Subscription updated."); } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:feedme.controller.UpdateCategoryServlet.java
/** * Handles the HTTP <code>POST</code> method. * * @param request servlet request/*from w ww .j a v a2s. c o m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); String city = request.getParameter("city"); HashMap<String, Integer> cat = new DbHPOnLoad().getCategoriesByCity(city); try { JSONObject catObj = new JSONObject(); catObj.put("categorys", new JSONArray()); JSONArray cate = catObj.getJSONArray("categorys"); for (Map.Entry<String, Integer> entry : cat.entrySet()) { cate.put(new JSONObject().put("cat_id", entry.getValue()).put("cat_name", entry.getKey())); } response.setContentType("application/json"); PrintWriter writer = response.getWriter(); writer.print(catObj); response.getWriter().flush(); } catch (JSONException ex) { Logger.getLogger(OrderCompleteServlet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:de.uni_koeln.spinfo.maalr.webapp.controller.JsonController.java
@RequestMapping(value = "/json", method = RequestMethod.GET, produces = { "application/json" }) @ResponseStatus(HttpStatus.OK)/*from w w w .j ava 2 s . com*/ public void queryJSON(@RequestParam("callback") String callback, MaalrQuery query, @RequestParam String locale, HttpServletResponse response) throws InvalidQueryException, NoIndexAvailableException, BrokenIndexException, IOException, InvalidTokenOffsetsException { String searchPhrase = query.getValue("searchPhrase"); searchPhrase = searchPhrase.endsWith("?") ? searchPhrase.substring(0, searchPhrase.lastIndexOf("?")) : searchPhrase; query.setQueryValue("searchPhrase", searchPhrase); QueryResult result = index.query(query, true); logger.info("Query {}", query); logger.info("QueryResult {}", result); List<LemmaVersion> entries = result.getEntries(); List<Map<String, String>> toReturn = new ArrayList<Map<String, String>>(entries.size()); for (LemmaVersion entry : entries) { String first = ld.toString(entry, UseCase.RESULT_LIST, true); String second = ld.toString(entry, UseCase.RESULT_LIST, false); Map<String, String> map = new HashMap<String, String>(); map.put("a", first); map.put("b", second); if (map.size() > 0) toReturn.add(map); } JsonResult json = new JsonResult(toReturn); if (toReturn.size() == 0) { String message = Localizer.getTranslation(locale, "maalr.query.nothing_found.embedded"); json.setNothingFoundMessage(message.replace("{0}", query.getValue("searchPhrase"))); } ObjectMapper om = new ObjectMapper(); String string = om.writeValueAsString(json); response.setContentType("text/javascript; charset=UTF-8"); PrintWriter out = response.getWriter(); out.print(callback); out.print('('); out.print(string); out.print(')'); }
From source file:gwtupload.server.UploadServlet.java
/** * Writes a response to the client./*from w ww .j av a2 s .co m*/ */ protected static void renderMessage(HttpServletResponse response, String message, String contentType) throws IOException { response.addHeader("Cache-Control", "no-cache"); response.setContentType(contentType + "; charset=UTF-8"); response.setCharacterEncoding("UTF-8"); PrintWriter out = response.getWriter(); out.print(message); out.flush(); out.close(); }
From source file:com.att.api.immn.controller.GetMsgContentController.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final HttpSession session = request.getSession(); OAuthToken token = (OAuthToken) session.getAttribute("token"); IMMNService srvc = new IMMNService(appConfig.getApiFQDN(), token); final String msgId = request.getParameter("contentMsgId"); final String partNumb = request.getParameter("contentPartNumber"); JSONObject jresponse = new JSONObject(); try {//from w w w . j a v a 2s . co m final MessageContent msgContent = srvc.getMessageContent(msgId, partNumb); jresponse.put("success", true); final String type = msgContent.getContentType().toLowerCase(); /* TODO: handle unknown type */ if (type.contains("text")) { jresponse.put("text", "Message Content: " + new String(msgContent.getContent())); } else if (type.contains("image")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("image", image); } else if (type.contains("video")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("video", image); } else if (type.contains("audio")) { final byte[] binary = msgContent.getContent(); final String base64 = new String(Base64.encodeBase64(binary)); final JSONObject image = new JSONObject().put("type", msgContent.getContentType()).put("base64", base64); jresponse.put("audio", image); } } catch (RESTException re) { jresponse.put("success", false).put("text", re.getMessage()); } response.setContentType("text/html"); PrintWriter writer = response.getWriter(); writer.print(jresponse); writer.flush(); }
From source file:grails.plugins.sitemapper.impl.XmlSitemapWriter.java
private void writeIndexTail(PrintWriter writer) { writer.print("</sitemapindex>"); }
From source file:grails.plugins.sitemapper.impl.XmlSitemapWriter.java
private void writeSitemapTail(PrintWriter writer) { writer.print("</urlset>"); }
From source file:grails.plugins.sitemapper.impl.XmlSitemapWriter.java
private void writeIndexHead(PrintWriter writer) { writer.print("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); writer.print("<sitemapindex xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n"); }