@Deprecated public DefaultHttpBinding(HttpCommonEndpoint endpoint) { this.headerFilterStrategy = endpoint.getHeaderFilterStrategy(); this.transferException = endpoint.isTransferException(); if (endpoint.getComponent() != null) { this.allowJavaSerializedObject = endpoint.getComponent().isAllowJavaSerializedObject(); } }
@Override public Map<String, String> getServiceProperties() { return CollectionHelper.immutableMapOf( ServiceDefinition.SERVICE_META_PORT, Integer.toString(getPort()), ServiceDefinition.SERVICE_META_PATH, getPath(), ServiceDefinition.SERVICE_META_PROTOCOL, getProtocol() ); }
public HttpConsumer(HttpCommonEndpoint endpoint, Processor processor) { super(endpoint, processor); if (endpoint.isTraceEnabled()) { setTraceEnabled(true); } if (endpoint.isOptionsEnabled()) { setOptionsEnabled(true); } }
if (consumer.getEndpoint().isSuspended()) { log.debug("Consumer suspended, cannot service request {}", request); response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE); if (consumer.getEndpoint().getHttpMethodRestrict() != null && !consumer.getEndpoint().getHttpMethodRestrict().equals(request.getMethod())) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; if ("TRACE".equals(request.getMethod()) && !consumer.getEndpoint().isTraceEnabled()) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; if (consumer.getEndpoint().isBridgeEndpoint()) { exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE); if (consumer.getEndpoint().isDisableStreamCache()) { exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE); exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response)); String contextPath = consumer.getEndpoint().getPath(); exchange.getIn().setHeader("CamelServletContextPath", contextPath); Integer bs = consumer.getEndpoint().getResponseBufferSize(); if (bs != null) { log.trace("Using response buffer size: {}", bs);
if (allowedMethods == null && consumer.getEndpoint().getHttpMethodRestrict() != null) { allowedMethods = consumer.getEndpoint().getHttpMethodRestrict(); if (consumer.getEndpoint().getHttpMethodRestrict() != null && !consumer.getEndpoint().getHttpMethodRestrict().contains(request.getMethod())) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; Exchange exchange = consumer.getEndpoint().createExchange(ExchangePattern.InOut); if (consumer.getEndpoint().isBridgeEndpoint()) { exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE); exchange.setProperty(Exchange.SKIP_WWW_FORM_URLENCODED, Boolean.TRUE); if (consumer.getEndpoint().isDisableStreamCache()) { exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE); exchange.setIn(new HttpMessage(exchange, consumer.getEndpoint(), request, response)); String contextPath = consumer.getEndpoint().getPath(); exchange.getIn().setHeader("CamelServletContextPath", contextPath); log.trace("Writing response for exchangeId: {}", exchange.getExchangeId()); Integer bs = consumer.getEndpoint().getResponseBufferSize(); if (bs != null) { log.trace("Using response buffer size: {}", bs);
public HttpBinding getHttpBinding() { if (httpBinding == null) { // create a new binding and use the options from this endpoint httpBinding = new DefaultHttpBinding(); httpBinding.setHeaderFilterStrategy(getHeaderFilterStrategy()); httpBinding.setTransferException(isTransferException()); if (getComponent() != null) { httpBinding.setAllowJavaSerializedObject(getComponent().isAllowJavaSerializedObject()); } httpBinding.setEagerCheckContentAvailable(isEagerCheckContentAvailable()); httpBinding.setMapHttpMessageBody(isMapHttpMessageBody()); httpBinding.setMapHttpMessageHeaders(isMapHttpMessageHeaders()); httpBinding.setMapHttpMessageFormUrlEncodedBody(isMapHttpMessageFormUrlEncodedBody()); } return httpBinding; }
@Override public String getRestrictMethod() { return consumer.getEndpoint().getHttpMethodRestrict(); }
@Override public boolean isMatchOnUriPrefix() { return consumer.getEndpoint().isMatchOnUriPrefix(); }
if (uri == null && !(endpoint.isBridgeEndpoint())) { uri = exchange.getIn().getHeader(Exchange.HTTP_URI, String.class); uri = endpoint.getHttpUri().toASCIIString();
@Override public void setHttpBinding(HttpBinding binding) { super.setHttpBinding(binding); this.binding = binding; }
@Override public ServletComponent getComponent() { return (ServletComponent) super.getComponent(); }
public String getPath() { return getEndpoint().getPath(); }
protected HttpConsumer doResolve(HttpServletRequest request, String method, Map<String, HttpConsumer> consumers) { String path = request.getPathInfo(); if (path == null) { return null; } HttpConsumer answer = consumers.get(path); List<HttpConsumer> candidates = resolveCandidates(request, method, consumers); // extra filter by restrict candidates = candidates.stream().filter(c -> matchRestMethod(method, c.getEndpoint().getHttpMethodRestrict())).collect(Collectors.toList()); if (candidates.size() == 1) { answer = candidates.get(0); } return answer; }
@Override protected HttpConsumer resolve(HttpServletRequest request) { String path = request.getPathInfo(); log.trace("Request path is: {}", path); String endpointName = getEndpointNameFromPath(path); log.trace("Looking up consumer for endpoint: {}", endpointName); HttpConsumer answer = consumers.get(endpointName); if (answer == null) { if (LOGGER.isDebugEnabled()) { log.debug("Consumer Keys: {}", consumers.keySet()); } for (Entry<String, HttpConsumer> entry : consumers.entrySet()) { if (entry.getValue().getEndpoint().isMatchOnUriPrefix() && path.startsWith(entry.getKey())) { answer = consumers.get(entry.getKey()); break; } } } return answer; }
/** * @deprecated use {@link #setHttpBinding(HttpBinding)} */ @Deprecated public void setBinding(HttpBinding httpBinding) { setHttpBinding(httpBinding); }
if (consumer.getEndpoint().getHttpMethodRestrict() != null && !consumer.getEndpoint().getHttpMethodRestrict().equals(request.getMethod())) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return;
private List<HttpConsumer> resolveCandidates(HttpServletRequest request, String method, Map<String, HttpConsumer> consumers) { String path = request.getPathInfo(); List<HttpConsumer> candidates = new ArrayList<>(); for (String key : consumers.keySet()) { //We need to look up the consumer path here String consumerPath = consumers.get(key).getPath(); HttpConsumer consumer = consumers.get(key); boolean matchOnUriPrefix = consumer.getEndpoint().isMatchOnUriPrefix(); // Just make sure the we get the right consumer path first if (RestConsumerContextPathMatcher.matchPath(path, consumerPath, matchOnUriPrefix)) { candidates.add(consumer); } } return candidates; }