[ https://issues.apache.org/jira/browse/CAMEL-3779?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13005614#comment-13005614 ]
ben commented on CAMEL-3779: ---------------------------- Hi Claus, thanks for your prompt answer. In the meantime, I found the following work around: I wrote a small ProcessorBean that simply creates the HTTP Authorization Header and stores HTTP Authorization Header in the message header: {code} final String userPassword = "foo" + ":" + "bar"; final byte[] encodeBase64 = Base64.encodeBase64(userPassword.getBytes()); final String encoding = new String(encodeBase64); final String authParameter = "Basic " + encoding; msg.setHeader("Authorization", authParameter);{code} This solution works with camel-http and camel-http4, because both implementations of the HttpProducer, the Header information of the message is passed through request, see HttpProducer.java from camel-http4 in the lines 87-93: {code} // propagate headers as HTTP headers for (Map.Entry<String, Object> entry : in.getHeaders().entrySet()) { String headerValue = in.getHeader(entry.getKey(), String.class); if (strategy != null && !strategy.applyFilterToCamelHeaders(entry.getKey(), headerValue, exchange)) { method.addRequestHeader(entry.getKey(), headerValue); } } {code} The route is now: {code} <route> <from uri="file:///tmp/files_to_retrieve/" /> <method bean="prepareDownLoadUri" method="parseIndexHtml" /> <!-- provide the HTTP auth. scheme --> <to uri="authorizeWebRequestProcessor" /> <to uri="http4://download.acme.com/" /> <to uri="bean:saveFileProcessor" /> </route> <bean id="prepareDownLoadUri" class="com.acme.PrepareDownLoadUri" /> <bean id="saveFileProcessor" class="com.acme.SaveFileProcessor" /> <bean id="saveFileProcessor" class="com.acme.SaveFileProcessor" /> <bean id="saveFileProcessor" class="com.acme.AuthorizeWebRequestProcessor" /> {code} best regards, ben > HttpProducer drops authentification parameters. > ----------------------------------------------- > > Key: CAMEL-3779 > URL: https://issues.apache.org/jira/browse/CAMEL-3779 > Project: Camel > Issue Type: Bug > Components: camel-http > Affects Versions: 2.6.0 > Reporter: ben > > Hi, > I run into the following problem with Camel 2.6.0: > An HTML file contain an URI lists of files to be downloaded from a web server > to the local file system. > The HTML file is parsed via a Java Bean Splitter. The Java Bean Splitter > produces a Set of URI strings. > These files should be downloaded from a web server to the local file system. > The files are protected with BASIC authentification. > The extraction and the splitting of the download URIs works quite well with > the Java Bean Splitter. > The Java Bean Splitter produces URI like: > {code}http4://download.acme.com/file_1.txt?username=foo&password=baa{code} > Here's the setup: > {code} > <route> > <from uri="file:///tmp/files_to_retrieve/" /> > <method bean="prepareDownLoadUri" method="parseIndexHtml" /> > <setHeader headerName="CamelHttpMethod"> > <constant>GET</constant> > </setHeader> > <setHeader headerName="CamelHttpUri"> > <simple>${body}</simple> > </setHeader> > <to uri="http4://download.acme.com/" /> > <to uri="bean:saveFileProcessor" /> > </route> > <bean id="prepareDownLoadUri" class="com.acme.PrepareDownLoadUri" /> > <bean id="saveFileProcessor" class="com.acme.SaveFileProcessor" /> > {code} > The injection of the URIs from the Splitter into the HttpProducer, works > quite well. > I debugged into the HttpProducer and it seems, that the HttpProducer does not > provide the unterlying http client (in this case Apache HttpClient 4) with > the authentification settings from the URI. > At first, the queryString is extracted from the Exchange-Header (if provided) > {code:title=HttpProducer.createMethod(), line 273} > String url = HttpHelper.createURL(exchange, getEndpoint()); > {code} > The url string contains the URI produces by the splitter including the > authentification parameters: > {code}http4://download.acme.com/file_1.txt?username=foo&password=baa{code} > Then the HttpProducer assembles a new URI for the requests. The new URI is > assembled from parts of the string url (line 273) > and other parameters from the Exchange Header: > {code:title=HttpProducer.createMethod(), lines 285-300} > // is a query string provided in the endpoint URI or in a header > (header overrules endpoint) > String queryString = exchange.getIn().getHeader(Exchange.HTTP_QUERY, > String.class); > if (queryString == null) { > queryString = getEndpoint().getHttpUri().getRawQuery(); > } > StringBuilder builder = new > StringBuilder(uri.getScheme()).append("://").append(uri.getHost()); > if (uri.getPort() != -1) { > builder.append(":").append(uri.getPort()); > } > if (uri.getPath() != null) { > builder.append(uri.getRawPath()); > } > if (queryString != null) { > builder.append('?'); > builder.append(queryString); > } > HttpRequestBase httpRequest = > methodToUse.createMethod(builder.toString()); > {code} > The problem is, in the assembling of the new URI, the authentification > parameters are dropped. > One possible solution could be: > # check for authentification parameters in the url (line 273) and extract > them. > # build the credentials, AuthScheme and provide it to the underlying http > client. > thanks in advance, > ben -- This message is automatically generated by JIRA. For more information on JIRA, see: http://www.atlassian.com/software/jira