use of org.eclipse.jetty.servlets.MultiPartFilter in project camel by apache.
the class JettyHttpComponent method enableMultipartFilter.
private void enableMultipartFilter(HttpCommonEndpoint endpoint, Server server, String connectorKey) throws Exception {
ServletContextHandler context = server.getChildHandlerByClass(ServletContextHandler.class);
CamelContext camelContext = this.getCamelContext();
FilterHolder filterHolder = new FilterHolder();
filterHolder.setInitParameter("deleteFiles", "true");
if (ObjectHelper.isNotEmpty(camelContext.getProperty(TMP_DIR))) {
File file = new File(camelContext.getProperty(TMP_DIR));
if (!file.isDirectory()) {
throw new RuntimeCamelException("The temp file directory of camel-jetty is not exists, please recheck it with directory name :" + camelContext.getProperties().get(TMP_DIR));
}
context.setAttribute("javax.servlet.context.tempdir", file);
}
// if a filter ref was provided, use it.
Filter filter = ((JettyHttpEndpoint) endpoint).getMultipartFilter();
if (filter == null) {
// if no filter ref was provided, use the default filter
filter = new MultiPartFilter();
}
filterHolder.setFilter(new CamelFilterWrapper(filter));
String pathSpec = endpoint.getPath();
if (pathSpec == null || "".equals(pathSpec)) {
pathSpec = "/";
}
if (endpoint.isMatchOnUriPrefix()) {
pathSpec = pathSpec.endsWith("/") ? pathSpec + "*" : pathSpec + "/*";
}
addFilter(context, filterHolder, pathSpec);
LOG.debug("using multipart filter implementation " + filter.getClass().getName() + " for path " + pathSpec);
}
use of org.eclipse.jetty.servlets.MultiPartFilter in project camel by apache.
the class JettyHttpComponent method createEndpoint.
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
// must extract well known parameters before we create the endpoint
List<Handler> handlerList = resolveAndRemoveReferenceListParameter(parameters, "handlers", Handler.class);
HttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "httpBindingRef", HttpBinding.class);
JettyHttpBinding jettyBinding = resolveAndRemoveReferenceParameter(parameters, "jettyHttpBindingRef", JettyHttpBinding.class);
Boolean enableJmx = getAndRemoveParameter(parameters, "enableJmx", Boolean.class);
Boolean enableMultipartFilter = getAndRemoveParameter(parameters, "enableMultipartFilter", Boolean.class, true);
Filter multipartFilter = resolveAndRemoveReferenceParameter(parameters, "multipartFilterRef", Filter.class);
List<Filter> filters = resolveAndRemoveReferenceListParameter(parameters, "filtersRef", Filter.class);
Boolean enableCors = getAndRemoveParameter(parameters, "enableCORS", Boolean.class, false);
HeaderFilterStrategy headerFilterStrategy = resolveAndRemoveReferenceParameter(parameters, "headerFilterStrategy", HeaderFilterStrategy.class);
UrlRewrite urlRewrite = resolveAndRemoveReferenceParameter(parameters, "urlRewrite", UrlRewrite.class);
SSLContextParameters sslContextParameters = resolveAndRemoveReferenceParameter(parameters, "sslContextParametersRef", SSLContextParameters.class);
SSLContextParameters ssl = sslContextParameters != null ? sslContextParameters : this.sslContextParameters;
String proxyHost = getAndRemoveParameter(parameters, "proxyHost", String.class, getProxyHost());
Integer proxyPort = getAndRemoveParameter(parameters, "proxyPort", Integer.class, getProxyPort());
Integer httpClientMinThreads = getAndRemoveParameter(parameters, "httpClientMinThreads", Integer.class, this.httpClientMinThreads);
Integer httpClientMaxThreads = getAndRemoveParameter(parameters, "httpClientMaxThreads", Integer.class, this.httpClientMaxThreads);
HttpClient httpClient = resolveAndRemoveReferenceParameter(parameters, "httpClient", HttpClient.class);
Boolean async = getAndRemoveParameter(parameters, "async", Boolean.class);
// extract httpClient. parameters
Map<String, Object> httpClientParameters = IntrospectionSupport.extractProperties(parameters, "httpClient.");
// extract filterInit. parameters
Map<String, String> filterInitParameters = IntrospectionSupport.extractStringProperties(IntrospectionSupport.extractProperties(parameters, "filterInit."));
String address = remaining;
URI addressUri = new URI(UnsafeUriCharactersEncoder.encodeHttpURI(address));
URI endpointUri = URISupport.createRemainingURI(addressUri, parameters);
// need to keep the httpMethodRestrict parameter for the endpointUri
String httpMethodRestrict = getAndRemoveParameter(parameters, "httpMethodRestrict", String.class);
// restructure uri to be based on the parameters left as we dont want to include the Camel internal options
URI httpUri = URISupport.createRemainingURI(addressUri, parameters);
// create endpoint after all known parameters have been extracted from parameters
// include component scheme in the uri
String scheme = ObjectHelper.before(uri, ":");
endpointUri = new URI(scheme + ":" + endpointUri);
JettyHttpEndpoint endpoint = createEndpoint(endpointUri, httpUri);
if (async != null) {
endpoint.setAsync(async);
}
if (headerFilterStrategy != null) {
endpoint.setHeaderFilterStrategy(headerFilterStrategy);
} else {
setEndpointHeaderFilterStrategy(endpoint);
}
// setup the proxy host and proxy port
if (proxyHost != null) {
endpoint.setProxyHost(proxyHost);
endpoint.setProxyPort(proxyPort);
}
if (urlRewrite != null) {
// let CamelContext deal with the lifecycle of the url rewrite
// this ensures its being shutdown when Camel shutdown etc.
getCamelContext().addService(urlRewrite);
endpoint.setUrlRewrite(urlRewrite);
}
if (httpClientParameters != null && !httpClientParameters.isEmpty()) {
endpoint.setHttpClientParameters(httpClientParameters);
}
if (filterInitParameters != null && !filterInitParameters.isEmpty()) {
endpoint.setFilterInitParameters(filterInitParameters);
}
if (handlerList.size() > 0) {
endpoint.setHandlers(handlerList);
}
// prefer to use endpoint configured over component configured
if (binding == null) {
// fallback to component configured
binding = getHttpBinding();
}
if (binding != null) {
endpoint.setBinding(binding);
}
// prefer to use endpoint configured over component configured
if (jettyBinding == null) {
// fallback to component configured
jettyBinding = getJettyHttpBinding();
}
if (jettyBinding != null) {
endpoint.setJettyBinding(jettyBinding);
}
if (enableJmx != null) {
endpoint.setEnableJmx(enableJmx);
} else {
// set this option based on setting of JettyHttpComponent
endpoint.setEnableJmx(isEnableJmx());
}
endpoint.setEnableMultipartFilter(enableMultipartFilter);
if (multipartFilter != null) {
endpoint.setMultipartFilter(multipartFilter);
endpoint.setEnableMultipartFilter(true);
}
if (enableCors) {
endpoint.setEnableCORS(enableCors);
if (filters == null) {
filters = new ArrayList<Filter>(1);
}
filters.add(new CrossOriginFilter());
}
if (filters != null) {
endpoint.setFilters(filters);
}
if (httpMethodRestrict != null) {
endpoint.setHttpMethodRestrict(httpMethodRestrict);
}
if (ssl != null) {
endpoint.setSslContextParameters(ssl);
}
if (httpClientMinThreads != null) {
endpoint.setHttpClientMinThreads(httpClientMinThreads);
}
if (httpClientMaxThreads != null) {
endpoint.setHttpClientMaxThreads(httpClientMaxThreads);
}
if (httpClient != null) {
endpoint.setHttpClient(httpClient);
}
endpoint.setSendServerVersion(isSendServerVersion());
setProperties(endpoint, parameters);
// re-create http uri after all parameters has been set on the endpoint, as the remainders are for http uri
httpUri = URISupport.createRemainingURI(addressUri, parameters);
endpoint.setHttpUri(httpUri);
return endpoint;
}
Aggregations