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

Avoid exceptions when extension objects cannot be retrieved #18

Merged
merged 1 commit into from
Jul 17, 2023
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
Expand Up @@ -233,7 +233,7 @@ public void modifiedService(ServiceReference<Object> reference, ServiceReference
@Override
public void removedService(ServiceReference<Object> reference, ServiceReference<?> service) {
JerseyExtensionProvider provider = new JerseyExtensionProvider(
context.getServiceObjects(reference), getServiceProps(reference));
null, getServiceProps(reference));
clearMap(extensionMap, provider);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.logging.Logger;
import java.util.stream.Collectors;

import org.eclipse.osgitech.rest.dto.DTOConverter;
import org.eclipse.osgitech.rest.proxy.ExtensionProxyFactory;
Expand Down Expand Up @@ -54,6 +57,8 @@
*/
public class JerseyExtensionProvider extends JerseyApplicationContentProvider {

private static final Logger logger = Logger.getLogger("jersey.extensionProvider");

private static final List<String> POSSIBLE_INTERFACES = Arrays.asList(new String[] {
ContainerRequestFilter.class.getName(),
ContainerResponseFilter.class.getName(),
Expand Down Expand Up @@ -154,7 +159,14 @@ protected String getJakartarsResourceConstant() {
* @return
*/
public JerseyExtension getExtension(FeatureContext context) {
Object service = getProviderObject().getService();
Object service = Optional.ofNullable(getProviderObject())
.map(ServiceObjects::getService)
.orElse(null);
if(service == null) {
logger.severe("Unable to get the service object for service " + getId() + " with name " + getName() +
" and contracts" + Arrays.stream(contracts).map(Class::getName).collect(Collectors.joining(", ")));
return null;
}
InjectionManagerProvider.getInjectionManager(context).inject(service);
return new JerseyExtension(service);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ public boolean configure(FeatureContext context) {

JerseyExtension je = extension.getExtension(context);

extensionInstanceTrackingMap.put(extension, je);
Map<Class<?>,Integer> contractPriorities = je.getContractPriorities();
if (contractPriorities.isEmpty()) {
context.register(je.getExtensionObject(), priority.getAndIncrement());
} else {
context.register(je.getExtensionObject(), je.getContractPriorities());
if(je != null) {
extensionInstanceTrackingMap.put(extension, je);
Map<Class<?>,Integer> contractPriorities = je.getContractPriorities();
if (contractPriorities.isEmpty()) {
context.register(je.getExtensionObject(), priority.getAndIncrement());
} else {
context.register(je.getExtensionObject(), je.getContractPriorities());
}
}
});
return true;
Expand Down