List of usage examples for org.springframework.http HttpMethod equals
public boolean equals(Object obj)
From source file:com.flipkart.poseidon.api.APIApplication.java
@Override public void handleRequest(PoseidonRequest request, PoseidonResponse response) throws ElementNotFoundException, BadRequestException, ProcessingException, InternalErrorException { HttpMethod method = request.getAttribute(RequestConstants.METHOD); boolean handled = false; if (method != null && method.equals(HttpMethod.OPTIONS)) { handled = handleOptionsRequest(request, response); }// ww w. ja v a 2s. c o m if (!handled) { // Ideally, we have to get the buildable for this request, get // API name from the buildable and use it to start a meter here. // As getting a buildable could be time consuming (say we use trie // instead of a map as in APIBuildable), we start a meter in // APILegoSet.getBuildable() and stop it here try { lego.buildResponse(request, response); } finally { Object timerContext = request.getAttribute(TIMER_CONTEXT); if (timerContext != null && timerContext instanceof Timer.Context) { ((Timer.Context) timerContext).stop(); } } } }
From source file:de.zib.gndms.gndmc.dspace.test.MockRestTemplate.java
/** * Checks if the given HTTP method is allowed to be executed on the given url. * /*from ww w. jav a 2 s .c om*/ * @param url The url the method shall be executed. * @param method The HTTP method. * @return true, if the method can be executed on the url, else false. */ private boolean validUrlMethod(final String url, final HttpMethod method) { if (url.matches(serviceURL + "/dspace")) { if (method.equals(HttpMethod.GET)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+")) { if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/config")) { if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/slicekinds")) { if (method.equals(HttpMethod.GET)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+")) { if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE) || method.equals(HttpMethod.POST)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+")) { if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE) || method.equals(HttpMethod.POST)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+/files")) { if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.DELETE)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+/gsiftp")) { if (method.equals(HttpMethod.GET)) { return true; } } if (url.matches(serviceURL + "/dspace/_\\w+/_\\w+/_\\w+/_\\w+")) { if (method.equals(HttpMethod.GET) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.DELETE)) { return true; } } return false; }
From source file:org.alfresco.rest.framework.core.ResourceInspector.java
/** * Determines if the resources supports the resource action specified by resourceInterfaceWithOneMethod * @param resourceInterfaceWithOneMethod The resource action * @param httpMethod http method the action supports. * @param helper Holder of simple meta data *///from w ww. j a v a 2 s. c o m private static void findOperation(Class<? extends ResourceAction> resourceInterfaceWithOneMethod, HttpMethod httpMethod, MetaHelperCallback helper) { if (resourceInterfaceWithOneMethod.isAssignableFrom(helper.resource)) { Method aMethod = findMethod(resourceInterfaceWithOneMethod, helper.resource); ResourceOperation operation = inspectOperation(helper.resource, aMethod, httpMethod); if (isDeleted(aMethod)) { helper.whenOperationDeleted(resourceInterfaceWithOneMethod, aMethod); } else { helper.whenNewOperation(operation, aMethod); } if (isNoAuth(aMethod)) { if (!(httpMethod.equals(HttpMethod.GET) || httpMethod.equals(HttpMethod.POST))) { throw new IllegalArgumentException("@WebApiNoAuth should only be on GET methods: " + operation.getTitle() + " Or POST method for creating a ticket."); } helper.whenOperationNoAuth(resourceInterfaceWithOneMethod, aMethod); } } }
From source file:org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService.java
@Override protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler, String sessionId, String transport) throws SockJsException { TransportType transportType = TransportType.fromValue(transport); if (transportType == null) { logger.error("Unknown transport type for " + request.getURI()); response.setStatusCode(HttpStatus.NOT_FOUND); return;//from w w w . j a v a2 s . c o m } TransportHandler transportHandler = this.handlers.get(transportType); if (transportHandler == null) { logger.error("No TransportHandler for " + request.getURI()); response.setStatusCode(HttpStatus.NOT_FOUND); return; } HttpMethod supportedMethod = transportType.getHttpMethod(); if (!supportedMethod.equals(request.getMethod())) { if (HttpMethod.OPTIONS.equals(request.getMethod()) && transportType.supportsCors()) { response.setStatusCode(HttpStatus.NO_CONTENT); addCorsHeaders(request, response, HttpMethod.OPTIONS, supportedMethod); addCacheHeaders(response); } else if (transportType.supportsCors()) { sendMethodNotAllowed(response, supportedMethod, HttpMethod.OPTIONS); } else { sendMethodNotAllowed(response, supportedMethod); } return; } HandshakeInterceptorChain chain = new HandshakeInterceptorChain(this.interceptors, handler); SockJsException failure = null; try { SockJsSession session = this.sessions.get(sessionId); if (session == null) { if (transportHandler instanceof SockJsSessionFactory) { Map<String, Object> attributes = new HashMap<String, Object>(); if (!chain.applyBeforeHandshake(request, response, attributes)) { return; } SockJsSessionFactory sessionFactory = (SockJsSessionFactory) transportHandler; session = createSockJsSession(sessionId, sessionFactory, handler, attributes); } else { response.setStatusCode(HttpStatus.NOT_FOUND); if (logger.isDebugEnabled()) { logger.debug( "Session not found, sessionId=" + sessionId + ". The session may have been closed " + "(e.g. missed heart-beat) while a message was coming in."); } return; } } if (transportType.sendsNoCacheInstruction()) { addNoCacheHeaders(response); } if (transportType.supportsCors()) { addCorsHeaders(request, response); } transportHandler.handleRequest(request, response, handler, session); chain.applyAfterHandshake(request, response, null); } catch (SockJsException ex) { failure = ex; } catch (Throwable ex) { failure = new SockJsException("Uncaught failure for request " + request.getURI(), sessionId, ex); } finally { if (failure != null) { chain.applyAfterHandshake(request, response, failure); throw failure; } } }