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 28, 2024
1 parent 429af6c commit a75ad32
Show file tree
Hide file tree
Showing 25 changed files with 1,828 additions and 1 deletion.
103 changes: 103 additions & 0 deletions containers/helidon/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?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-http</artifactId>
<packaging>jar</packaging>
<name>jersey-container-helidon</name>

<description>Helidon (4.x) HTTP Container</description>

<dependencies>
<dependency>
<groupId>jakarta.inject</groupId>
<artifactId>jakarta.inject-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.helidon.webserver</groupId>
<artifactId>helidon-webserver</artifactId>
<version>${helidon.container.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.tracing</groupId>
<artifactId>helidon-tracing</artifactId>
<version>${helidon.container.version}</version>
</dependency>
<dependency>
<groupId>io.helidon.http</groupId>
<artifactId>helidon-http</artifactId>
<version>${helidon.container.version}</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>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</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,111 @@
/*
* 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 jakarta.ws.rs.core.Application;
import org.glassfish.jersey.server.ApplicationHandler;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.server.spi.Container;

/**
* {@link Container} running on the Helidon {@link WebServer} core, supporting Jersey routing
*
* @since 3.1.8
*/
public final class HelidonHttpContainer implements Container, WebServer {

private WebServer webServer;

private ApplicationHandler applicationHandler;

private HelidonJerseyBridge bridge;

HelidonHttpContainer(Application application, HelidonJerseyBridge bridge) {
this.applicationHandler = new ApplicationHandler(application,
new HelidonHttpContainerBinder(), bridge.getParentContext());
this.bridge = bridge;
webServer = bridge.getBuilder().build();
bridge.setContainer(this);
}

@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) {
//Helidon container does not support reload
throw new IllegalStateException(LocalizationMessages.RELOAD_NOT_SUPPORTED());
}

@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,61 @@
/*
* 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.http.ServerRequest;
import io.helidon.webserver.http.ServerResponse;
import jakarta.inject.Inject;
import jakarta.inject.Provider;
import jakarta.ws.rs.core.GenericType;
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.ReferencingFactory;
import org.glassfish.jersey.internal.util.collection.Ref;
import org.glassfish.jersey.process.internal.RequestScoped;

class HelidonHttpContainerBinder extends AbstractBinder {
@Override
protected void configure() {
bindFactory(WebServerRequestReferencingFactory.class).to(ServerRequest.class)
.proxy(true).proxyForSameScope(false)
.in(RequestScoped.class);
bindFactory(ReferencingFactory.<ServerRequest>referenceFactory()).to(new GenericType<Ref<ServerRequest>>() { })
.in(RequestScoped.class);

bindFactory(WebServerResponseReferencingFactory.class).to(ServerResponse.class)
.proxy(true).proxyForSameScope(false)
.in(RequestScoped.class);
bindFactory(ReferencingFactory.<ServerResponse>referenceFactory()).to(new GenericType<Ref<ServerResponse>>() { })
.in(RequestScoped.class);
}

private static class WebServerRequestReferencingFactory extends ReferencingFactory<ServerRequest> {

@Inject
WebServerRequestReferencingFactory(final Provider<Ref<ServerRequest>> referenceFactory) {
super(referenceFactory);
}
}

private static class WebServerResponseReferencingFactory extends ReferencingFactory<ServerResponse> {

@Inject
WebServerResponseReferencingFactory(final Provider<Ref<ServerResponse>> referenceFactory) {
super(referenceFactory);
}
}
}

Loading

0 comments on commit a75ad32

Please sign in to comment.