List of usage examples for javax.servlet.http HttpServletResponse SC_METHOD_NOT_ALLOWED
int SC_METHOD_NOT_ALLOWED
To view the source code for javax.servlet.http HttpServletResponse SC_METHOD_NOT_ALLOWED.
Click Source Link
Request-Line
is not allowed for the resource identified by the Request-URI
. From source file:org.wso2.identity.integration.test.entitlement.EntitlementSecurityTestCase.java
@Test(alwaysRun = true, description = "Test reflected XSS in XACML policy editor") public void testXSS() throws IOException { HttpGet request = new HttpGet(url); HttpResponse response = httpClient.execute(request); // If HTTP status code is 200... if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) { BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line;/*from ww w .jav a2 s . c o m*/ boolean success = false; while ((line = rd.readLine()) != null) { success = line.equals(StringEscapeUtils.escapeHtml(value)); if (success) { break; } } rd.close(); if (!success) { Assert.fail("Content is not encoded"); } } // If HTTP status code is 405... else if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_METHOD_NOT_ALLOWED) { log.info("GET request to XACML policy editor is blocked as expected"); } // If HTTP status code is neither 200 nor 405... else { log.info("Unknown response"); } }
From source file:org.dataconservancy.dcs.lineage.http.view.BaseStreamingView.java
@Override public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response) throws Exception { if (entities == null) { throw new IllegalStateException("Entities must be set first: call setEntities(List<DcsEntity>)"); }//from ww w.j av a 2s .c o m // Serialize the entities to a temporary byte array List<DcsEntity> entities = (List<DcsEntity>) model.get(ENTITIES.name()); ByteArrayOutputStream tempOut = new ByteArrayOutputStream(1024 * 4); serializeEntities(entities, tempOut); setResponseHeaders(model, response, tempOut.size()); if (request.getMethod().equalsIgnoreCase("HEAD")) { streamResponse(response, new byte[] {}); } else if (request.getMethod().equalsIgnoreCase("GET")) { streamResponse(response, tempOut.toByteArray()); } else { // catch-all, should never be invoked because this should be dealt with in the Controller. response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, request.getMethod() + " requests not allowed."); } }
From source file:com.vigglet.oei.standardinspection.CopyStandardinspectionToServiceServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:com.aipo.social.core.oauth2.AipoOAuth2Servlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpUtil.setNoCache(response);/*from www . j a v a 2 s.co m*/ String path = request.getPathInfo(); if (path.endsWith(AUTHORIZE)) { sendOAuth2Response(response, authorizationHandler.handle(request, response)); } else if (path.endsWith(TOKEN)) { // token endpoint must use POST method response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "The client MUST use the HTTP \"POST\" method " + "when making access token requests."); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown URL"); } }
From source file:org.apache.hadoop.gateway.dispatch.AbstractGatewayDispatch.java
public void doGet(URI url, HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:org.jboss.as.test.integration.web.security.servlet.methods.DenyUncoveredHttpMethodsTestCase.java
@Test public void testTraceMethod() throws Exception { HttpTrace httpTrace = new HttpTrace(getURL()); HttpResponse response = getHttpResponse(httpTrace); assertThat(statusCodeOf(response), is(HttpServletResponse.SC_METHOD_NOT_ALLOWED)); }
From source file:org.apache.hadoop.gateway.dispatch.AbstractGatewayDispatch.java
public void doPost(URI url, HttpServletRequest request, HttpServletResponse response) throws IOException, URISyntaxException { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); }
From source file:org.openmrs.module.hl7query.web.controller.BaseHL7QueryController.java
@ExceptionHandler(Exception.class) @ResponseBody/*from www . j a v a 2s .c o m*/ private AuthenticationErrorObject handleException(Exception ex, HttpServletResponse response) throws Exception { ResponseStatus ann = ex.getClass().getAnnotation(ResponseStatus.class); if (ann != null) { errorCode = ann.value().value(); if (StringUtils.isNotEmpty(ann.reason())) { errorDetail = ann.reason(); } } else if (ExceptionUtil.hasCause(ex, APIAuthenticationException.class)) { return apiAuthenticationExceptionHandler(ex, response); } else if (ex.getClass() == HttpRequestMethodNotSupportedException.class) { errorCode = HttpServletResponse.SC_METHOD_NOT_ALLOWED; } response.setStatus(errorCode); return ExceptionUtil.wrapErrorResponse(ex, errorDetail); }
From source file:io.github.gsteckman.rpi_rest.SubscriptionManager.java
/** * Processes a UPnP SUBSCRIBE request and creates or renews a subscription. * //from ww w . j ava 2 s .c o m * @param key * The key identifies the resource to which this subscription applies. * @param req * Subscription request * @param res * Response to the subscription request * @throws IOException * Thrown by HttpServletResponse.sendError if an error occurs writing the response. */ public void processSubscribe(String key, HttpServletRequest req, HttpServletResponse res) throws IOException { String timeoutHdr = req.getHeader("TIMEOUT"); String callbackHdr = req.getHeader("CALLBACK"); String sidHdr = req.getHeader("SID"); List<URL> callbackUrls = new LinkedList<URL>(); // Perform error checking: // 1. Method must be SUBSCRIBE // 2. If no SID header // a. CALLBACK header must be present & properly formatted as a correct URL // b. NT header must be present with a value of "upnp:event" // 3. If there is a SID header, CALLBACK and NT headers not present if (!"SUBSCRIBE".equalsIgnoreCase(req.getMethod())) { // Return 405 status res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "Method " + req.getMethod() + " not allowed for this resource."); return; } if (sidHdr != null && (timeoutHdr != null || callbackHdr != null)) { res.sendError(HttpServletResponse.SC_BAD_REQUEST, "An SID header field and one of NT or CALLBACK header fields are present."); return; } else { if (callbackHdr == null) { // CALLBACK is a required header. Return status 412 res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "CALLBACK header is missing."); return; } else { // parse callback header and ensure proper format callbackUrls = parseCallbackHeader(callbackHdr); if (callbackUrls.size() == 0) { res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "CALLBACK header doesn't contain a valid HTTP URL."); return; } } if (!"upnp:event".equals(req.getHeader("NT"))) { // NT is a required header. Return status 412 res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "NT header field does not equal upnp:event."); return; } } // parse timeout header long timeout = DEFAULT_TIMEOUT; try { timeout = Long.parseLong(timeoutHdr.substring(7)) * 1000; } catch (NumberFormatException e) { // ignore, use default LOG.info("Using default timeout", e); } // check if new subscription or a renewal if (sidHdr != null) { // subscription renewal Map<UUID, SubscriptionInfo> m = subscriptions.get(key); if (m == null) { res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "SID doesn't correspond to a known subscription."); return; } // parse SID String ss = sidHdr.substring(5).trim(); UUID sid = new UUID(ss); SubscriptionInfo si = m.get(sid); if (si == null) { res.sendError(HttpServletResponse.SC_PRECONDITION_FAILED, "SID doesn't correspond to a known subscription."); return; } si.renew(timeout); } else { // new subscription // create subscription identifier UUID sid = new UUID(); addSubscription(key, sid, new SubscriptionInfo(sid, timeout, callbackUrls)); // Create response res.setStatus(HttpServletResponse.SC_OK); res.addHeader("SERVER", System.getProperty("os.name") + "/" + System.getProperty("os.version") + ", UPnP/1.1, rpi-rest/0.1"); res.addHeader("SID", "uuid:" + sid.toString()); res.addHeader("TIMEOUT", "Second-" + (timeout / 1000)); } }
From source file:edu.iu.incntre.flowscalehttplistener.HttpListener.java
@Override /** //w ww .j a v a 2 s . c om * method will call other other methods based on the Http Message most * methods call other bundles */ public void handle(String arg0, HttpServletRequest request, HttpServletResponse response, int arg3) throws IOException, ServletException { // TODO Auto-generated method stub logger.debug("http request received"); logger.debug("request header type is {}", request.getMethod()); Request base_request = (request instanceof Request) ? (Request) request : HttpConnection.getCurrentConnection().getRequest(); base_request.setHandled(true); response.setContentType("text/html;charset=utf-8"); String output = ""; JSONObject obj; if (request.getMethod() != "GET") { response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); obj = new JSONObject(); obj.put("success", 0); obj.put("error", "method not allowed"); response.getWriter().print(obj); return; } String requestAction = request.getHeader("action"); logger.debug("action is {}", requestAction); if (requestAction.equals("getSwitchStatus")) { } else if (requestAction.equals("getSwitchPorts")) { long datapathId = HexString.toLong(request.getHeader("datapathId")); if (flowscaleController.getSwitchDevices().get(datapathId) == null) { logger.error("Switch {} is not connected to the controller ", HexString.toHexString(datapathId)); output = ""; } else { List<OFPhysicalPort> portList = flowscaleController.getSwitchDevices().get(datapathId) .getPortStates(); if (portList == null) { logger.error("no switch connected yet "); } else { output = JSONConverter.toPortStatus(portList).toJSONString(); } } } else if (requestAction.equals("addSwitch")) { logger.debug(("action is to add Switch")); flowscaleController.addSwitchFromInterface(request.getHeader("datapathId")); } else if (requestAction.equals("removeSwitch")) { flowscaleController.removeSwitchFromInterface(request.getHeader("datapathId")); } else if (requestAction.equals("addGroup")) { // get all values for the grouop String groupIdString = request.getHeader("groupId"); String groupName = request.getHeader("groupName"); String inputSwitchDatapathIdString = request.getHeader("inputSwitch"); String outputSwitchDatapathIdString = request.getHeader("outputSwitch"); String inputPortListString = request.getHeader("inputPorts"); String outputPortListString = request.getHeader("outputPorts"); String typeString = request.getHeader("type"); String priorityString = request.getHeader("priority"); String valuesString = request.getHeader("values"); String maximumFlowsAllowedString = request.getHeader("maximumFlowsAllowed"); String networkProtocolString = request.getHeader("networkProtocol"); String transportDestinationString = request.getHeader("transportDirection"); // end get all values for the gorup output = flowscaleController.addGroupFromInterface(groupIdString, groupName, inputSwitchDatapathIdString, outputSwitchDatapathIdString, inputPortListString, outputPortListString, typeString, priorityString, valuesString, maximumFlowsAllowedString, networkProtocolString, transportDestinationString); } else if (requestAction.equals("editGroup")) { String groupIdString = request.getHeader("groupId"); String editTypeString = request.getHeader("editType"); String updateValueString = request.getHeader("updateValue"); flowscaleController.editGroupFromInterface(groupIdString, editTypeString, updateValueString); // parse command , // the right methods } else if (requestAction.equals("deleteGroup")) { logger.debug("group id is {}", request.getHeader("groupId")); flowscaleController.deleteGroupFromInterface(request.getHeader("groupId")); } else if (requestAction.equals("getSwitchStatistics")) { try { List<OFStatistics> ofs = flowscaleController.getSwitchStatisticsFromInterface( request.getHeader("datapathId"), request.getHeader("type")); output = JSONConverter.toStat(ofs, request.getHeader("type")).toJSONString(); } catch (NoSwitchException e) { // TODO Auto-generated catch block logger.error("Switch is not connected", e); } catch (InterruptedException e) { // TODO Auto-generated catch block logger.error("Thread Interrupted {}", e); } catch (ExecutionException e) { // TODO Auto-generated catch block logger.error("Execution Aborted {}", e); } catch (TimeoutException e) { logger.error("Request to switch timed out"); } } else if (requestAction.equals("sensorUpdate")) { String datapathIdString = request.getHeader("datapathId"); String sensorIdString = request.getHeader("sensorId"); String updateStatus = request.getHeader("updateStatus"); logger.info("datapathId {} sensorId {}", datapathIdString, sensorIdString); logger.info("update status {}", updateStatus); try { SwitchDevice switchDevice = flowscaleController.getSwitchDevices() .get(HexString.toLong(datapathIdString)); IOFSwitch sw = switchDevice.getOpenFlowSwitch(); List<OFPhysicalPort> switchPorts = switchDevice.getPortStates(); OFPhysicalPort updatedPort = null; for (OFPhysicalPort ofPort : switchPorts) { if (ofPort.getPortNumber() == Short.parseShort(sensorIdString)) { updatedPort = ofPort; break; } } updatedPort.setConfig(0); OFPortMod portMod = new OFPortMod(); if (updateStatus.equals("down")) { portMod.setConfig(OFPhysicalPort.OFPortConfig.OFPPC_PORT_DOWN.getValue()); } else if (updateStatus.equals("up")) { portMod.setConfig(0); } portMod.setMask(1); portMod.setPortNumber(updatedPort.getPortNumber()); portMod.setHardwareAddress(updatedPort.getHardwareAddress()); portMod.setType(OFType.PORT_MOD); sw.getOutputStream().write(portMod); sw.getOutputStream().flush(); obj = new JSONObject(); obj.put("result", "success"); obj.put("desc", "sensor " + sensorIdString + " marked as " + updateStatus + " on switch " + datapathIdString); response.getWriter().print(obj); } catch (Exception e) { logger.error("{}", e); obj = new JSONObject(); obj.put("result", "failure"); obj.put("desc", e.toString()); response.getWriter().print(obj); } } response.setStatus(HttpServletResponse.SC_OK); logger.debug("response output {}", output); response.getWriter().print(output); }