-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
478 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
http/grizzly/src/test/java/cloud/piranha/http/grizzly/GrizzlyHttpServerRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package cloud.piranha.http.grizzly; | ||
|
||
import cloud.piranha.http.api.HttpServer; | ||
import cloud.piranha.http.api.HttpServerProcessor; | ||
import cloud.piranha.http.tests.HttpServerRequestTest; | ||
|
||
/** | ||
* The JUnit tests for the DefaultHttpServer class. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
public class GrizzlyHttpServerRequestTest extends HttpServerRequestTest { | ||
|
||
/** | ||
* Create the Netty HTTP server. | ||
* | ||
* @param portNumber the port number. | ||
* @param processor the HTTP server processor. | ||
* @return the Netty HTTP server. | ||
*/ | ||
@Override | ||
protected HttpServer createServer(int portNumber, HttpServerProcessor processor) { | ||
return new GrizzlyHttpServer(portNumber, processor); | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
http/tests/src/main/java/cloud/piranha/http/tests/HttpServerRequestTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package cloud.piranha.http.tests; | ||
|
||
import cloud.piranha.http.api.HttpServer; | ||
import cloud.piranha.http.api.HttpServerProcessor; | ||
import static cloud.piranha.http.api.HttpServerProcessorEndState.COMPLETED; | ||
import cloud.piranha.http.api.HttpServerRequest; | ||
import cloud.piranha.http.api.HttpServerResponse; | ||
import java.net.URI; | ||
import java.net.http.HttpClient; | ||
import java.net.http.HttpRequest; | ||
import java.net.http.HttpResponse.BodyHandlers; | ||
import me.alexpanov.net.FreePortFinder; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* The JUnit tests for the HttpServerRequest class. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
public abstract class HttpServerRequestTest { | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public HttpServerRequestTest() { | ||
} | ||
|
||
/** | ||
* Create server with a port and processor. | ||
* | ||
* @param portNumber the port number. | ||
* @param processor the HTTP processor. | ||
* @return the HTTP server. | ||
*/ | ||
protected abstract HttpServer createServer(int portNumber, HttpServerProcessor processor); | ||
|
||
/** | ||
* Test getRequestTarget method. | ||
*/ | ||
@Test | ||
void testGetRequestTarget() { | ||
System.clearProperty("requestTarget"); | ||
int port = FreePortFinder.findFreeLocalPort(); | ||
HttpServer server = createServer(port, | ||
(HttpServerRequest request, HttpServerResponse response) -> { | ||
System.setProperty("requestTarget", request.getRequestTarget()); | ||
return COMPLETED; | ||
}); | ||
server.start(); | ||
try { | ||
HttpClient client = HttpClient.newHttpClient(); | ||
HttpRequest request = HttpRequest.newBuilder( | ||
URI.create("http://localhost:" + port)).build(); | ||
client.send(request, BodyHandlers.discarding()); | ||
} catch (Exception e) { | ||
// do nothing | ||
} finally { | ||
server.stop(); | ||
} | ||
assertNotNull(System.getProperty("requestTarget")); | ||
System.clearProperty("requestTarget"); | ||
} | ||
|
||
/** | ||
* Test getRequestTarget method (looking for query string marker). | ||
*/ | ||
@Test | ||
void testGetRequestTarget2() { | ||
System.clearProperty("requestTarget"); | ||
int port = FreePortFinder.findFreeLocalPort(); | ||
HttpServer server = createServer(port, | ||
(HttpServerRequest request, HttpServerResponse response) -> { | ||
System.setProperty("requestTarget", request.getRequestTarget()); | ||
return COMPLETED; | ||
}); | ||
server.start(); | ||
try { | ||
HttpClient client = HttpClient.newHttpClient(); | ||
HttpRequest request = HttpRequest.newBuilder( | ||
URI.create("http://localhost:" + port + "?queryParam=queryParam")).build(); | ||
client.send(request, BodyHandlers.discarding()); | ||
} catch (Exception e) { | ||
// do nothing | ||
} finally { | ||
server.stop(); | ||
} | ||
assertNotNull(System.getProperty("requestTarget")); | ||
assertTrue(System.getProperty("requestTarget").indexOf("?") > 0); | ||
System.clearProperty("requestTarget"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
.../integration/src/main/java/cloud/piranha/test/coreprofile/distribution/BeanParamBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, | ||
* this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* 3. Neither the name of the copyright holder nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
package cloud.piranha.test.coreprofile.distribution; | ||
|
||
import jakarta.ws.rs.BeanParam; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import static jakarta.ws.rs.core.MediaType.APPLICATION_FORM_URLENCODED; | ||
import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
/** | ||
* The BeanParam bean to test the BeanParam annotation integration. | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
@Path("/beanParam") | ||
public class BeanParamBean { | ||
|
||
/** | ||
* Process BeanParam annotated input. | ||
* | ||
* @param input the input. | ||
* @return the response. | ||
*/ | ||
@POST | ||
@Consumes(APPLICATION_FORM_URLENCODED) | ||
@Produces(TEXT_PLAIN) | ||
public Response beanParamInput(@BeanParam BeanParamInput input) { | ||
return Response.ok(input.toString()).build(); | ||
} | ||
} |
Oops, something went wrong.