From 399dd20263750cd0823127cd56ab127700edf95a Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Mon, 28 Oct 2024 11:56:26 +0000 Subject: [PATCH 1/6] docs: describe how to use ApplicationPrereq --- .../lifecycle/ApplicationPrereq.java | 122 ++++++++++++++++-- 1 file changed, 114 insertions(+), 8 deletions(-) diff --git a/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java b/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java index cdbad0249b0..a2b0a626417 100644 --- a/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java +++ b/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2020 IBM Corporation and others. + * Copyright (c) 2020,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -13,12 +13,118 @@ package com.ibm.wsspi.application.lifecycle; /** - * This a marker interface for Service components that must be present before wsspi.applications are started. - * - * Implementors must also provide a config element in their defaultInstances.xml as follows: - * {@code - * - * } + * A marker interface for service components indicating + * they must be present before applications are started. + *

+ * Liberty's processing of configuration and metatype will discover + * these declarations and wait for the configured services before + * allowing applications to start. + *

+ * + * Every implementor must observe the following conventions: + *
    + *
  1. Edit the {@code bnd.bnd} for the bundle to instruct bnd appropriately: + *
      + *
    • Process the class for declarative services annotations: + *
      + * -dsannotations: com.acme.Widget
      + *         
      + *
    • + *
    • Add the metatype and default instances to the bundle: + *
      + * Include-Resource: OSGI-INF=resources/OSGI-INF
      + *         
      + *
    • + *
    • Declare the default instances (if required — see below): + *
      + * IBM-Default-Config: OSGI-INF/wlp/defaultInstances.xml
      + *         
      + *
    • + *
    • Add the app manager lifecycle bundle to the build path: + *
      + * -buildpath: com.ibm.ws.app.manager.lifecycle;version=latest
      + *         
      + *
    • + *
    + *
  2. + *
  3. The implementation must declare itself as a declarative services (DS) component. + *
      + *
    • The component declaration must provide {@link ApplicationPrereq} as a service.
      + * + * If this is not done, the configured component instance will never be discovered, and applications will not start up. + * + *
    • + *
    • The component declaration must require configuration.
    • + *
    + * e.g.: + *
    + * package com.acme;
    + * {@code @Component}(
    + *         service = ApplicationPrereq.class,
    + *         configurationPolicy = REQUIRE,
    + *         configurationPid = "com.acme.Widget",
    + *         property = "service.vendor=Acme")
    + * public class Widget implements ApplicationPrereq {…}
    + *     
    + * + * Note: Components can be declared in the Java source or in the {@code bnd.bnd} file.
    + * Verify the component xml in the generated bundle, + * e.g. {@code OSGI-INF/com.acme.Widget.xml} + *
    + *
  4. + *
  5. + * The implementing bundle must provide an {@code OCD} and a {@code Designate} + * for the configuration in an XML file in {@code resources/OSGI-INF/metatype/}, + * usually {@code metatype.xml}. + *
      + *
    • the OCD must declare its objectClass to be {@link ApplicationPrereq}
      + * e.g. + *
      + * {@code }
      + * ⋮
      + * {@code }
      + *         
      + * + * Declaring the objectClass correctly allows every configuration of this OCD to be discovered. + * Application containers will start only after the configured component instances become available. + * + *
    • + *
    • + * Either the Designate must use a factoryPid instead of a pid, + *
      + * {@code }
      + *   {@code }
      + * {@code }
      + *         
      + *       
      + *       
    • + * Or the OCD must contain a required AD without a default value: + *
      + * {@code }
      + *   {@code }
      + * {@code }
      + *         
      + * + * If the delegate uses a pid and the OCD has no required non-default AD, + * Liberty's configuration processing may not be invoked for this OCD, + * and the counting of application prereqs may fail. + * This can be very difficult to debug! + * + *
    • + * + * + *
    • The configuration may be user-specified in the server.xml or provided in the bundle's default instances: + *
      + * {@code }
      + *   {@code }
      + * {@code }
      + *     
      + *
    • + * */ public interface ApplicationPrereq { } From 09e0b29786dd2cb1e911035a0f2100ab869d4428 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Mon, 28 Oct 2024 12:05:47 +0000 Subject: [PATCH 2/6] fix: put an ApplicationPrereq in jndi.iiop --- dev/com.ibm.ws.jndi.iiop/bnd.bnd | 9 ++++-- .../resources/OSGI-INF/metatype/metatype.xml | 30 +++++++++++++++++++ .../OSGI-INF/wlp/defaultInstances.xml | 15 ++++++++++ .../jndi/iiop/CorbanameUrlContextFactory.java | 27 ++++++++++------- 4 files changed, 68 insertions(+), 13 deletions(-) create mode 100644 dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml create mode 100644 dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml diff --git a/dev/com.ibm.ws.jndi.iiop/bnd.bnd b/dev/com.ibm.ws.jndi.iiop/bnd.bnd index 38850c12205..ec0abfaf6e2 100644 --- a/dev/com.ibm.ws.jndi.iiop/bnd.bnd +++ b/dev/com.ibm.ws.jndi.iiop/bnd.bnd @@ -1,10 +1,10 @@ #******************************************************************************* -# Copyright (c) 2017,2021 IBM Corporation and others. +# Copyright (c) 2017,2024 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License 2.0 # which accompanies this distribution, and is available at # http://www.eclipse.org/legal/epl-2.0/ -# +# # SPDX-License-Identifier: EPL-2.0 # # Contributors: @@ -21,7 +21,7 @@ Bundle-Description: This bundle provides a way to access CosNaming via JNDI; ver WS-TraceGroup: Naming # For each exported package, create (in that package) a package-info.java -# file, and place an @version javadoc tag in package-level javadoc. +# file, and place an @version javadoc tag in package-level javadoc. # Append ";provide:=true" if this bundle also provides an implementation # for the exported API. @@ -33,6 +33,9 @@ Import-Package: \ javax.rmi.*;version="[2.4,3.0)", \ * +Include-Resource: OSGI-INF=resources/OSGI-INF +IBM-Default-Config: OSGI-INF/wlp/defaultInstances.xml + -dsannotations-inherit: true -dsannotations: com.ibm.ws.jndi.iiop.*UrlContextFactory diff --git a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml new file mode 100644 index 00000000000..13fc53f5656 --- /dev/null +++ b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml new file mode 100644 index 00000000000..2d411e6a806 --- /dev/null +++ b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml @@ -0,0 +1,15 @@ + + + + diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java index 3b68ae0842a..22597c39ed0 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -12,9 +12,8 @@ *******************************************************************************/ package com.ibm.ws.jndi.iiop; -import static org.osgi.service.component.annotations.ConfigurationPolicy.IGNORE; +import static org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.BitSet; import java.util.regex.Matcher; @@ -26,10 +25,18 @@ import com.ibm.websphere.ras.Tr; import com.ibm.websphere.ras.TraceComponent; +import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -@Component(configurationPolicy=IGNORE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaname"}) -public class CorbanameUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent { +/** + * One of the context factories should be an {@link ApplicationPrereq} + * to represent this bundle being up and running. + * This (the most commonly used one) was chosen. + */ + + +@Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaname"}) +public class CorbanameUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { static class Escaper{ static final TraceComponent tc = Tr.register(CorbanameUrlContextFactory.Escaper.class); private static final Pattern PERCENT_TRIPLET = Pattern.compile("%(?:[0-9a-f]{2}|[0-9A-F]{2})"); @@ -88,7 +95,7 @@ public static String escapeCorbanameUrlIfNecessary(String url) { // escape dots n = n.replaceAll("\\.", "\\\\."); - // + // sn.append(n).append("/"); } @@ -118,8 +125,8 @@ public static String escapeCorbanameUrlIfNecessary(String url) { return escaped.toString(); } - + } - - + + } From fab2ffc51b6f5400837231dd14d1d4fa69ab01f0 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 29 Oct 2024 14:32:33 +0000 Subject: [PATCH 3/6] refactor: simplify DS declarations --- dev/com.ibm.ws.jndi.iiop/bnd.bnd | 49 +++++++++---------- .../jndi/iiop/CorbalocUrlContextFactory.java | 14 ++++-- .../jndi/iiop/CorbanameUrlContextFactory.java | 16 +++--- .../jndi/iiop/InitialContextFactoryImpl.java | 23 +++++---- .../ws/jndi/iiop/IorUrlContextFactory.java | 14 ++++-- .../ibm/ws/jndi/iiop/UrlContextFactory.java | 29 ++++------- 6 files changed, 77 insertions(+), 68 deletions(-) diff --git a/dev/com.ibm.ws.jndi.iiop/bnd.bnd b/dev/com.ibm.ws.jndi.iiop/bnd.bnd index ec0abfaf6e2..8305fbbac67 100644 --- a/dev/com.ibm.ws.jndi.iiop/bnd.bnd +++ b/dev/com.ibm.ws.jndi.iiop/bnd.bnd @@ -28,15 +28,14 @@ WS-TraceGroup: Naming Export-Package: com.ibm.ws.jndi.iiop;thread-context=true;mandatory:=thread-context Import-Package: \ - !com.ibm.ws.jndi.iiop, \ - org.omg.*;version="[2.4,3.0)", \ - javax.rmi.*;version="[2.4,3.0)", \ - * + !com.ibm.ws.jndi.iiop, \ + org.omg.*;version="[2.4,3.0)", \ + javax.rmi.*;version="[2.4,3.0)", \ + * Include-Resource: OSGI-INF=resources/OSGI-INF IBM-Default-Config: OSGI-INF/wlp/defaultInstances.xml --dsannotations-inherit: true -dsannotations: com.ibm.ws.jndi.iiop.*UrlContextFactory instrument.classesExcludes: com/ibm/ws/jndi/iiop/*.class @@ -47,25 +46,25 @@ instrument.classesExcludes: com/ibm/ws/jndi/iiop/*.class # dependencies of a classpath declared to and resolved by the bnd tooling. Sigh. # Therefore, all three are declared here so that build.gradle can find and endorse them. -buildpath: \ - com.ibm.ws.org.apache.yoko.osgi.1.5;version=latest,\ - com.ibm.ws.org.apache.yoko.corba.spec.1.5;version=latest,\ - com.ibm.ws.org.apache.yoko.rmi.spec.1.5;version=latest,\ - com.ibm.websphere.org.osgi.core;version=latest,\ - com.ibm.wsspi.org.osgi.service.component.annotations;version=latest,\ - com.ibm.websphere.appserver.spi.logging;version=latest,\ - com.ibm.ws.app.manager.lifecycle;version=latest,\ - com.ibm.ws.container.service;version=latest,\ - com.ibm.ws.jndi;version=latest,\ - com.ibm.ws.transport.iiop;version=latest, \ - com.ibm.ws.org.osgi.annotation.versioning;version=latest + com.ibm.ws.org.apache.yoko.osgi.1.5;version=latest,\ + com.ibm.ws.org.apache.yoko.corba.spec.1.5;version=latest,\ + com.ibm.ws.org.apache.yoko.rmi.spec.1.5;version=latest,\ + com.ibm.websphere.org.osgi.core;version=latest,\ + com.ibm.wsspi.org.osgi.service.component.annotations;version=latest,\ + com.ibm.websphere.appserver.spi.logging;version=latest,\ + com.ibm.ws.app.manager.lifecycle;version=latest,\ + com.ibm.ws.container.service;version=latest,\ + com.ibm.ws.jndi;version=latest,\ + com.ibm.ws.transport.iiop;version=latest, \ + com.ibm.ws.org.osgi.annotation.versioning;version=latest -testpath: \ - ../build.sharedResources/lib/junit/old/junit.jar;version=file, \ - org.hamcrest:hamcrest-all;version=1.3, \ - org.apache.bcel:bcel;version=6.6.1, \ - com.ibm.ws.org.apache.commons.lang3;version=latest,\ - com.ibm.ws.org.apache.yoko.osgi.1.5;version=latest,\ - com.ibm.ws.org.apache.yoko.util.1.5;version=latest,\ - com.ibm.ws.org.apache.yoko.rmi.impl.1.5;version=latest,\ - com.ibm.ws.org.apache.yoko.core.1.5;version=latest, \ - com.ibm.ws.logging.core;version=latest + ../build.sharedResources/lib/junit/old/junit.jar;version=file, \ + org.hamcrest:hamcrest-all;version=1.3, \ + org.apache.bcel:bcel;version=6.6.1, \ + com.ibm.ws.org.apache.commons.lang3;version=latest,\ + com.ibm.ws.org.apache.yoko.osgi.1.5;version=latest,\ + com.ibm.ws.org.apache.yoko.util.1.5;version=latest,\ + com.ibm.ws.org.apache.yoko.rmi.impl.1.5;version=latest,\ + com.ibm.ws.org.apache.yoko.core.1.5;version=latest, \ + com.ibm.ws.logging.core;version=latest diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java index f6556bcaaf4..2f95da795e5 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -16,9 +16,17 @@ import javax.naming.spi.ObjectFactory; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; @Component(configurationPolicy=IGNORE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaloc"}) -public class CorbalocUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent {} +public class CorbalocUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent { + @Activate + public CorbalocUrlContextFactory(@Reference ClientORBRef orbRef) { + super(orbRef); + } +} diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java index 22597c39ed0..20bc9ab2de8 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java @@ -21,20 +21,21 @@ import javax.naming.spi.ObjectFactory; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; import com.ibm.websphere.ras.Tr; import com.ibm.websphere.ras.TraceComponent; +import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; /** - * One of the context factories should be an {@link ApplicationPrereq} - * to represent this bundle being up and running. - * This (the most commonly used one) was chosen. + * One of the context factories in this bundle should be an {@link ApplicationPrereq}. + * This will cause applications to wait until this bundle is ready. + * This URL context factory was chosen since "corbaname:" is the most common lookup protocol. */ - - @Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaname"}) public class CorbanameUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { static class Escaper{ @@ -128,5 +129,8 @@ public static String escapeCorbanameUrlIfNecessary(String url) { } - + @Activate + public CorbanameUrlContextFactory(@Reference ClientORBRef orbRef) { + super(orbRef); + } } diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/InitialContextFactoryImpl.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/InitialContextFactoryImpl.java index 14710547461..9d50f6ae15a 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/InitialContextFactoryImpl.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/InitialContextFactoryImpl.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2015 IBM Corporation and others. + * Copyright (c) 2015,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -12,6 +12,8 @@ *******************************************************************************/ package com.ibm.ws.jndi.iiop; +import static org.osgi.framework.FrameworkUtil.getBundle; + import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Hashtable; @@ -21,14 +23,11 @@ import javax.naming.NamingException; import org.omg.CORBA.ORB; -import org.osgi.framework.Bundle; -import org.osgi.framework.FrameworkUtil; import com.ibm.websphere.ras.Tr; import com.ibm.websphere.ras.TraceComponent; -public class InitialContextFactoryImpl implements - javax.naming.spi.InitialContextFactory { +public class InitialContextFactoryImpl implements javax.naming.spi.InitialContextFactory { static final TraceComponent tc = Tr .register(InitialContextFactoryImpl.class); @@ -53,17 +52,17 @@ public void run() { } @Override - public Context getInitialContext(Hashtable environment) - throws NamingException { + public Context getInitialContext(Hashtable environment) throws NamingException { final String methodName = "getInitialContext(): "; - // if we are in a bundle, then defer to the corbaname lookup - Bundle b = FrameworkUtil.getBundle(InitialContextFactoryImpl.class); - if (b == null) { + // if NOT in a bundle, create and return a context object + if (getBundle(InitialContextFactoryImpl.class) == null) { if (tc.isDebugEnabled()) Tr.debug(tc, methodName + "using internal ORB instance"); return new JndiCosNamingContext(OrbHolder.INSTANCE.orb, environment); } - // if we get here, we are in a bundle + // if the code reaches here, it is running in a bundle + // so defer to the corbaloc handler to retrieve the context + String uri = JndiCosNamingContext.getProviderUri(environment); // if the provider uri is unavailable, use the default if (uri == null) { diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java index 5c6be443a11..9f8a32fe4ac 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -16,9 +16,17 @@ import javax.naming.spi.ObjectFactory; +import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Reference; +import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; @Component(configurationPolicy=IGNORE,property={"service.vendor=ibm","osgi.jndi.url.scheme=ior"}) -public class IorUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent {} +public class IorUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent { + @Activate + public IorUrlContextFactory(@Reference ClientORBRef orbRef) { + super(orbRef); + } +} diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/UrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/UrlContextFactory.java index 4aa0e5e9bae..948dd830ea3 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/UrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/UrlContextFactory.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -23,8 +23,6 @@ import javax.naming.OperationNotSupportedException; import javax.naming.spi.ObjectFactory; -import org.osgi.service.component.annotations.Reference; - import com.ibm.websphere.ras.Tr; import com.ibm.websphere.ras.TraceComponent; import com.ibm.ws.runtime.metadata.ComponentMetaData; @@ -34,21 +32,15 @@ import com.ibm.wsspi.application.lifecycle.ApplicationRecycleContext; public abstract class UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent { - static final TraceComponent tc = Tr.register(UrlContextFactory.class); - - private ClientORBRef orbRef; + + private final ClientORBRef orbRef; private final Set appsToRecycle = Collections.newSetFromMap(new ConcurrentHashMap()); - - @Reference - protected void setIIOPClient(ClientORBRef orbRef) { + + protected UrlContextFactory(ClientORBRef orbRef) { this.orbRef = orbRef; } - - protected void unsetIIOPClient(ClientORBRef orbRef) { - if(this.orbRef==orbRef) orbRef = null; - } - + @Override public Object getObjectInstance(Object o, Name n, Context c, Hashtable env) throws Exception { final String methodName = "getObjectInstance(): "; @@ -64,20 +56,20 @@ public Object getObjectInstance(Object o, Name n, Context c, Hashtable env registerCaller(); return new OrbContext(orbRef.getORB(), env); } - + if (o instanceof String) { if (tc.isDebugEnabled()) Tr.debug(tc, methodName + "object was a string - performing a lookup on new OrbContext"); registerCaller(); return new OrbContext(orbRef.getORB(), env).lookup((String) o); } - + if (o instanceof String[]) { if (tc.isDebugEnabled()) Tr.debug(tc, methodName + "object was a string[] - ignoring"); } throw new OperationNotSupportedException(); } - + private void registerCaller() { ComponentMetaData cData = ComponentMetaDataAccessorImpl.getComponentMetaDataAccessor().getComponentMetaData(); if (cData != null) @@ -95,5 +87,4 @@ public Set getDependentApplications() { appsToRecycle.removeAll(members); return members; } - } From 0d5b86b0325f127a72c0392661573fc7867794b6 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 29 Oct 2024 15:12:39 +0000 Subject: [PATCH 4/6] fix: make *all* URL context factories app prereqs --- .../resources/OSGI-INF/metatype/metatype.xml | 18 ++++++++++++++++++ .../OSGI-INF/wlp/defaultInstances.xml | 2 ++ .../jndi/iiop/CorbalocUrlContextFactory.java | 7 ++++--- .../jndi/iiop/CorbanameUrlContextFactory.java | 5 ----- .../ibm/ws/jndi/iiop/IorUrlContextFactory.java | 7 ++++--- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml index 13fc53f5656..f391cd8dad3 100644 --- a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml +++ b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml @@ -25,6 +25,24 @@ + + + + + + + + + + + + + + + + diff --git a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml index 2d411e6a806..d3728b123e5 100644 --- a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml +++ b/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/wlp/defaultInstances.xml @@ -12,4 +12,6 @@ --> + + diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java index 2f95da795e5..87d624e5a7b 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java @@ -12,7 +12,7 @@ *******************************************************************************/ package com.ibm.ws.jndi.iiop; -import static org.osgi.service.component.annotations.ConfigurationPolicy.IGNORE; +import static org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE; import javax.naming.spi.ObjectFactory; @@ -21,10 +21,11 @@ import org.osgi.service.component.annotations.Reference; import com.ibm.ws.transport.iiop.spi.ClientORBRef; +import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -@Component(configurationPolicy=IGNORE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaloc"}) -public class CorbalocUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent { +@Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaloc"}) +public class CorbalocUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { @Activate public CorbalocUrlContextFactory(@Reference ClientORBRef orbRef) { super(orbRef); diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java index 20bc9ab2de8..76ff265c74f 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java @@ -31,11 +31,6 @@ import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -/** - * One of the context factories in this bundle should be an {@link ApplicationPrereq}. - * This will cause applications to wait until this bundle is ready. - * This URL context factory was chosen since "corbaname:" is the most common lookup protocol. - */ @Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaname"}) public class CorbanameUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { static class Escaper{ diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java index 9f8a32fe4ac..e60d0feecc9 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java @@ -12,7 +12,7 @@ *******************************************************************************/ package com.ibm.ws.jndi.iiop; -import static org.osgi.service.component.annotations.ConfigurationPolicy.IGNORE; +import static org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE; import javax.naming.spi.ObjectFactory; @@ -21,10 +21,11 @@ import org.osgi.service.component.annotations.Reference; import com.ibm.ws.transport.iiop.spi.ClientORBRef; +import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -@Component(configurationPolicy=IGNORE,property={"service.vendor=ibm","osgi.jndi.url.scheme=ior"}) -public class IorUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent { +@Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=ior"}) +public class IorUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { @Activate public IorUrlContextFactory(@Reference ClientORBRef orbRef) { super(orbRef); From 4b856805198fbbd4001b7f33e9a951d1dd69b708 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:09:57 +0000 Subject: [PATCH 5/6] refactor: move escape method to util class --- .../jndi/iiop/CorbanameUrlContextFactory.java | 98 ------------------- .../src/com/ibm/ws/jndi/iiop/CosNameUtil.java | 98 ++++++++++++++++++- .../src/com/ibm/ws/jndi/iiop/OrbContext.java | 8 +- .../jndi/iiop/CorbanameEscapeTestSuite.java | 8 +- .../test/com/ibm/ws/jndi/iiop/TestFacade.java | 8 +- 5 files changed, 108 insertions(+), 112 deletions(-) diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java index 76ff265c74f..e9bc736cd45 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java @@ -14,116 +14,18 @@ import static org.osgi.service.component.annotations.ConfigurationPolicy.REQUIRE; -import java.nio.charset.StandardCharsets; -import java.util.BitSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - import javax.naming.spi.ObjectFactory; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; -import com.ibm.websphere.ras.Tr; -import com.ibm.websphere.ras.TraceComponent; import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; @Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaname"}) public class CorbanameUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { - static class Escaper{ - static final TraceComponent tc = Tr.register(CorbanameUrlContextFactory.Escaper.class); - private static final Pattern PERCENT_TRIPLET = Pattern.compile("%(?:[0-9a-f]{2}|[0-9A-F]{2})"); - private static final Pattern ALL_LEGAL_CHARS = Pattern.compile("[;/:?@&=+\\$,\\-_.!~*’()0-9A-Za-z]*"); - private static final Pattern ILLEGAL_NAME = Pattern.compile("(?:[^/]\\./|\\.[^/]*\\.|[^/]\\.$)"); - private static final BitSet ESCAPE_NOT_NEEDED = new BitSet(256); - static { - for (char c : ";/:?@&=+$,-_.!~*’()".toCharArray()) { - ESCAPE_NOT_NEEDED.set(c); - } - for (char c = '0'; c <= 0xFF; c++) { - if (Character.isAlphabetic(c) || Character.isDigit(c)) { - ESCAPE_NOT_NEEDED.set(c); - } - } - } - public static String escapeCorbanameUrlIfNecessary(String url) { - final String methodName = "escapeCorbanameUrlIfNecessary(): "; - if (url == null || !!!url.startsWith("corbaname:") || url.contains("\\")) - return url; - - // split on the first hash, which MUST delimit the start of the stringified name - String[] twoParts = url.split("#", 2); - // early return if there is no stringified name - if (twoParts.length < 2) - return url; - - String stringifiedName = twoParts[1]; - if (stringifiedName.isEmpty()) - return url; - - // check if it contains any percent escapes - if (PERCENT_TRIPLET.matcher(stringifiedName).find()) { - // found some - not touching this string - // if it is badly escaped then errors will arise later - return url; - } - - // check for no need of escaping - if (ALL_LEGAL_CHARS.matcher(stringifiedName).matches()) { - // no characters need to be URI-escaped - // so just check for illegal dot patterns - Matcher matcher = ILLEGAL_NAME.matcher(stringifiedName); - if (!!!matcher.find()) { - // really, nothing needed replacing! - return url; - } - } - - StringBuilder sn = new StringBuilder(); - - for (String n : stringifiedName.split("/", -1)) { - // escape backslashes - n = n.replaceAll("\\\\", "\\\\" + "\\\\"); - - // escape dots - n = n.replaceAll("\\.", "\\\\."); - - // - sn.append(n).append("/"); - } - - sn.setLength(sn.length() - 1); - - // now for the URI escaping... - // The CosNaming specification v1.4 2.5.3.3 specifies that: - // corbaname URLs use the escape mechanism described in the Internet Engineering - // Task Force (IETF) RFC 2396. These escape rules insure that URLs can be transferred - // via a variety of transports without undergoing changes. The character escape rules for - // the stringified name portion of a corbaname are: - // - // The CosNaming spec goes on to say that only the following characters go unescaped: - // * US-ASCII alphanumeric characters - // * any of these: ; / : ? @ & = + $ , - _ . ! ~ * ’ ( ) - StringBuilder escaped = new StringBuilder(twoParts[0]).append("#"); - // since we must use an octet-based representation to URI-encode, convert the string into its UTF-8 bytes - for (byte b : sn.toString().getBytes(StandardCharsets.UTF_8)) { - if (ESCAPE_NOT_NEEDED.get(b)) { - escaped.append((char) b); - } else { - escaped.append(String.format("%%%02x", 0xFF & b)); - } - } - - if (tc.isDebugEnabled()) Tr.debug(tc, methodName + "escaped original url " + url + " to " + escaped); - return escaped.toString(); - } - - - } - @Activate public CorbanameUrlContextFactory(@Reference ClientORBRef orbRef) { super(orbRef); diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CosNameUtil.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CosNameUtil.java index 7cd39b25e8f..81c8e0bb3b9 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CosNameUtil.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CosNameUtil.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -12,17 +12,111 @@ *******************************************************************************/ package com.ibm.ws.jndi.iiop; +import java.nio.charset.StandardCharsets; +import java.util.BitSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import javax.naming.CompositeName; import javax.naming.InvalidNameException; import javax.naming.NamingException; import org.omg.CosNaming.NameComponent; +import com.ibm.websphere.ras.Tr; +import com.ibm.websphere.ras.TraceComponent; import com.ibm.ws.ffdc.annotation.FFDCIgnore; import com.ibm.ws.jndi.WSName; public enum CosNameUtil { ; + private static final TraceComponent tc = Tr.register(CosNameUtil.class); + private static final Pattern PERCENT_TRIPLET = Pattern.compile("%(?:[0-9a-f]{2}|[0-9A-F]{2})"); + private static final Pattern ALL_LEGAL_CHARS = Pattern.compile("[;/:?@&=+\\$,\\-_.!~*’()0-9A-Za-z]*"); + private static final Pattern ILLEGAL_NAME = Pattern.compile("(?:[^/]\\./|\\.[^/]*\\.|[^/]\\.$)"); + private static final BitSet ESCAPE_NOT_NEEDED = new BitSet(256); + static { + for (char c : ";/:?@&=+$,-_.!~*’()".toCharArray()) { + ESCAPE_NOT_NEEDED.set(c); + } + for (char c = '0'; c <= 0xFF; c++) { + if (Character.isAlphabetic(c) || Character.isDigit(c)) { + ESCAPE_NOT_NEEDED.set(c); + } + } + } + public static String escapeCorbanameUrlIfNecessary(String url) { + final String methodName = "escapeCorbanameUrlIfNecessary(): "; + if (url == null || !!!url.startsWith("corbaname:") || url.contains("\\")) + return url; + + // split on the first hash, which MUST delimit the start of the stringified name + String[] twoParts = url.split("#", 2); + // early return if there is no stringified name + if (twoParts.length < 2) + return url; + + String stringifiedName = twoParts[1]; + if (stringifiedName.isEmpty()) + return url; + + // check if it contains any percent escapes + if (PERCENT_TRIPLET.matcher(stringifiedName).find()) { + // found some - not touching this string + // if it is badly escaped then errors will arise later + return url; + } + + // check for no need of escaping + if (ALL_LEGAL_CHARS.matcher(stringifiedName).matches()) { + // no characters need to be URI-escaped + // so just check for illegal dot patterns + Matcher matcher = ILLEGAL_NAME.matcher(stringifiedName); + if (!!!matcher.find()) { + // really, nothing needed replacing! + return url; + } + } + + StringBuilder sn = new StringBuilder(); + + for (String n : stringifiedName.split("/", -1)) { + // escape backslashes + n = n.replaceAll("\\\\", "\\\\" + "\\\\"); + + // escape dots + n = n.replaceAll("\\.", "\\\\."); + + // + sn.append(n).append("/"); + } + + sn.setLength(sn.length() - 1); + + // now for the URI escaping... + // The CosNaming specification v1.4 2.5.3.3 specifies that: + // corbaname URLs use the escape mechanism described in the Internet Engineering + // Task Force (IETF) RFC 2396. These escape rules insure that URLs can be transferred + // via a variety of transports without undergoing changes. The character escape rules for + // the stringified name portion of a corbaname are: + // + // The CosNaming spec goes on to say that only the following characters go unescaped: + // * US-ASCII alphanumeric characters + // * any of these: ; / : ? @ & = + $ , - _ . ! ~ * ’ ( ) + StringBuilder escaped = new StringBuilder(twoParts[0]).append("#"); + // since we must use an octet-based representation to URI-encode, convert the string into its UTF-8 bytes + for (byte b : sn.toString().getBytes(StandardCharsets.UTF_8)) { + if (ESCAPE_NOT_NEEDED.get(b)) { + escaped.append((char) b); + } else { + escaped.append(String.format("%%%02x", 0xFF & b)); + } + } + + if (tc.isDebugEnabled()) Tr.debug(tc, methodName + "escaped original url " + url + " to " + escaped); + return escaped.toString(); + } + static NameComponent[] cosify(WSName name) { NameComponent[] cosName = new NameComponent[name.size()]; for (int i = 0; i < cosName.length; i++) diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/OrbContext.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/OrbContext.java index 04677415732..56433d6feed 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/OrbContext.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/OrbContext.java @@ -1,10 +1,10 @@ /******************************************************************************* - * Copyright (c) 2017 IBM Corporation and others. + * Copyright (c) 2017,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -12,6 +12,8 @@ *******************************************************************************/ package com.ibm.ws.jndi.iiop; +import static com.ibm.ws.jndi.iiop.CosNameUtil.escapeCorbanameUrlIfNecessary; + import java.util.Hashtable; import javax.naming.Binding; @@ -50,7 +52,7 @@ public Object lookup(Name name) throws NamingException { @FFDCIgnore(NO_IMPLEMENT.class) public Object lookup(String name) throws NamingException { final String methodName = "lookup(): "; - name = CorbanameUrlContextFactory.Escaper.escapeCorbanameUrlIfNecessary(name); + name = escapeCorbanameUrlIfNecessary(name); if (tc.isDebugEnabled()) Tr.debug(tc, methodName + ""); org.omg.CORBA.Object result = orb.string_to_object(name); if (tc.isDebugEnabled()) Tr.debug(tc, methodName + ": orb.string_to_object() returned "+result); diff --git a/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/CorbanameEscapeTestSuite.java b/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/CorbanameEscapeTestSuite.java index 61a6819d9fb..938e7289b63 100755 --- a/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/CorbanameEscapeTestSuite.java +++ b/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/CorbanameEscapeTestSuite.java @@ -1,10 +1,10 @@ /* *************************************************************************** - * Copyright (c) 2015 IBM Corporation and others. + * Copyright (c) 2015,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -12,6 +12,8 @@ * ***************************************************************************/ package com.ibm.ws.jndi.iiop; +import static com.ibm.ws.jndi.iiop.CosNameUtil.escapeCorbanameUrlIfNecessary; + import java.util.Arrays; import java.util.List; @@ -213,7 +215,7 @@ private static void assertNoChange(String expected) { } private static void assertEscaped(String from, String to) { - String actual = TestFacade.escapeCorbanameUrlIfNecessary(from); + String actual = escapeCorbanameUrlIfNecessary(from); Assert.assertEquals(to, actual); } } diff --git a/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/TestFacade.java b/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/TestFacade.java index c500c16f977..d7b654e56e3 100755 --- a/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/TestFacade.java +++ b/dev/com.ibm.ws.jndi.iiop/test/com/ibm/ws/jndi/iiop/TestFacade.java @@ -1,10 +1,10 @@ /* *************************************************************************** - * Copyright (c) 2015 IBM Corporation and others. + * Copyright (c) 2015,2024 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-2.0/ - * + * * SPDX-License-Identifier: EPL-2.0 * * Contributors: @@ -91,10 +91,6 @@ private static NameComponent[] cosName(String s) throws Exception { return result; } - public static String escapeCorbanameUrlIfNecessary(String url) { - return CorbanameUrlContextFactory.Escaper.escapeCorbanameUrlIfNecessary(url); - } - private static class TestFacadeDelegate { final short port; From 19782d242953339deb3c2068f23f9ffb98282c12 Mon Sep 17 00:00:00 2001 From: Joe Chacko <143064+joe-chacko@users.noreply.github.com> Date: Wed, 30 Oct 2024 01:25:39 +0000 Subject: [PATCH 6/6] refactor: use annotations instead of XML for metatype --- .../application/lifecycle/ApplicationPrereq.java | 3 +-- dev/com.ibm.ws.jndi.iiop/bnd.bnd | 3 +++ .../OSGI-INF/metatype => }/metatype.xml | 3 +-- .../ws/jndi/iiop/CorbalocUrlContextFactory.java | 16 ++++++++++++++-- .../ws/jndi/iiop/CorbanameUrlContextFactory.java | 14 +++++++++++++- .../ibm/ws/jndi/iiop/IorUrlContextFactory.java | 14 +++++++++++++- 6 files changed, 45 insertions(+), 8 deletions(-) rename dev/com.ibm.ws.jndi.iiop/{resources/OSGI-INF/metatype => }/metatype.xml (95%) diff --git a/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java b/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java index a2b0a626417..16386eb0dba 100644 --- a/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java +++ b/dev/com.ibm.ws.app.manager.lifecycle/src/com/ibm/wsspi/application/lifecycle/ApplicationPrereq.java @@ -126,5 +126,4 @@ * * */ -public interface ApplicationPrereq { -} +public interface ApplicationPrereq {} diff --git a/dev/com.ibm.ws.jndi.iiop/bnd.bnd b/dev/com.ibm.ws.jndi.iiop/bnd.bnd index 8305fbbac67..e13ad995ce7 100644 --- a/dev/com.ibm.ws.jndi.iiop/bnd.bnd +++ b/dev/com.ibm.ws.jndi.iiop/bnd.bnd @@ -37,6 +37,7 @@ Include-Resource: OSGI-INF=resources/OSGI-INF IBM-Default-Config: OSGI-INF/wlp/defaultInstances.xml -dsannotations: com.ibm.ws.jndi.iiop.*UrlContextFactory +-metatypeannotations: com.ibm.ws.jndi.iiop.*UrlContextFactory* instrument.classesExcludes: com/ibm/ws/jndi/iiop/*.class @@ -51,6 +52,8 @@ instrument.classesExcludes: com/ibm/ws/jndi/iiop/*.class com.ibm.ws.org.apache.yoko.rmi.spec.1.5;version=latest,\ com.ibm.websphere.org.osgi.core;version=latest,\ com.ibm.wsspi.org.osgi.service.component.annotations;version=latest,\ + com.ibm.wsspi.org.osgi.service.metatype.annotations;version=latest, \ + com.ibm.ws.bnd.annotations;version=latest, \ com.ibm.websphere.appserver.spi.logging;version=latest,\ com.ibm.ws.app.manager.lifecycle;version=latest,\ com.ibm.ws.container.service;version=latest,\ diff --git a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml b/dev/com.ibm.ws.jndi.iiop/metatype.xml similarity index 95% rename from dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml rename to dev/com.ibm.ws.jndi.iiop/metatype.xml index f391cd8dad3..ac7970c61a3 100644 --- a/dev/com.ibm.ws.jndi.iiop/resources/OSGI-INF/metatype/metatype.xml +++ b/dev/com.ibm.ws.jndi.iiop/metatype.xml @@ -13,8 +13,7 @@ --> + xmlns:ibmui="http://www.ibm.com/xmlns/appservers/osgi/metatype/ui/v1.0.0"> diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java index 87d624e5a7b..f5e87ee4148 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbalocUrlContextFactory.java @@ -19,13 +19,25 @@ import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; +import com.ibm.ws.bnd.metatype.annotation.Ext; import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -@Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaloc"}) -public class CorbalocUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { +@ObjectClassDefinition(name = "internal", description = "internal use only") +@Ext.ObjectClassClass(ApplicationPrereq.class) +@interface CorbalocUrlContextFactoryConfig { + @AttributeDefinition(name = "internal", description = "internal use only") + String id(); +} + +@Component(configurationPolicy = REQUIRE, property = "osgi.jndi.url.scheme=corbaloc") +@Designate(ocd = CorbalocUrlContextFactoryConfig.class) +public class CorbalocUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { @Activate public CorbalocUrlContextFactory(@Reference ClientORBRef orbRef) { super(orbRef); diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java index e9bc736cd45..4b38638502e 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/CorbanameUrlContextFactory.java @@ -19,12 +19,24 @@ import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; +import com.ibm.ws.bnd.metatype.annotation.Ext; import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -@Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=corbaname"}) +@ObjectClassDefinition(name = "internal", description = "internal use only") +@Ext.ObjectClassClass(ApplicationPrereq.class) +@interface CorbanameUrlContextFactoryConfig { + @AttributeDefinition(name = "internal", description = "internal use only") + String id(); +} + +@Component(configurationPolicy = REQUIRE, property = "osgi.jndi.url.scheme=corbaname") +@Designate(ocd = CorbanameUrlContextFactoryConfig.class) public class CorbanameUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { @Activate public CorbanameUrlContextFactory(@Reference ClientORBRef orbRef) { diff --git a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java index e60d0feecc9..3a2a5d0c689 100644 --- a/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java +++ b/dev/com.ibm.ws.jndi.iiop/src/com/ibm/ws/jndi/iiop/IorUrlContextFactory.java @@ -19,12 +19,24 @@ import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.Designate; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; +import com.ibm.ws.bnd.metatype.annotation.Ext; import com.ibm.ws.transport.iiop.spi.ClientORBRef; import com.ibm.wsspi.application.lifecycle.ApplicationPrereq; import com.ibm.wsspi.application.lifecycle.ApplicationRecycleComponent; -@Component(configurationPolicy=REQUIRE,property={"service.vendor=ibm","osgi.jndi.url.scheme=ior"}) +@ObjectClassDefinition(name = "internal", description = "internal use only") +@Ext.ObjectClassClass(ApplicationPrereq.class) +@interface IorUrlContextFactoryConfig { + @AttributeDefinition(name = "internal", description = "internal use only", required = true) + String id(); +} + +@Component(configurationPolicy = REQUIRE, property = "osgi.jndi.url.scheme=ior") +@Designate(ocd = IorUrlContextFactoryConfig.class) public class IorUrlContextFactory extends UrlContextFactory implements ObjectFactory, ApplicationRecycleComponent, ApplicationPrereq { @Activate public IorUrlContextFactory(@Reference ClientORBRef orbRef) {