List of usage examples for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE
int SC_SERVICE_UNAVAILABLE
To view the source code for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE.
Click Source Link
From source file:org.energy_home.jemma.internal.ah.eh.esp.ESPServlet.java
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ServletException, IOException { String queryString = servletRequest.getRequestURI(); if (queryString.startsWith(userRegistrationUri)) { if (servletRequest.getRemoteHost().equals(remoteHostAddr)) { log.warn("service: registration uri is not accessible through vpn proxy"); servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); } else {/*from w w w. ja v a 2 s . com*/ HttpResponse response = null; try { response = restClient.get(userRegistrationGetUri); String responseUri = EntityUtils.toString(response.getEntity()); servletResponse.sendRedirect(responseUri); } catch (Exception e) { log.error("service: error while connecting to userRegistrationGetUri", e); servletResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } finally { releaseRequestResources(response); } } } else if (queryString.startsWith(authTokenUriStr)) { HttpResponse response = null; PrintWriter pw = null; try { response = restClient.get(remoteAuthTokenUri); String token = EntityUtils.toString(response.getEntity()); pw = servletResponse.getWriter(); pw.println(token); } catch (Exception e) { log.error("service: error while connecting to remoteAuthTokenUri", e); servletResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } finally { releaseRequestResources(response); if (pw != null) try { pw.close(); } catch (Exception e2) { log.error( "service: error while releasing printwriter used for connection to remoteAuthTokenUri", e2); } } } else { servletResponse.sendError(HttpServletResponse.SC_NOT_FOUND); } }
From source file:org.jahia.bin.filters.MaintenanceFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { boolean block = Jahia.isMaintenance(); if (block) {/* w ww .j a va 2 s .c o m*/ HttpServletRequest httpRequest = (HttpServletRequest) request; String uri = StringUtils.substringAfter(httpRequest.getRequestURI(), httpRequest.getContextPath()); for (Pattern resourcePattern : allowedResources) { if (resourcePattern.matcher(uri).matches()) { block = false; break; } } } if (block) { ((HttpServletResponse) response).sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, ErrorServlet.MAINTENANCE_MODE); } else { chain.doFilter(request, response); } }
From source file:com.cloudera.oryx.als.serving.web.RecommendToAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;//from w w w . ja v a 2 s . c o m } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); Pair<String[], float[]> itemIDsAndValue; try { itemIDsAndValue = parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } String[] itemIDs = itemIDsAndValue.getFirst(); float[] values = itemIDsAndValue.getSecond(); OryxRecommender recommender = getRecommender(); RescorerProvider rescorerProvider = getRescorerProvider(); try { Rescorer rescorer = rescorerProvider == null ? null : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request)); output(response, recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer)); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (IllegalArgumentException iae) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString()); } }
From source file:com.lfv.lanzius.server.InfoRequestHandler.java
/** * Handle an incoming http request and let the Velocity module create the * response from user and channel structures and xml templates located on * the server data/resources folder.// w w w . ja va2 s . co m * */ public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException { Request base_request = (request instanceof Request) ? (Request) request : HttpConnection.getCurrentConnection().getRequest(); log.debug("Incoming request: " + target); // Create a velocity context VelocityContext context = new VelocityContext(); // Get output writer PrintWriter writer = response.getWriter(); try { base_request.setHandled(true); if (target.equals("/info")) { Document doc = server.getDocument(); if (doc == null || !server.isServerStarted()) { log.warn("Trying to get info from xml server but the server is not started yet!"); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); } else { String tid_s = request.getParameter("terminal"); log.debug("Incoming info request for terminal: " + tid_s); // Lists for velocity merge List<Channel> channelList = new LinkedList<Channel>(); List<Role> roleList = new LinkedList<Role>(); synchronized (doc) { // Get Player element from PlayerSetup Element ep = DomTools.getElementFromSection(doc, "PlayerSetup", "terminalid", tid_s); if (ep != null) { int gid = DomTools.getAttributeInt(ep, "groupid", 0, true); // Names, Group and Codec context.put("TerminalName", DomTools.getChildText( DomTools.getElementFromSection(doc, "TerminalDefs", "id", tid_s), "Name", "T/" + tid_s, false)); context.put("PlayerName", DomTools.getChildText(ep, "Name", "", false)); context.put("Group", DomTools.getChildText( DomTools.getElementFromSection(doc, "GroupDefs", "id", String.valueOf(gid)), "Name", "G/" + gid, false)); context.put("Codec", DomTools.getAttributeString(doc.getRootElement(), "codec", "null", false)); // Role defs list if (roleDefsList == null) { roleDefsList = new LinkedList<Role>(); // Populate Iterator iter = doc.getRootElement().getChild("RoleDefs").getChildren().iterator(); while (iter.hasNext()) { Element er = (Element) iter.next(); int id = DomTools.getAttributeInt(er, "id", 0, false); if (id > 0) { Role r = new Role(DomTools.getChildText(er, "Name", "Withheld", false)); r.setId(id); roleDefsList.add(r); } } } context.put("RoleDefsList", roleDefsList); // Channels boolean addedMonitor = false; Element ecs = ep.getChild("ChannelSetup"); Iterator iter = ecs.getChildren().iterator(); while (iter.hasNext()) { Element ecr = (Element) iter.next(); int cid = DomTools.getAttributeInt(ecr, "id", 0, true); Element ec = DomTools.getElementFromSection(doc, "ChannelDefs", "id", String.valueOf(cid)); if (ec != null) { // Collect all attributes and textnodes into the Channel struct // with correct attribute priority: // high: Channel node under ChannelSetup // med: Channel node under ChannelDefs // low: Player (groupId) Channel ch = new Channel(DomTools.getChildText(ec, "Name", "C/" + cid, false)); // Calculate which group the channel belongs to and set client cid int gidc = DomTools.getPrioritizedAttribute("groupid", gid, ecr, ec); ch.setId((gidc << Constants.ID_BITSHIFT) | cid); // All other attrs ch.setState(DomTools.getPrioritizedAttribute("state", "off", ecr, ec)); ch.setLocked(DomTools.getPrioritizedAttribute("locked", "false", ecr, ec)); ch.setRecordable( DomTools.getPrioritizedAttribute("recordable", "false", ecr, ec)); ch.setHidden(DomTools.getPrioritizedAttribute("hidden", "false", ecr, ec)); ch.setMonitor(DomTools.getPrioritizedAttribute("monitor", "false", ecr, ec)); // Prevent duplicate monitors and monitor and state rxtx combination if (ch.getMonitor().equals("true")) { if (addedMonitor) { ch.setMonitor("false"); } else { if (ch.getState().equals("rxtx")) { ch.setState("rx"); } addedMonitor = true; } } // Show group name on channel? if (DomTools.getPrioritizedAttribute("showgroup", "false", ecr, ec) .equals("true")) { String groupName = DomTools.getChildText(DomTools.getElementFromSection(doc, "GroupDefs", "id", String.valueOf(gidc)), "Name", "G/" + gidc, false); ch.setName(groupName + "/" + ch.getName()); } channelList.add(ch); } else log.error("Missing Channel node in ChannelDefs (" + cid + ")"); } // Roles Element ers = ep.getChild("RoleSetup"); iter = ers.getChildren().iterator(); while (iter.hasNext()) { Element err = (Element) iter.next(); int rid = DomTools.getAttributeInt(err, "id", 0, false); // Empty slot if (rid == 0) { roleList.add(new Role("empty_slot")); } else { Element er = DomTools.getElementFromSection(doc, "RoleDefs", "id", String.valueOf(rid)); Role r = new Role(DomTools.getChildText(er, "Name", "R/" + rid, false)); int uid = DomTools.getAttributeInt(err, "uid", 0, true); // Debug check, calculate which group the role belongs to (already done in linkTerminal) int uidc = (DomTools.getPrioritizedAttribute("groupid", gid, err, er) << Constants.ID_BITSHIFT) | rid; if (uid != uidc) log.error("UIDs mismatch when requesting xml info (" + uid + " != " + uidc + ")"); // Set client rid r.setId(uid); // Peers List<Peer> l = r.getPeerList(); Element eps = er.getChild("PhoneSetup"); if (eps != null) { Iterator iter2 = eps.getChildren().iterator(); while (iter2.hasNext()) { Element erpr = (Element) iter2.next(); int rpid = DomTools.getAttributeInt(erpr, "id", 0, false); // Empty slot if (rpid == 0) { l.add(new Peer("empty_slot")); } else { Element erp = DomTools.getElementFromSection(doc, "RoleDefs", "id", String.valueOf(rpid)); Peer p = new Peer( DomTools.getChildText(erp, "Name", "R/" + rpid, false)); // Calculate which group the role belongs to and set client rpid int gidc = DomTools.getPrioritizedAttribute("groupid", gid, erpr, erp); p.setId((gidc << Constants.ID_BITSHIFT) | rpid); // Show group name on peer? if (DomTools .getPrioritizedAttribute("showgroup", "false", erpr, erp) .equals("true")) { String groupName = DomTools.getChildText( DomTools.getElementFromSection(doc, "GroupDefs", "id", String.valueOf(gidc)), "Name", "G/" + gidc, false); p.setName(groupName + "/" + p.getName()); } // Add to phone peer list, never add self! if (r.getId() != p.getId()) l.add(p); } } } else log.warn("Missing PhoneSetup for Role " + rid + "!"); roleList.add(r); } } } else { log.warn("Incoming info request for a terminal that does not exist (" + tid_s + ")"); context.put("Name", "Unknown"); context.put("Group", "Unknown"); context.put("Codec", "Unknown"); } } context.put("ChannelList", channelList); context.put("RoleList", roleList); userTemplate.merge(context, writer); } } else if (target.equals("/isa")) { log.debug("Received ISA request"); response.sendError(HttpServletResponse.SC_OK); int terminalId = Integer.parseInt(request.getParameter("terminal")); int value = Integer.parseInt(request.getParameter("val")); int time = Integer.parseInt(request.getParameter("t")); log.debug("ISA request, terminal = " + terminalId + ", val = " + value + ", time = " + time); server.addIsaValue(terminalId, value, time); } else response.sendError(HttpServletResponse.SC_NOT_FOUND); } catch (ResourceNotFoundException ex) { log.error("Resource not found", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (ParseErrorException ex) { log.error("Parse Error", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (MethodInvocationException ex) { log.error("Method Invocation Error", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } catch (Exception ex) { log.error("Exception in request! Correct configuration?", ex); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } writer.close(); }
From source file:org.apache.brooklyn.rest.filter.BrooklynPropertiesSecurityFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; HttpServletResponse httpResponse = (HttpServletResponse) response; String uri = httpRequest.getRequestURI(); if (provider == null) { log.warn("No security provider available: disallowing web access to brooklyn"); httpResponse.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); return;/*from www. java2 s .c o m*/ } if (originalRequest.get() != null) { // clear the entitlement context before setting to avoid warnings Entitlements.clearEntitlementContext(); } else { originalRequest.set(uri); } boolean authenticated = provider.isAuthenticated(httpRequest.getSession()); if ("/logout".equals(uri) || "/v1/logout".equals(uri)) { httpResponse.setHeader("WWW-Authenticate", "Basic realm=\"brooklyn\""); if (authenticated && httpRequest.getSession().getAttributeNames().hasMoreElements()) { logout(httpRequest); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); } else { RequestDispatcher dispatcher = httpRequest.getRequestDispatcher("/"); log.debug("Not authenticated, forwarding request for {} to {}", uri, dispatcher); dispatcher.forward(httpRequest, httpResponse); } return; } if (!(httpRequest.getSession().getAttributeNames().hasMoreElements() && provider.isAuthenticated(httpRequest.getSession())) || "/logout".equals(originalRequest.get())) { authenticated = authenticate(httpRequest); } if (!authenticated) { httpResponse.setHeader("WWW-Authenticate", "Basic realm=\"brooklyn\""); httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } // Note that the attribute AUTHENTICATED_USER_SESSION_ATTRIBUTE is only set in the call to authenticate(httpRequest), // so must not try to get the user until that is done. String uid = RequestTaggingFilter.getTag(); String user = Strings.toString(httpRequest.getSession().getAttribute(AUTHENTICATED_USER_SESSION_ATTRIBUTE)); try { WebEntitlementContext entitlementContext = new WebEntitlementContext(user, httpRequest.getRemoteAddr(), uri, uid); Entitlements.setEntitlementContext(entitlementContext); chain.doFilter(request, response); } catch (Throwable e) { if (!response.isCommitted()) { httpResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } } finally { originalRequest.remove(); Entitlements.clearEntitlementContext(); } }
From source file:org.sakaiproject.search.tool.ControllerServlet.java
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (wac == null) { wac = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext()); if (wac == null) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Cannot get WebApplicationContext"); return; }/*w w w .java2 s . com*/ } request.setAttribute(Tool.NATIVE_URL, Tool.NATIVE_URL); if (searchBeanFactory == null) { searchBeanFactory = (SearchBeanFactory) wac.getBean("search-searchBeanFactory"); ServletContext context = getServletContext(); searchBeanFactory.setContext(context); } if (sessionManager == null) { sessionManager = (SessionManager) wac.getBean(SessionManager.class.getName()); } addLocalHeaders(request); String targetURL = persistState(request); if (targetURL != null && targetURL.trim().length() > 0) { response.sendRedirect(targetURL); return; } if (TITLE_PANEL.equals(request.getParameter(PANEL))) { String targetPage = "/WEB-INF/pages/title.jsp"; RequestDispatcher rd = request.getRequestDispatcher(targetPage); rd.forward(request, response); } else { String path = request.getPathInfo(); if (path == null || path.length() == 0) { path = "/index"; } if (!path.startsWith("/")) { path = "/" + path; } String targetPage = "/WEB-INF/pages" + path + ".jsp"; request.setAttribute(SearchBeanFactory.SEARCH_BEAN_FACTORY_ATTR, searchBeanFactory); RequestDispatcher rd = request.getRequestDispatcher(targetPage); rd.forward(request, response); } request.removeAttribute(Tool.NATIVE_URL); }
From source file:com.netflix.spinnaker.fiat.controllers.RolesController.java
@RequestMapping(value = "/sync", method = RequestMethod.POST) public long sync(HttpServletResponse response, @RequestBody(required = false) List<String> specificRoles) throws IOException { if (specificRoles == null) { log.info("Full role sync invoked by web request."); long count = syncer.syncAndReturn(); if (count == 0) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "Error occurred syncing permissions. See Fiat Logs."); }// w w w.ja va2 s . c o m return count; } log.info("Web request role sync of roles: " + String.join(",", specificRoles)); Map<String, UserPermission> affectedUsers = permissionsRepository.getAllByRoles(specificRoles); if (affectedUsers.size() == 0) { log.info("No users found with specified roles"); return 0; } return syncer.updateUserPermissions(affectedUsers); }
From source file:de.mpg.escidoc.services.fledgeddata.webservice.oaiServlet.java
/** * Peform the http GET action. Note that POST is shunted to here as well. * The verb widget is taken from the request and used to invoke an * OAIVerb object of the corresponding kind to do the actual work of the verb. * * @param request the servlet's request information * @param response the servlet's response information * @exception IOException an I/O error occurred *///from w ww .ja v a 2s . com public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { boolean serviceUnavailable = isServiceUnavailable(); HashMap serverVerbs = ServerVerb.getVerbs(); request.setCharacterEncoding("UTF-8"); if (serviceUnavailable) { LOGGER.info("[FDS] oai servcice set to 'unavailable' in properties file."); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, "[FDS] Sorry. This server is down for maintenance"); } else { try { String result = getResult(request, response, serverVerbs); Writer out = getWriter(request, response); out.write(result); out.close(); } catch (OAIInternalServerError e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (SocketException e) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } catch (Throwable e) { e.printStackTrace(); response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage()); } } }
From source file:net.myrrix.web.servlets.RecommendToAnonymousServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { CharSequence pathInfo = request.getPathInfo(); if (pathInfo == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path"); return;/*from ww w . ja v a 2 s . com*/ } Iterator<String> pathComponents = SLASH.split(pathInfo).iterator(); Pair<long[], float[]> itemIDsAndValue; try { itemIDsAndValue = parseItemValuePairs(pathComponents); } catch (NoSuchElementException nsee) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString()); return; } catch (NumberFormatException nfe) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString()); return; } if (itemIDsAndValue.getFirst().length == 0) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items"); return; } long[] itemIDs = itemIDsAndValue.getFirst(); float[] values = itemIDsAndValue.getSecond(); MyrrixRecommender recommender = getRecommender(); RescorerProvider rescorerProvider = getRescorerProvider(); try { IDRescorer rescorer = rescorerProvider == null ? null : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender, getRescorerParams(request)); Iterable<RecommendedItem> recommended = recommender.recommendToAnonymous(itemIDs, values, getHowMany(request), rescorer); output(request, response, recommended); } catch (NotReadyException nre) { response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString()); } catch (NoSuchItemException nsie) { response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString()); } catch (TasteException te) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString()); getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te); } catch (IllegalArgumentException iae) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString()); } }