Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpServer.createContext() uses 'startsWith' for context compare?

843790Nov 2 2009 — edited Nov 4 2009
When using Java 6's HttpServer, an HTTP 'context' is created as follows:
HttpServer server = new HttpServer.create(address, 10);
server.createContext("/search", new SearchHandler());
so that when 'search?' is used in the URL, the query portion will be passed to SearchHandler.

A search URL might look like this:
http://www.searchengine.com/search?thing1=foo&thing2=bar
My problem is that if I have a file at the same site called say 'searchData.xml' and if I try fetching it using:
http://www.searchengine.com/searchData.xml
The HttpServer will pass this off to SearchHandler and not read the file! It appears that it is doing a 'startsWith' compare when looking for a context name match.

This can't be the correct behavior can it?


Kevin
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 2 2009
Added on Nov 2 2009
26 comments
1,535 views