List of usage examples for io.netty.handler.codec.http HttpMethod equals
@Override public boolean equals(Object o)
From source file:org.waarp.gateway.kernel.rest.HttpRestHandler.java
License:Open Source License
/** * Create the decoder/*from w w w .ja v a 2s. com*/ * * @throws HttpIncorrectRequestException */ protected void createDecoder() throws HttpIncorrectRequestException { HttpMethod method = request.method(); if (!method.equals(HttpMethod.HEAD)) { // in order decoder allows to parse request.setMethod(HttpMethod.POST); } try { decoder = new HttpPostRequestDecoder(factory, request); } catch (ErrorDataDecoderException e1) { status = HttpResponseStatus.NOT_ACCEPTABLE; throw new HttpIncorrectRequestException(e1); } catch (Exception e1) { // GETDOWNLOAD Method: should not try to create a HttpPostRequestDecoder // So OK but stop here status = HttpResponseStatus.NOT_ACCEPTABLE; throw new HttpIncorrectRequestException(e1); } }
From source file:org.wso2.carbon.mss.internal.router.HttpResourceHandler.java
License:Open Source License
/** * Get HttpResourceModel which matches the HttpMethod of the request. * * @param routableDestinations List of ResourceModels. * @param targetHttpMethod HttpMethod. * @param requestUri request URI. * @return RoutableDestination that matches httpMethod that needs to be handled. null if there are no matches. *///from w ww .jav a 2s.com private List<PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel>> getMatchedDestination( List<PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel>> routableDestinations, HttpMethod targetHttpMethod, String requestUri) { Iterable<String> requestUriParts = Splitter.on('/').omitEmptyStrings().split(requestUri); List<PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel>> matchedDestinations = Lists .newArrayListWithExpectedSize(routableDestinations.size()); int maxExactMatch = 0; int maxGroupMatch = 0; int maxPatternLength = 0; for (PatternPathRouterWithGroups.RoutableDestination<HttpResourceModel> destination : routableDestinations) { HttpResourceModel resourceModel = destination.getDestination(); int groupMatch = destination.getGroupNameValues().size(); for (HttpMethod httpMethod : resourceModel.getHttpMethod()) { if (targetHttpMethod.equals(httpMethod)) { int exactMatch = getExactPrefixMatchCount(requestUriParts, Splitter.on('/').omitEmptyStrings().split(resourceModel.getPath())); // When there are multiple matches present, the following precedence order is used - // 1. template path that has highest exact prefix match with the url is chosen. // 2. template path has the maximum groups is chosen. // 3. finally, template path that has the longest length is chosen. if (exactMatch > maxExactMatch) { maxExactMatch = exactMatch; maxGroupMatch = groupMatch; maxPatternLength = resourceModel.getPath().length(); matchedDestinations.clear(); matchedDestinations.add(destination); } else if (exactMatch == maxExactMatch && groupMatch >= maxGroupMatch) { if (groupMatch > maxGroupMatch || resourceModel.getPath().length() > maxPatternLength) { maxGroupMatch = groupMatch; maxPatternLength = resourceModel.getPath().length(); matchedDestinations.clear(); } matchedDestinations.add(destination); } } } } return matchedDestinations; }
From source file:reactor.ipc.netty.http.client.HttpClientFormEncoder.java
License:Open Source License
/** * @param factory the factory used to create InterfaceHttpData * @param request the request to encode/*from w w w . j a va 2 s . co m*/ * @param multipart True if the FORM is a ENCTYPE="multipart/form-data" * @param charset the charset to use as default * @param encoderMode the mode for the encoder to use. See {@link EncoderMode} for the * details. * * @throws NullPointerException for request or charset or factory * @throws ErrorDataEncoderException if the request is not a POST */ HttpClientFormEncoder(HttpDataFactory factory, HttpRequest request, boolean multipart, Charset charset, EncoderMode encoderMode) throws ErrorDataEncoderException { if (factory == null) { throw new NullPointerException("factory"); } if (request == null) { throw new NullPointerException("request"); } if (charset == null) { throw new NullPointerException("charset"); } HttpMethod method = request.method(); if (!(method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT) || method.equals(HttpMethod.PATCH) || method.equals(HttpMethod.OPTIONS))) { throw new ErrorDataEncoderException("Cannot create a Encoder if not a POST"); } this.request = request; this.charset = charset; this.newCharset = charset; this.factory = factory; this.progressFlux = DirectProcessor.create(); this.cleanOnTerminate = true; this.newMode = encoderMode; this.newMultipart = multipart; // Fill default values bodyListDatas = new ArrayList<>(); // default mode isLastChunk = false; isLastChunkSent = false; isMultipart = multipart; multipartHttpDatas = new ArrayList<>(); this.encoderMode = encoderMode; if (isMultipart) { initDataMultipart(); } }