Hi Alan,
Thanks for the reply, patch attached (generated against the Taverna 2.4.0
release src tarball). As for the contributor's agreement, I had assumed that
because I'm a University of Southampton employee that this may well already be
covered, given the links between myExperiment and Taverna.
The patch is undoubtedly not the best method for adding the functionality I was
after (I feel embarrassed even sending a patch that catches and ignores
exceptions), but given the structure of the code it was certainly the
lightest-touch I could come up with.
Joel.
--
Dr Joel Wright
IT Innovation Centre
Gamma House
Enterprise Road
Southampton
SO16 7NS, UK
Tel.:+44 23 8059 8866
mailto:[email protected]
http://www.it-innovation.soton.ac.uk/
________________________________________
From: Alan R Williams [[email protected]]
Sent: 21 May 2012 11:54
To: [email protected]
Subject: Re: [Taverna-hackers] REST Services and Optional Query String
Parameters
On 21/05/2012 10:37, Joel Wright wrote:
> Hi Everyone,
Hello
> I've recently needed to include services that make use of optional
> query string parameters in some workflows I've been working on. The
> problem I encountered is that when specifying a REST activity with a
> URL template similar to the one below forces the user to modify the
> URL each time to only include the query string parameters they wish
> to use in that particular invocation.
>
> URL: http://example.org/{path}/?p1={p1?}&p2={p2?}&p3={p3?} ....
>
> Some of the URL templates I'm dealing with have 20+ optional
> parameters so editing them each time to provide a different subset of
> query strings has been a bit of a pain.
I know :( I think the same problem affects BioCatalogue.
> I was wondering if partially completing URL templates of this form is
> already supported, and if not would there be any interest in my patch
> against Taverna 2.4.0 to allow optional parameters to be
> automatically removed from the URL if the value to complete them is
> not supplied.
I would be very interested in seeing the patch. In theory before we
include it, you should sign the Contributor's License Agreement (CLA).
It is at http://www.taverna.org.uk/about/legal-stuff/contributors-guide/
Stian wants to do a patch for the REST activity anyway. So, we may be
able to include your proposal.
> Joel. --
Alan
> Dr Joel Wright IT Innovation Centre Gamma House Enterprise Road
> Southampton SO16 7NS, UK
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
taverna-hackers mailing list
[email protected]
Web site: http://www.taverna.org.uk
Mailing lists: http://www.taverna.org.uk/about/contact-us/
Developers Guide: http://www.taverna.org.uk/developers/
diff -crB taverna-workbench-2.4.0/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/RESTActivity.java taverna-workbench-2.4.0-jjw/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/RESTActivity.java
*** taverna-workbench-2.4.0/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/RESTActivity.java 2012-03-20 14:35:02.000000000 +0000
--- taverna-workbench-2.4.0-jjw/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/RESTActivity.java 2012-05-21 12:24:18.304306962 +0100
***************
*** 230,254 ****
// (just use the configuration that was determined in
// configurePorts() - all ports in this set are required)
Map<String, String> urlParameters = new HashMap<String, String>();
! try {
! for (String inputName : configBean.getActivityInputs()
! .keySet()) {
urlParameters.put(inputName, (String) referenceService
! .renderIdentifier(inputs.get(inputName),
! configBean.getActivityInputs().get(
! inputName), context));
}
- } catch (Exception e) {
- // problem occurred while resolving the inputs
- callback
- .fail(
- "REST activity was unable to resolve all necessary inputs"
- + "that contain values for populating the URI signature placeholders "
- + "with values.", e);
-
- // make sure we don't call callback.receiveResult later
- return;
- }
String completeURL = URISignatureHandler.generateCompleteURI(
configBean.getUrlSignature(), urlParameters, configBean
.getEscapeParameters());
--- 230,245 ----
// (just use the configuration that was determined in
// configurePorts() - all ports in this set are required)
Map<String, String> urlParameters = new HashMap<String, String>();
! for (String inputName : configBean.getActivityInputs().keySet()) {
! try {
urlParameters.put(inputName, (String) referenceService
! .renderIdentifier(inputs.get(inputName),
! configBean.getActivityInputs().get(inputName), context));
! } catch (Exception e) {
! // Input value doesn't exist, but we might not care, so just swallow the exception
! // when we try to get the value for an input we didn't specify. This error will be
! // raised later when we try to build the URI.
}
String completeURL = URISignatureHandler.generateCompleteURI(
configBean.getUrlSignature(), urlParameters, configBean
.getEscapeParameters());
diff -crB taverna-workbench-2.4.0/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/URISignatureHandler.java taverna-workbench-2.4.0-jjw/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/URISignatureHandler.java
*** taverna-workbench-2.4.0/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/URISignatureHandler.java 2011-06-02 12:28:20.000000000 +0100
--- taverna-workbench-2.4.0-jjw/engine/net.sf.taverna.t2.activities/rest-activity/src/main/java/net/sf/taverna/t2/activities/rest/URISignatureHandler.java 2012-05-21 12:26:49.632311472 +0100
***************
*** 298,308 ****
while (placeholdersIterator.hasNext()) {
String placeholder = placeholdersIterator.next();
if (parameters.containsKey(placeholder)) {
- int placeholderStartPos = placeholdersWithPositions
- .get(placeholder) - 1;
- int placeholderEndPos = placeholderStartPos
- + placeholder.length() + 2;
if (escapeParameters) {
completeURI.replace(placeholderStartPos,
placeholderEndPos, urlEncodeQuery(parameters
--- 298,308 ----
while (placeholdersIterator.hasNext()) {
String placeholder = placeholdersIterator.next();
+ int placeholderStartPos = placeholdersWithPositions
+ .get(placeholder) - 1;
+ int placeholderEndPos = placeholderStartPos
+ + placeholder.length() + 2;
if (parameters.containsKey(placeholder)) {
if (escapeParameters) {
completeURI.replace(placeholderStartPos,
placeholderEndPos, urlEncodeQuery(parameters
***************
*** 312,320 ****
placeholderEndPos, parameters.get(placeholder));
}
} else {
! throw new URIGenerationFromSignatureException(
! "Parameter map does not contain a key/value for \""
! + placeholder + "\" placeholder");
}
}
}
--- 312,341 ----
placeholderEndPos, parameters.get(placeholder));
}
} else {
! int qnPos = completeURI.lastIndexOf("?", placeholderStartPos);
! int ampPos = completeURI.lastIndexOf("&", placeholderStartPos);
! int slashPos = completeURI.lastIndexOf("/", placeholderStartPos);
! int startParamPos = Math.max(qnPos, ampPos);
! if (startParamPos > -1 && startParamPos > slashPos) {
! // We found an optional parameter, so delete all of it
! if (qnPos > ampPos) {
! // It might be the first or only parameter so delete carefully
! if (placeholderEndPos >= (completeURI.length() - 1)) {
! // No parameters
! completeURI.replace(startParamPos, placeholderEndPos, "");
! } else {
! // Remove the & from the following parameter, not the ? that starts
! completeURI.replace(startParamPos + 1, placeholderEndPos + 1, "");
! }
! } else {
! // Just delete the optional parameter in total
! completeURI.replace(startParamPos, placeholderEndPos, "");
! }
! } else {
! throw new URIGenerationFromSignatureException(
! "Parameter map does not contain a key/value for \""
! + placeholder + "\" mandatory placeholder");
! }
}
}
}
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
taverna-hackers mailing list
[email protected]
Web site: http://www.taverna.org.uk
Mailing lists: http://www.taverna.org.uk/about/contact-us/
Developers Guide: http://www.taverna.org.uk/developers/