Skip to content

Commit c900125

Browse files
committed
Fixed NullPointerException when requestind a Directory with a query string. Issue #1206. Reported by Ralph van Etten.
1 parent 6f2befc commit c900125

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

build/tmpl/text/changes.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Changes log
44
===========
55

66
@version-full@ (@release-date@)
7+
- Bugs fixed
8+
- Fixed NullPointerException when requestind a Directory with a query string. Issue #1206.
9+
Reported by Ralph van Etten.
710

811
- 2.3.7 (03/14/2016)
912
- Bugs fixed

modules/org.restlet.test/src/org/restlet/test/resource/DirectoryTestCase.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.restlet.data.Method;
5959
import org.restlet.data.Reference;
6060
import org.restlet.data.Status;
61+
import org.restlet.engine.Engine;
6162
import org.restlet.engine.header.HeaderConstants;
6263
import org.restlet.engine.io.IoUtils;
6364
import org.restlet.engine.util.ReferenceUtils;
@@ -156,6 +157,8 @@ public static void main(String[] args) throws Exception {
156157
File testDir;
157158

158159
public void testDirectory() throws Exception {
160+
Engine.getInstance().getRegisteredConverters().clear();
161+
Engine.getInstance().registerDefaultConverters();
159162
// Create a new Restlet component
160163
Component clientComponent = new Component();
161164
clientComponent.getClients().add(FILE);
@@ -263,6 +266,11 @@ protected TestRequest header(Header header) {
263266
return this;
264267
}
265268

269+
protected TestRequest query(String name, String value) {
270+
request.getResourceRef().addQueryParameter(name, value);
271+
return this;
272+
}
273+
266274
protected Response handle(Method method) {
267275
final Response response = new Response(request);
268276
request.setMethod(method);
@@ -474,6 +482,13 @@ private void testDirectory(MyApplication application, Directory directory, Strin
474482
.handle(PUT);
475483
assertEquals(SUCCESS_CREATED, response.getStatus());
476484

485+
response = new TestRequest(this.baseFileUrl)
486+
.baseRef(this.webSiteURL)
487+
.query("x", "y")
488+
.handle(GET);
489+
assertEquals(SUCCESS_OK, response.getStatus());
490+
assertTrue(response.getEntityAsText().equals("this is test 3b"));
491+
477492
// Test 4 : Try to get the representation of the new file
478493
response = new TestRequest(this.baseFileUrl)
479494
.baseRef(this.webSiteURL)

modules/org.restlet/src/org/restlet/data/Protocol.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
package org.restlet.data;
2626

27+
import org.restlet.engine.util.StringUtils;
28+
2729
/**
2830
* Protocol used by client and server connectors. Connectors enable the
2931
* communication between components by implementing standard protocols.
@@ -182,7 +184,7 @@ public final class Protocol {
182184
public static Protocol valueOf(String name) {
183185
Protocol result = null;
184186

185-
if ((name != null) && !name.equals("")) {
187+
if (!StringUtils.isNullOrEmpty(name)) {
186188
if (name.equalsIgnoreCase(AJP.getSchemeName())) {
187189
result = AJP;
188190
} else if (name.equalsIgnoreCase(CLAP.getSchemeName())) {

modules/org.restlet/src/org/restlet/engine/local/DirectoryServerResource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ && getApplication().getTunnelService().isExtensionsTunnel()) {
196196
Reference originalBaseRef = new Reference(this.originalRef);
197197
originalBaseRef.setPath(getReference().getBaseRef().getPath());
198198
this.originalRef.setBaseRef(originalBaseRef);
199-
this.relativePart = this.originalRef.getRemainingPart();
199+
this.relativePart = this.originalRef.getRemainingPart(false, false);
200200
}
201201
}
202202

0 commit comments

Comments
 (0)