Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query parameters were not included in netty URI #4393

Merged
merged 2 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down Expand Up @@ -205,15 +205,16 @@ public void operationComplete(io.netty.util.concurrent.Future<? super Void> futu
ch.closeFuture().addListener(closeListener);

HttpRequest nettyRequest;
String pathWithQuery = buildPathWithQueryParameters(requestUri);

if (jerseyRequest.hasEntity()) {
nettyRequest = new DefaultHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.valueOf(jerseyRequest.getMethod()),
requestUri.getRawPath());
pathWithQuery);
} else {
nettyRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1,
HttpMethod.valueOf(jerseyRequest.getMethod()),
requestUri.getRawPath());
pathWithQuery);
}

// headers
Expand Down Expand Up @@ -282,6 +283,14 @@ public void run() {
return settableFuture;
}

private String buildPathWithQueryParameters(URI requestUri) {
if (requestUri.getRawQuery() != null) {
return String.format("%s?%s", requestUri.getRawPath(), requestUri.getRawQuery());
} else {
return requestUri.getRawPath();
}
}

@Override
public String getName() {
return "Netty 4.1.x";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -10,9 +10,13 @@

package org.glassfish.jersey.examples.helloworld.netty;

import javax.ws.rs.Consumes;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;

/**
*
Expand All @@ -28,4 +32,21 @@ public String getHello() {
return CLICHED_MESSAGE;
}

@GET
@Path("query1")
@Produces("text/plain")
public String getQueryParameter(@DefaultValue("error1") @QueryParam(value = "test1") String test1,
@DefaultValue("error2") @QueryParam(value = "test2") String test2) {
return test1 + test2;
}

@POST
@Path("query2")
@Consumes("text/plain")
@Produces("text/plain")
public String postQueryParameter(@DefaultValue("error1") @QueryParam(value = "test1") String test1,
@DefaultValue("error2") @QueryParam(value = "test2") String test2, String entity) {
return entity + test1 + test2;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand All @@ -18,6 +18,7 @@

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.InvocationCallback;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
Expand Down Expand Up @@ -224,4 +225,22 @@ public void testConfigurationUpdate() {
assertEquals(1, CustomLoggingFilter.preFilterCalled);
assertEquals(1, CustomLoggingFilter.postFilterCalled);
}

@Test
@RunSeparately
public void testQueryParameterGet() {
String result = target().path(App.ROOT_PATH + "/query1").queryParam("test1", "expected1")
.queryParam("test2", "expected2").request().get(String.class);
assertEquals("expected1expected2", result);
}

@Test
@RunSeparately
public void testQueryParameterPost() {
String result = target().path(App.ROOT_PATH + "/query2").queryParam("test1", "expected1")
.queryParam("test2", "expected2").request("text/plain").post(Entity.entity("entity", "text/plain"))
.readEntity(String.class);
assertEquals("entityexpected1expected2", result);
}

}