okleine / nCoAP

Java implementation of the CoAP protocol using netty
BSD 3-Clause "New" or "Revised" License
179 stars 57 forks source link

CoAP URI options encoding throws URISyntaxException #14

Closed stefanhueske closed 11 years ago

stefanhueske commented 12 years ago

Will be thrown when the CoAPRequest's URI_PATH option contains a special character like "]" and calling CoAPRequest.getTargetUri()

java.net.URISyntaxException: Illegal character in path at index 34: coap://host.com:5555/testpath/test]path
    at java.net.URI$Parser.fail(URI.java:2829)
    at java.net.URI$Parser.checkChars(URI.java:3002)
    at java.net.URI$Parser.parseHierarchical(URI.java:3086)
    at java.net.URI$Parser.parse(URI.java:3034)
    at java.net.URI.<init>(URI.java:595)
    at de.uniluebeck.itm.spitfire.nCoap.message.CoapRequest.getTargetUri(CoapRequest.java:150)

Possible solution: "In Java, the correct way to build a URL is with the URI class. Use one of the multi-argument constructors that takes the URL components as separate strings, and it'll escape each component correctly according to that component's rules." see accepted answer on stackoverflow.com