Skip to content

Commit

Permalink
Helidon 4.x container
Browse files Browse the repository at this point in the history
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
  • Loading branch information
senivam committed Jun 12, 2024
1 parent 429af6c commit b3bac21
Show file tree
Hide file tree
Showing 12 changed files with 1,055 additions and 0 deletions.
104 changes: 104 additions & 0 deletions containers/helidon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2024 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
http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the
Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
version 2 with the GNU Classpath Exception, which is available at
https://www.gnu.org/software/classpath/license.html.
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>project</artifactId>
<groupId>org.glassfish.jersey.containers</groupId>
<version>3.1.99-SNAPSHOT</version>
</parent>

<artifactId>jersey-container-helidon</artifactId>
<packaging>jar</packaging>
<name>jersey-container-helidon</name>

<description>Helidon Http Container</description>

<properties>
<java11.build.outputDirectory>${project.basedir}/target</java11.build.outputDirectory>
<java11.sourceDirectory>${project.basedir}/src/main/java11</java11.sourceDirectory>
<java17.build.outputDirectory>${project.basedir}/target17</java17.build.outputDirectory>
<java17.sourceDirectory>${project.basedir}/src/main/java17</java17.sourceDirectory>
</properties>

<dependencies>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>4.0.9</version>
</dependency>
<dependency>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
<version>4.0.9</version>
</dependency>
<dependency>
<groupId>io.helidon.http</groupId>
<artifactId>helidon-http</artifactId>
<version>4.0.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.sun.istack</groupId>
<artifactId>istack-commons-maven-plugin</artifactId>
<inherited>true</inherited>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<inherited>true</inherited>
</plugin>
</plugins>

<resources>
<resource>
<directory>${basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* Copyright (c) 2024 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.helidon;

import io.helidon.common.context.Context;
import io.helidon.common.tls.Tls;
import io.helidon.webserver.WebServer;
import io.helidon.webserver.WebServerConfig;
import io.helidon.webserver.http.HttpRouting;
import jakarta.ws.rs.core.Application;
import org.glassfish.jersey.server.ApplicationHandler;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spi.Container;

public class HelidonHttpContainer implements Container, WebServer {

private final WebServer webServer;

private ApplicationHandler applicationHandler;

HelidonHttpContainer(Application application) {
this.applicationHandler = new ApplicationHandler(application, new WebServerBinder());
this.webServer = WebServer.builder().port(8080).routing(
HttpRouting.builder().register(
JerseySupport.create(this)
)).build();
}

@Override
public ResourceConfig getConfiguration() {
return applicationHandler.getConfiguration();
}

@Override
public ApplicationHandler getApplicationHandler() {
return applicationHandler;
}

@Override
public void reload() {
reload(new ResourceConfig(getConfiguration()));
}

@Override
public void reload(ResourceConfig configuration) {
applicationHandler.onShutdown(this);

applicationHandler = new ApplicationHandler(configuration);
applicationHandler.onReload(this);
applicationHandler.onStartup(this);
if (webServer.isRunning()) {
webServer.stop();
webServer.start();
}
}

@Override
public WebServer start() {
webServer.start();
return this;
}

@Override
public WebServer stop() {
webServer.stop();
return this;
}

@Override
public boolean isRunning() {
return webServer.isRunning();
}

@Override
public int port(String socketName) {
return webServer.port(socketName);
}

@Override
public Context context() {
return webServer.context();
}

@Override
public boolean hasTls(String socketName) {
return webServer.hasTls(socketName);
}

@Override
public void reloadTls(String socketName, Tls tls) {
webServer.reloadTls(socketName, tls);
}

@Override
public WebServerConfig prototype() {
return webServer.prototype();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.helidon;

import io.helidon.webserver.WebServer;
import org.glassfish.jersey.server.ResourceConfig;

import java.net.URI;

public class HelidonHttpContainerFactory {

private HelidonHttpContainerFactory() {
}

public static WebServer createServer(URI baseUri, ResourceConfig config) {
return new HelidonHttpContainer(config);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 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
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package org.glassfish.jersey.helidon;

import io.helidon.webserver.WebServer;
import jakarta.ws.rs.ProcessingException;
import jakarta.ws.rs.core.Application;
import org.glassfish.jersey.server.spi.ContainerProvider;

public class HelidonHttpContainerProvider implements ContainerProvider {
@Override
public <T> T createContainer(Class<T> type, Application application) throws ProcessingException {
if (type != WebServer.class && type != HelidonHttpContainer.class) {
return null;
}
return type.cast(new HelidonHttpContainer(application));
}
}
Loading

0 comments on commit b3bac21

Please sign in to comment.