You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by HockeyDave <da...@yahoo.com> on 2008/10/18 19:08:10 UTC

camel-http instructions wrong

Camel-http documents a way to send query parameters, but it doesn't work.
http://activemq.apache.org/camel/http.html

Specifically this section:
--------------------------
URI Parameters from the Message
Map headers = new HashMap();
headers.put(HttpProducer.QUERY, "q=Camel&lr=lang_en");
// we query for Camel and english language at Google
template.sendBody("http://www.google.com/search", "", headers);
------------------------
However the signature of this call doesn't even exist.  Attempting to use a
different signature 
template.sendBody("http://www.google.com/search, headers);

also won't work because the parameters just gets jammed into a post-body. 
You can't leave the query actually on the URI either because you'll get a
can't find endpoint failure.  This is kind of a rock and a hard place issue
as there doesn't seem to be any way to get there from here.  :)




The issue seems to be covered in this forum entry, but I don't see any kind
of a workaround for this.  Does anyone have a workaround?
http://www.nabble.com/HttpGet-Issue-with-1.4.0-td18899762s22882.html#a18899762


Thanks
Dave
-- 
View this message in context: http://www.nabble.com/camel-http-instructions-wrong-tp20048788s22882p20048788.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: camel-http instructions wrong

Posted by HockeyDave <da...@yahoo.com>.
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
Login/Password

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),
					defaultcreds);
			client.getParams().setAuthenticationPreemptive(true);
			method = new GetMethod(baseurl);
			method.setQueryString(URIUtil.encodeQuery(query, "UTF-8"));
			
			method.setFollowRedirects(true);
			method.setDoAuthentication(true);
			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)
				method.releaseConnection();
		}

	}
-- 
View this message in context: http://www.nabble.com/camel-http-instructions-for-Query-string-handling-don%27t-work-tp20048788s22882p20054996.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: camel-http instructions wrong

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

Yeah the sample is wrong. It doesn't use GET but POST as you write. I will look into it, so Camel will be smarter and use GET if the URI has parameters.

Otherwise you can provide method to use by adding a header, see wiki.


Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk

-----Original Message-----
From: HockeyDave [mailto:david_peterson4146@yahoo.com] 
Sent: 18. oktober 2008 19:08
To: camel-user@activemq.apache.org
Subject: camel-http instructions wrong


Camel-http documents a way to send query parameters, but it doesn't work.
http://activemq.apache.org/camel/http.html

Specifically this section:
--------------------------
URI Parameters from the Message
Map headers = new HashMap();
headers.put(HttpProducer.QUERY, "q=Camel&lr=lang_en");
// we query for Camel and english language at Google
template.sendBody("http://www.google.com/search", "", headers);
------------------------
However the signature of this call doesn't even exist.  Attempting to use a
different signature 
template.sendBody("http://www.google.com/search, headers);

also won't work because the parameters just gets jammed into a post-body. 
You can't leave the query actually on the URI either because you'll get a
can't find endpoint failure.  This is kind of a rock and a hard place issue
as there doesn't seem to be any way to get there from here.  :)




The issue seems to be covered in this forum entry, but I don't see any kind
of a workaround for this.  Does anyone have a workaround?
http://www.nabble.com/HttpGet-Issue-with-1.4.0-td18899762s22882.html#a18899762


Thanks
Dave
-- 
View this message in context: http://www.nabble.com/camel-http-instructions-wrong-tp20048788s22882p20048788.html
Sent from the Camel - Users mailing list archive at Nabble.com.