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

Added support for HK2 factories, binders to comply with documentation. #5614

Merged
merged 1 commit into from
Apr 19, 2024
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
@@ -0,0 +1,21 @@
/*
* 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
*/

/**
* Jersey innate injection related packages. The innate packages will not be opened by JPMS outside of Jersey.
* Not for public use.
*/
package org.glassfish.jersey.innate.inject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.innate.inject.spi;

import javax.ws.rs.RuntimeType;
import java.util.List;

/**
* Provide a list of classes or interfaces the InjectionManager can support.
*/
public interface ExternalRegistrables {

/**
* Contract - RuntimeType pair. For a contract applicable on both client and server, use {@code null} as RuntimeType.
*/
public static final class ClassRuntimeTypePair {
private final Class<?> contract;
private final RuntimeType runtimeType;

public ClassRuntimeTypePair(Class<?> contract, RuntimeType runtimeType) {
this.contract = contract;
this.runtimeType = runtimeType;
}

public Class<?> getContract() {
return contract;
}

public RuntimeType getRuntimeType() {
return runtimeType;
}
}

/**
* List of contracts that can be registered into Jersey to be passed by the external injection framework.
* @return list of contracts allowed to be registered in Jersey.
*/
List<ClassRuntimeTypePair> registrableContracts();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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
*/

/**
* Jersey innate injection related packages. The innate packages will not be opened by JPMS outside of Jersey.
* Not for public use.
*/
package org.glassfish.jersey.innate.inject.spi;
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* 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
*/

/**
* Jersey innate packages. The innate packages will not be opened by JPMS outside of Jersey.
* Not for public use.
*/
package org.glassfish.jersey.innate;
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
Expand Down Expand Up @@ -43,7 +43,9 @@
import javax.annotation.Priority;

import org.glassfish.jersey.JerseyPriorities;
import org.glassfish.jersey.innate.inject.spi.ExternalRegistrables;
import org.glassfish.jersey.internal.LocalizationMessages;
import org.glassfish.jersey.internal.ServiceFinder;
import org.glassfish.jersey.model.ContractProvider;
import org.glassfish.jersey.model.internal.RankedComparator;
import org.glassfish.jersey.model.internal.RankedProvider;
Expand Down Expand Up @@ -103,6 +105,14 @@ private static Map<Class<?>, ProviderRuntime> getExternalProviderInterfaces() {
interfaces.putAll(JAX_RS_PROVIDER_INTERFACE_WHITELIST);
interfaces.put(javax.ws.rs.core.Feature.class, ProviderRuntime.BOTH);
interfaces.put(Binder.class, ProviderRuntime.BOTH);

try {
ServiceFinder<ExternalRegistrables> registerables = ServiceFinder.find(ExternalRegistrables.class, true);
registerables.forEach(regs -> regs.registrableContracts()
.forEach(pair -> interfaces.put(pair.getContract(), ProviderRuntime.fromRuntimeType(pair.getRuntimeType()))));
} catch (Throwable t) {
LOGGER.warning(LocalizationMessages.ERROR_EXTERNAL_REGISTERABLES_IGNORED(t.getMessage()));
}
return interfaces;
}

Expand All @@ -119,6 +129,10 @@ private ProviderRuntime(final RuntimeType runtime) {
public RuntimeType getRuntime() {
return runtime;
}

private static ProviderRuntime fromRuntimeType(RuntimeType type) {
return type == null ? BOTH : (type == RuntimeType.SERVER ? SERVER : CLIENT);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2012, 2020 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2012, 2024 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2018 Payara Foundation and/or its affiliates.
#
# This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -39,6 +39,7 @@ error.entity.stream.closed=Entity input stream has already been closed.
error.entity.provider.basictypes.character.morechars=A single character expected in the entity input stream.
error.entity.provider.basictypes.constructor=Error converting entity to {0} type by single String constructor.
error.entity.provider.basictypes.unkwnown=Unsupported basic type {0}.
error.external.registerables.ignored=Error reading external registrable contracts: {0}.
error.finding.exception.mapper.type=Could not find exception type for given ExceptionMapper class: {0}.
error.interceptor.reader.proceed=Last reader interceptor in the chain called the method proceed.
error.interceptor.writer.proceed=Last writer interceptor in the chain called the method proceed.
Expand Down
Loading