You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by em...@apache.org on 2022/10/09 01:43:38 UTC
[cxf] branch main updated: [CXF-8716]:Migration path for Project Grizzly
This is an automated email from the ASF dual-hosted git repository.
ema pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/main by this push:
new e7157bb371 [CXF-8716]:Migration path for Project Grizzly
e7157bb371 is described below
commit e7157bb371804a15e3c78351c9b506776bcbdeda
Author: Jim Ma <em...@apache.org>
AuthorDate: Fri Sep 30 18:47:31 2022 +0800
[CXF-8716]:Migration path for Project Grizzly
---
systests/container-integration/grizzly/pom.xml | 18 +--
.../cxf/systest/grizzly/EndpointAPITest.java | 24 ++-
.../cxf/systest/grizzly/GrizzlyHttpContext.java | 60 +++++++
.../cxf/systest/grizzly/GrizzlyHttpExchange.java | 179 +++++++++++++++++++++
.../cxf/systest/grizzly/GrizzlyHttpHandler.java | 22 +++
systests/container-integration/pom.xml | 12 +-
6 files changed, 276 insertions(+), 39 deletions(-)
diff --git a/systests/container-integration/grizzly/pom.xml b/systests/container-integration/grizzly/pom.xml
index 9e9f83073f..976ffbcc1a 100644
--- a/systests/container-integration/grizzly/pom.xml
+++ b/systests/container-integration/grizzly/pom.xml
@@ -58,23 +58,11 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>com.sun.grizzly</groupId>
- <artifactId>grizzly-http</artifactId>
- <version>1.9.65</version>
+ <groupId>org.glassfish.grizzly</groupId>
+ <artifactId>grizzly-http-server</artifactId>
+ <version>3.0.1</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.jvnet.jax-ws-commons</groupId>
- <artifactId>jaxws-grizzly-httpspi</artifactId>
- <version>1.1</version>
- <scope>test</scope>
- <exclusions>
- <exclusion>
- <groupId>jakarta.xml.ws</groupId>
- <artifactId>jaxws-api</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>${cxf.servlet-api.group}</groupId>
<artifactId>${cxf.servlet-api.artifact}</artifactId>
diff --git a/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/EndpointAPITest.java b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/EndpointAPITest.java
index 5999a33585..0227684ef2 100644
--- a/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/EndpointAPITest.java
+++ b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/EndpointAPITest.java
@@ -33,8 +33,9 @@ import jakarta.xml.ws.Service;
import jakarta.xml.ws.soap.MTOMFeature;
import jakarta.xml.ws.spi.http.HttpContext;
import org.apache.cxf.testutil.common.TestUtil;
-import org.jvnet.jax_ws_commons.transport.grizzly_httpspi.GrizzlyHttpContextFactory;
+import org.glassfish.grizzly.http.server.HttpServer;
+import org.glassfish.grizzly.http.server.NetworkListener;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -47,17 +48,19 @@ public class EndpointAPITest {
private static int counter;
private static int currentPort;
- private com.sun.grizzly.http.embed.GrizzlyWebServer server;
+ private HttpServer server;
@Before
public void setUp() {
currentPort = Integer.valueOf(TestUtil.getPortNumber(EndpointAPITest.class, counter++));
- server = new com.sun.grizzly.http.embed.GrizzlyWebServer(currentPort);
+ server = new HttpServer();
+ NetworkListener networkListener = new NetworkListener("jaxwslistener", "0.0.0.0", currentPort);
+ server.addListener(networkListener);
}
@After
public void tearDown() {
- server.stop();
+ server.shutdownNow();
server = null;
}
@@ -68,8 +71,7 @@ public class EndpointAPITest {
String path = "/echo";
String address = "http://localhost:" + currentPort + contextPath + path;
- HttpContext context = GrizzlyHttpContextFactory.createHttpContext(server, contextPath, path);
-
+ HttpContext context = new GrizzlyHttpContext(server, contextPath, path);
Endpoint endpoint = Endpoint.create(new EndpointBean());
endpoint.publish(context); // Use grizzly HTTP context for publishing
@@ -86,7 +88,7 @@ public class EndpointAPITest {
String contextPath = "/ctxt";
String path = "/echo";
//need to use the same HttpContext, otherwise Grizzly get confused
- HttpContext ctx = GrizzlyHttpContextFactory.createHttpContext(server, contextPath, path);
+ HttpContext ctx = new GrizzlyHttpContext(server, contextPath, path);
for (int i = 0; i < 3; i++) {
String address = "http://localhost:" + currentPort + contextPath + path;
@@ -110,9 +112,7 @@ public class EndpointAPITest {
String[] addresses = new String[k];
for (int i = 0; i < k; i++) {
addresses[i] = "http://localhost:" + currentPort + contextPath + path + i;
- contexts[i] = GrizzlyHttpContextFactory.createHttpContext(server,
- contextPath,
- path + i);
+ contexts[i] = new GrizzlyHttpContext(server, contextPath, path + i);
endpoints[i] = Endpoint.create(new EndpointBean());
endpoints[i].publish(contexts[i]);
}
@@ -135,9 +135,7 @@ public class EndpointAPITest {
String[] addresses = new String[k];
for (int i = 0; i < k; i++) {
addresses[i] = "http://localhost:" + currentPort + contextPath + i + path;
- contexts[i] = GrizzlyHttpContextFactory.createHttpContext(server,
- contextPath + i,
- path);
+ contexts[i] = new GrizzlyHttpContext(server,contextPath + i, path);
endpoints[i] = Endpoint.create(new EndpointBean());
endpoints[i].publish(contexts[i]);
}
diff --git a/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpContext.java b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpContext.java
new file mode 100644
index 0000000000..b46972c340
--- /dev/null
+++ b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpContext.java
@@ -0,0 +1,60 @@
+package org.apache.cxf.systest.grizzly;
+
+import jakarta.xml.ws.spi.http.HttpContext;
+import java.util.Map;
+import java.util.Set;
+import org.glassfish.grizzly.http.server.HttpHandler;
+import org.glassfish.grizzly.http.server.HttpHandlerRegistration;
+import org.glassfish.grizzly.http.server.HttpServer;
+
+public class GrizzlyHttpContext extends HttpContext {
+ private final String contextPath;
+ private final String path;
+ private final HttpServer server;
+
+ public GrizzlyHttpContext(HttpServer server, String contextPath, String path) {
+ this.server = server;
+ this.contextPath = contextPath;
+ this.path = path;
+ }
+
+ @Override
+ public void setHandler(jakarta.xml.ws.spi.http.HttpHandler handler) {
+ HttpHandlerRegistration httpHandlerRegistration = new HttpHandlerRegistration.Builder().
+ contextPath(this.contextPath).urlPattern(path).build();
+ for (Map.Entry<HttpHandler, HttpHandlerRegistration[]> httpHandlerMapping :
+ server.getServerConfiguration().getHttpHandlersWithMapping().entrySet()) {
+ for(HttpHandlerRegistration registration : httpHandlerMapping.getValue()) {
+ if (registration.equals(httpHandlerRegistration)) {
+ server.getServerConfiguration().removeHttpHandler(httpHandlerMapping.getKey());
+ }
+ }
+ }
+ server.getServerConfiguration().addHttpHandler(new GrizzlyHttpHandler(handler, this), httpHandlerRegistration);
+ }
+
+ @Override
+ public String getPath() {
+ return path;
+ }
+
+ String getContextPath() {
+ return contextPath;
+ }
+
+ jakarta.xml.ws.spi.http.HttpHandler getHandler() {
+ return handler;
+ }
+
+ //There is no grizzly server configuration can be provided for jaxws service
+ @Override
+ public Object getAttribute(String s) {
+ return null;
+ }
+
+ //There is no grizzly server configuration can be provided for jaxws service
+ @Override
+ public Set<String> getAttributeNames() {
+ return null;
+ }
+}
diff --git a/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpExchange.java b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpExchange.java
new file mode 100644
index 0000000000..8b3b2faab3
--- /dev/null
+++ b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpExchange.java
@@ -0,0 +1,179 @@
+package org.apache.cxf.systest.grizzly;
+
+import jakarta.xml.ws.spi.http.HttpContext;
+import jakarta.xml.ws.spi.http.HttpExchange;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.security.Principal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.glassfish.grizzly.http.server.Request;
+import org.glassfish.grizzly.http.server.Response;
+
+public class GrizzlyHttpExchange extends HttpExchange {
+ private final Request request;
+ private final Response response;
+ private Map<String, List<String>> requestHeaders;
+ private Map<String, List<String>> responseHeaders;
+ private final GrizzlyHttpContext context;
+
+ public GrizzlyHttpExchange(GrizzlyHttpContext context, Request request, Response response) {
+ this.context = context;
+ this.request = request;
+ this.response = response;
+ }
+
+ @Override
+ public Map<String, List<String>> getRequestHeaders() {
+ if (requestHeaders == null) {
+
+ requestHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
+ for (String key : request.getHeaderNames()) {
+ List<String> values = new ArrayList<String>();
+ for (String value : request.getHeaders(key)) {
+ values.add(value);
+ }
+ requestHeaders.put(key, values);
+ }
+ }
+ return requestHeaders;
+ }
+
+ @Override
+ public String getRequestHeader(String name) {
+ return request.getHeader(name);
+ }
+
+ @Override
+ public Map<String, List<String>> getResponseHeaders() {
+ if (responseHeaders == null) {
+ responseHeaders = new ResponseHeaders(response);
+ for (String key : response.getHeaderNames()) {
+ List<String> values = new ArrayList<String>();
+ for (String value : response.getHeaderValues(key)) {
+ values.add(value);
+ }
+ responseHeaders.put(key, values);
+ }
+
+ }
+ return responseHeaders;
+ }
+
+ @Override
+ public void addResponseHeader(String name, String value) {
+ response.addHeader(name, value);
+ }
+
+ @Override
+ public String getRequestURI() {
+ return request.getRequestURI() + "?" + request.getQueryString();
+ }
+
+ @Override
+ public String getContextPath() {
+ return request.getContextPath();
+ }
+
+ @Override
+ public String getRequestMethod() {
+ return request.getMethod().getMethodString();
+ }
+
+ @Override
+ public HttpContext getHttpContext() {
+
+ return context;
+ }
+
+ @Override
+ public void close() throws IOException {
+ response.finish();
+ }
+
+ @Override
+ public InputStream getRequestBody() throws IOException {
+ return request.getInputStream();
+ }
+
+ @Override
+ public OutputStream getResponseBody() throws IOException {
+ return response.getOutputStream();
+ }
+
+ @Override
+ public void setStatus(int status) {
+ response.setStatus(status);
+
+ }
+
+ @Override
+ public InetSocketAddress getRemoteAddress() {
+ return InetSocketAddress.createUnresolved(request.getRemoteHost(), request.getRemotePort());
+ }
+
+ @Override
+ public InetSocketAddress getLocalAddress() {
+ return InetSocketAddress.createUnresolved(request.getLocalAddr(), request.getLocalPort());
+ }
+
+ @Override
+ public String getProtocol() {
+ return request.getProtocol().getProtocolString();
+ }
+
+ @Override
+ public String getScheme() {
+ return request.getScheme();
+ }
+
+ @Override
+ public String getPathInfo() {
+ return request.getRequestURI();
+ }
+
+ @Override
+ public String getQueryString() {
+ return request.getQueryString();
+ }
+
+ @Override
+ public Object getAttribute(String name) {
+ return request.getAttribute(name);
+ }
+
+ @Override
+ public Set<String> getAttributeNames() {
+ return request.getAttributeNames();
+ }
+
+ @Override
+ public Principal getUserPrincipal() {
+ return null;
+ }
+
+ @Override
+ public boolean isUserInRole(String role) {
+ return false;
+ }
+
+ public class ResponseHeaders extends TreeMap<String, List<String>> {
+ private final Response response;
+ public ResponseHeaders(Response response) {
+ super(String.CASE_INSENSITIVE_ORDER);
+ this.response = response;
+ }
+ @Override
+ public List<String> put(String key, List<String> value) {
+ for(String val : value) {
+ response.addHeader(key, val);
+ }
+ return super.put(key, value);
+ }
+ }
+}
\ No newline at end of file
diff --git a/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpHandler.java b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpHandler.java
new file mode 100644
index 0000000000..db0d52df59
--- /dev/null
+++ b/systests/container-integration/grizzly/src/test/java/org/apache/cxf/systest/grizzly/GrizzlyHttpHandler.java
@@ -0,0 +1,22 @@
+package org.apache.cxf.systest.grizzly;
+
+import jakarta.xml.ws.spi.http.HttpHandler;
+import org.glassfish.grizzly.http.server.Request;
+import org.glassfish.grizzly.http.server.Response;
+
+public class GrizzlyHttpHandler extends org.glassfish.grizzly.http.server.HttpHandler {
+
+ private final jakarta.xml.ws.spi.http.HttpHandler spihandler;
+ private final GrizzlyHttpContext context;
+
+ public GrizzlyHttpHandler(HttpHandler handler, GrizzlyHttpContext context) {
+ spihandler = handler;
+ this.context = context;
+ }
+
+ @Override
+ public void service(Request request, Response response) throws Exception {
+ spihandler.handle(new GrizzlyHttpExchange(context, request, response));
+ }
+
+}
\ No newline at end of file
diff --git a/systests/container-integration/pom.xml b/systests/container-integration/pom.xml
index 4441620c54..9d681bb30a 100644
--- a/systests/container-integration/pom.xml
+++ b/systests/container-integration/pom.xml
@@ -33,16 +33,6 @@
<url>https://cxf.apache.org</url>
<modules>
<module>webapp</module>
+ <module>grizzly</module>
</modules>
-
- <profiles>
- <!-- TODO: This profile includes modules which are still on 'javax.*' namespace and
- are not migrated to Jakarta -->
- <profile>
- <id>javax</id>
- <modules>
- <module>grizzly</module>
- </modules>
- </profile>
- </profiles>
</project>