public static Content ok(Readable content) { return content(200, content); }
public static Status notFound() { return status(404); }
/** * Removes a property. * * @param propertyType the property type * @throws NullPointerException if the property type is null */ public <T> Response without(PropertyType<T> propertyType) throws NullPointerException { return with(propertyType, null); }
page.clear(); page.sendHeader(stream); Response.error(e).asStatus(true).streamable().send(new Stream() { public void provide(Chunk chunk) { stream.provide(chunk);
@Test public void testMimeType() throws Exception { MockApplication app = application("plugin.controller.mimetype.html").init(); MockClient client = app.client(); MockViewBridge render = client.render(); render.assertStringResponse("HELLO"); Iterable<String> mimeType = render.getResponse().getProperties().getValues(PropertyType.MIME_TYPE); assertNotNull(mimeType); Iterator<String> iterator = mimeType.iterator(); assertTrue(iterator.hasNext()); assertEquals("text/html", iterator.next()); } }
private Response redirectToHomePage() { PortalRequestContext portalRequestContext = Util.getPortalRequestContext(); HttpServletRequest currentServletRequest = portalRequestContext.getRequest(); StringBuilder sb = new StringBuilder(); sb.append(currentServletRequest.getScheme()).append("://") .append(currentServletRequest.getServerName()) .append(":").append(currentServletRequest.getServerPort()) .append("/").append(PortalContainer.getCurrentPortalContainerName()) .append("/").append(Util.getPortalRequestContext().getPortalOwner()); WebuiRequestContext ctx = WebuiRequestContext.getCurrentInstance(); JavascriptManager jsManager = ctx.getJavascriptManager(); jsManager.addJavascript("try { window.location.href='" + sb.toString() + "' } catch(e) {" + "window.location.href('" + sb.toString() + "') }"); return Response.redirect(sb.toString()); }
@Resource public Response.Content onlineFriends() { String userId = ConversationState.getCurrent().getIdentity().getUserId(); JSONArray json = getOnlineFriends(userId); return Response.ok(json.toString()).withMimeType("application/json; charset=UTF-8").withHeader("Cache-Control", "no-cache"); }
page.clear(); page.sendHeader(stream); Response.error(e).asStatus(true).streamable().send(new Stream() { public void provide(Chunk chunk) { stream.provide(chunk);
@Test public void testMimeType() throws Exception { MockApplication app = application("plugin.controller.mimetype.html").init(); MockClient client = app.client(); MockViewBridge render = client.render(); render.assertStringResponse("HELLO"); Iterable<String> mimeType = render.getResponse().getProperties().getValues(PropertyType.MIME_TYPE); assertNotNull(mimeType); Iterator<String> iterator = mimeType.iterator(); assertTrue(iterator.hasNext()); assertEquals("text/html", iterator.next()); } }
/** * return the object data contains the url of logo and the bar navigation * * @param httpContext * @return Resource */ @Ajax @Resource public Response.Content getResource(HttpContext httpContext) { JSONObject json = new JSONObject(); String style = "Dark"; if (settingService.get(Context.GLOBAL, Scope.GLOBAL, BAR_NAVIGATION_STYLE_KEY) != null) { style = (String) settingService.get(Context.GLOBAL, Scope.GLOBAL, BAR_NAVIGATION_STYLE_KEY) .getValue(); } try { json.put("error", "0"); json.put("style", style); json.put("logoUrl", getLogoUrl(httpContext, true)); } catch (JSONException ex) { if (LOG.isErrorEnabled()) { LOG.error("Can not put json value", ex); } } return Response.ok(json.toString()).with(PropertyType.MIME_TYPE, "application/json"); }
public static Content notFound(byte[] content) { return content(404, content); }
/** * Set a boolean property to true. * * @param propertyType the property type * @throws NullPointerException if the property type is null */ public Response with(PropertyType<Boolean> propertyType) throws NullPointerException { return with(propertyType, true); }
public static Status ok() { return status(200); }
@Ajax @Resource public Response saveActivePlugin(String pluginId, String inputs) { JSON data = new JSON(); try { Map<String, String> datas = parserParams(inputs); for (String channelId : datas.keySet()) { pluginSettingService.saveActivePlugin(channelId, pluginId, Boolean.valueOf(datas.get(channelId))); } data.set("status", "ok"); data.set("result", datas); } catch (Exception e) { LOG.error("Failed to save settings", e); data.set("status", "false"); data.set("error", "Exception: " + e.getMessage()); } return Response.ok(data.toString()).withMimeType("application/json"); }
public static Content notFound(CharSequence content) { return content(404, content); }
/** * Set a boolean property to false. * * @param propertyType the property type * @throws NullPointerException if the property type is null */ public Response withNo(PropertyType<Boolean> propertyType) throws NullPointerException { return with(propertyType, false); }