I have a Java agent that accepts a GET request URL from an external application (not Domino and not easily modified). The URL is invoked with several query string variables, including one for ShippingAddress. I found yesterday that when their system passes a pound sign (#) in the URL, it crashes my agent. Apparently, the pound sign is not just converted to a hex value like a space, for example. So when I try to parse it, it fails. For example, the URL might be something like this:
http://www.mydomain.com/process.nsf?openagent&shippingaddress=123 Main Street #307
The spaces do not cause any issues. However, when it comes to parsing the " #307", it dies.
To parse the query string, I’m using some code I found on this forum (I think)…is there any way to modify the parsing code to handle the # sign issue?
import lotus.domino.*;
import java.util.*;
public class UrlArguments extends Hashtable {
public UrlArguments() {
}
public void fromString(String args) {
StringTokenizer toks = new StringTokenizer(args, "&=", true);
String tok = toks.nextToken(); // first token is command: skip it.
String key = null;
boolean bKeyNext = true;
while (toks.hasMoreTokens()) {
tok = toks.nextToken();
if (tok.equals("&")) {
if (bKeyNext && (key != null)) {
// Null value
put(key, "");
}
key = null;
bKeyNext = true;
} else if (tok.equals("=")) {
bKeyNext = false;
} else {
if (bKeyNext) {
key = new String(tok);
} else {
if (key != null) {
put(key, tok);
}
key = null;
}
}
}
// We have to special-case a valueless argument at the end.
if (bKeyNext && (key != null)) {
// Null value
put(key, "");
}
}
public void fromSession(Session session)
throws lotus.domino.NotesException {
AgentContext agentContext = session.getAgentContext();
Document doc = agentContext.getDocumentContext();
// First add all of the CGI variables. They are in the document context.
Vector items = doc.getItems();
for (int iItem = 0; iItem < items.size(); iItem++) {
Item item = (Item) items.elementAt(iItem);
put(item.getName(), item.getText());
}
// Now parse the URL arguments themselves.
fromString(
doc.getItemValue("QUERY_STRING_DECODED").elementAt(0).toString());
}
// A simple accessor to make casts unnecessary.
public String getString(String key) {
return (String) get(key);
}
}