camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From HockeyDave <>
Subject RE: camel-http instructions wrong
Date Sun, 19 Oct 2008 10:53:09 GMT

Thanks Claus,

  In the meantime, I realize that my scenario is complex and probably beyond
the current state of what Camel can support so I moved to straight
HttpClient usage.  I have:
URI parameters
https security

Here is working code that you can use if you need.

// Basically fetch the file from a system that doesn't email attachments,
but rather sends
// an email with a link in it that you need to https login to.
private void processNoAttachmentEmails(Exchange exchange, String body,
			String from) throws Exception {
		HttpClient client = new HttpClient();

                         // Spring bean containg all security information
for this server looked
                         // up by the email's from header
		ServerBean server = getServerBean(from);
                          // process the mail body to find the "click here"
to get your report
		String uri = getUrlFromMailBody(body, server);

		URL url = new URL(uri);
		String query = url.getQuery();
		String baseurl = uri.substring(0, uri.indexOf('?'));
		String username = server.getUserName();
		String password = server.getUserPassword();
		String domain = server.getAdserverDomain();
		String realm = server.getDomainRealm();

		GetMethod method = null;
		try {
			Credentials defaultcreds = new UsernamePasswordCredentials(
					username, password);
			client.getState().setCredentials(new AuthScope(domain, 443, realm),
			method = new GetMethod(baseurl);
			method.setQueryString(URIUtil.encodeQuery(query, "UTF-8"));
			int status = client.executeMethod(method);
			long length = method.getResponseContentLength();
			if (status != 401 && length > 0) {
				InputStream stream = method.getResponseBodyAsStream();
				processSaveCsv(exchange, stream, server.getServerName());
			} else {
				log.error("cannot retrieve Report from server " + status
						+ " " + length);
		} catch (Exception e) {
			log.error("unable to get email server report file" + e);
		} finally {
			// always release the connection after we're done
			if (method != null)

View this message in context:
Sent from the Camel - Users mailing list archive at

View raw message