# sign in URL query string crashes Java agent

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);

}

}

Subject: # sign in URL query string crashes Java agent

The # sign is a reserved character in urls - see Uniform Resource Locators - it starts a fragment identifier and is correctly not encoded.

Where/how does it die? Any messages or other clues would be helpful.

Steve

Subject: RE: # sign in URL query string crashes Java agent

After a bit of research I have found that the resolution is that there IS NOT one in Domino, regardless of the language of the agent. I found that the QUERY_STRING variable just ignores the # sign and anything after it…so there’s nothing I can do about it. I have to go to the other system and ask that any time the # sign is present it has to be encoded as %23. Oh well…live and learn…