This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch jakarta/fixes in repository https://gitbox.apache.org/repos/asf/camel.git
commit 6d9ff02a6f390017f3f92a8f8f05671a9357d572 Author: Guillaume Nodet <[email protected]> AuthorDate: Tue Jan 3 16:29:45 2023 +0100 Additional fixes (cherry picked from commit 034027ac8b8fd040fe1c1eaa2ae6dc951c07c42d) --- .../src/main/resources/META-INF/beans.xml | 2 +- ...ion => jakarta.enterprise.inject.spi.Extension} | 0 components/camel-grpc/pom.xml | 6 +- components/camel-jackson/pom.xml | 2 +- .../jackson/JacksonJAXBAnnotationTest.java | 4 +- .../converter/JacksonConversionsPojoTest.java | 4 +- components/camel-jacksonxml/pom.xml | 2 +- .../component/jacksonxml/JacksonXMLDataFormat.java | 4 +- .../jaxb/mapper/DefaultNamespacePrefixMapper.java | 2 +- components/camel-jms/pom.xml | 12 -- components/camel-jsonpath/pom.xml | 2 +- .../camel/spring/rmi/RmiRegistryFactoryBean.java | 239 +++++++++++++++++++++ .../management/jmxInstrumentationWithConnector.xml | 2 +- components/pom.xml | 2 +- parent/pom.xml | 2 +- .../test/resources/SpringBootRestController.txt | 4 +- .../test/resources/SpringBootRestController.txt | 4 +- 17 files changed, 261 insertions(+), 32 deletions(-) diff --git a/components/camel-cdi/src/main/resources/META-INF/beans.xml b/components/camel-cdi/src/main/resources/META-INF/beans.xml index 0e3dd95de90..d2712729ec5 100644 --- a/components/camel-cdi/src/main/resources/META-INF/beans.xml +++ b/components/camel-cdi/src/main/resources/META-INF/beans.xml @@ -21,7 +21,7 @@ <scan> <exclude name="org.apache.camel.cdi.transaction.*"> - <if-class-not-available name="javax.transaction.Transaction"/> + <if-class-not-available name="jakarta.transaction.Transaction"/> </exclude> <exclude name="org.apache.camel.cdi.xml.*"/> </scan> diff --git a/components/camel-cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension b/components/camel-cdi/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension similarity index 100% rename from components/camel-cdi/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension rename to components/camel-cdi/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension diff --git a/components/camel-grpc/pom.xml b/components/camel-grpc/pom.xml index 44d74208baf..1f95daacac5 100644 --- a/components/camel-grpc/pom.xml +++ b/components/camel-grpc/pom.xml @@ -142,9 +142,11 @@ </exclusion> </exclusions> </dependency> + <!-- GRPC does not support the jakarta annotation, see https://github.com/grpc/grpc-java/issues/9179 --> <dependency> - <groupId>jakarta.annotation</groupId> - <artifactId>jakarta.annotation-api</artifactId> + <groupId>javax.annotation</groupId> + <artifactId>javax.annotation-api</artifactId> + <version>1.3.2</version> <scope>test</scope> </dependency> diff --git a/components/camel-jackson/pom.xml b/components/camel-jackson/pom.xml index 70495cef642..d5d695db0cb 100644 --- a/components/camel-jackson/pom.xml +++ b/components/camel-jackson/pom.xml @@ -50,7 +50,7 @@ <!-- testing --> <dependency> <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jaxb-annotations</artifactId> + <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId> <scope>test</scope> </dependency> <dependency> diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJAXBAnnotationTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJAXBAnnotationTest.java index 8fc84f17c76..00eec75b8af 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJAXBAnnotationTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/JacksonJAXBAnnotationTest.java @@ -16,7 +16,7 @@ */ package org.apache.camel.component.jackson; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.test.junit5.CamelTestSupport; @@ -58,7 +58,7 @@ public class JacksonJAXBAnnotationTest extends CamelTestSupport { from("direct:back").unmarshal(format).to("mock:reverse"); JacksonDataFormat formatPojo = new JacksonDataFormat(TestJAXBPojo.class); - formatPojo.setModuleClassNames(JaxbAnnotationModule.class.getName()); + formatPojo.setModuleClassNames(JakartaXmlBindAnnotationModule.class.getName()); from("direct:inPojo").marshal(formatPojo); from("direct:backPojo").unmarshal(formatPojo).to("mock:reversePojo"); diff --git a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java index 95d810d810e..085a46113ce 100644 --- a/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java +++ b/components/camel-jackson/src/test/java/org/apache/camel/component/jackson/converter/JacksonConversionsPojoTest.java @@ -16,7 +16,7 @@ */ package org.apache.camel.component.jackson.converter; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.jackson.JacksonConstants; import org.apache.camel.test.junit5.CamelTestSupport; @@ -44,7 +44,7 @@ public class JacksonConversionsPojoTest extends CamelTestSupport { context.getGlobalOptions().put(JacksonConstants.ENABLE_TYPE_CONVERTER, "true"); context.getGlobalOptions().put(JacksonConstants.TYPE_CONVERTER_TO_POJO, "true"); context.getGlobalOptions().put(JacksonConstants.TYPE_CONVERTER_MODULE_CLASS_NAMES, - JaxbAnnotationModule.class.getName()); + JakartaXmlBindAnnotationModule.class.getName()); Order order = new Order(); order.setAmount(1); diff --git a/components/camel-jacksonxml/pom.xml b/components/camel-jacksonxml/pom.xml index 30b29fc04ea..44aea076ecd 100644 --- a/components/camel-jacksonxml/pom.xml +++ b/components/camel-jacksonxml/pom.xml @@ -51,7 +51,7 @@ </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jaxb-annotations</artifactId> + <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId> </dependency> <!-- testing --> diff --git a/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java b/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java index 21f3e1629f5..18192f32afb 100644 --- a/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java +++ b/components/camel-jacksonxml/src/main/java/org/apache/camel/component/jacksonxml/JacksonXMLDataFormat.java @@ -34,7 +34,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.type.CollectionType; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.xml.deser.FromXmlParser; -import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule; +import com.fasterxml.jackson.module.jakarta.xmlbind.JakartaXmlBindAnnotationModule; import org.apache.camel.CamelContext; import org.apache.camel.CamelContextAware; import org.apache.camel.Exchange; @@ -519,7 +519,7 @@ public class JacksonXMLDataFormat extends ServiceSupport if (enableJaxbAnnotationModule) { // Enables JAXB processing - JaxbAnnotationModule module = new JaxbAnnotationModule(); + JakartaXmlBindAnnotationModule module = new JakartaXmlBindAnnotationModule(); LOG.info("Registering module: {}", module); xmlMapper.registerModule(module); } diff --git a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/mapper/DefaultNamespacePrefixMapper.java b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/mapper/DefaultNamespacePrefixMapper.java index 01cdf60618f..a8e7ef53a22 100644 --- a/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/mapper/DefaultNamespacePrefixMapper.java +++ b/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/mapper/DefaultNamespacePrefixMapper.java @@ -35,7 +35,7 @@ public class DefaultNamespacePrefixMapper extends NamespacePrefixMapper implemen @Override public String getRegistrationKey() { - return "com.sun.xml.bind.namespacePrefixMapper"; + return "org.glassfish.jaxb.namespacePrefixMapper"; } @Override diff --git a/components/camel-jms/pom.xml b/components/camel-jms/pom.xml index 4541007fa34..524da6b019f 100644 --- a/components/camel-jms/pom.xml +++ b/components/camel-jms/pom.xml @@ -116,18 +116,6 @@ <type>test-jar</type> </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-test-infra-artemis</artifactId> - <version>${project.version}</version> - <scope>test</scope> - <type>test-jar</type> - </dependency> - - - - - <dependency> <groupId>org.apache.xbean</groupId> <artifactId>xbean-spring</artifactId> diff --git a/components/camel-jsonpath/pom.xml b/components/camel-jsonpath/pom.xml index dba8decf904..20a80ef6ffe 100644 --- a/components/camel-jsonpath/pom.xml +++ b/components/camel-jsonpath/pom.xml @@ -63,7 +63,7 @@ </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jaxb-annotations</artifactId> + <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId> <optional>true</optional> </dependency> diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/rmi/RmiRegistryFactoryBean.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/rmi/RmiRegistryFactoryBean.java new file mode 100644 index 00000000000..08d5c331b8c --- /dev/null +++ b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/rmi/RmiRegistryFactoryBean.java @@ -0,0 +1,239 @@ +package org.apache.camel.spring.rmi; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; + +import java.rmi.RemoteException; +import java.rmi.registry.LocateRegistry; +import java.rmi.registry.Registry; +import java.rmi.server.RMIClientSocketFactory; +import java.rmi.server.RMIServerSocketFactory; +import java.rmi.server.UnicastRemoteObject; + +public class RmiRegistryFactoryBean implements FactoryBean<Registry>, InitializingBean, DisposableBean { + + private final Log logger = LogFactory.getLog(getClass()); + + private String host; + + private int port = Registry.REGISTRY_PORT; + + private RMIClientSocketFactory clientSocketFactory; + + private RMIServerSocketFactory serverSocketFactory; + + private Registry registry; + + private boolean alwaysCreate = false; + + private boolean created = false; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public RMIClientSocketFactory getClientSocketFactory() { + return clientSocketFactory; + } + + public void setClientSocketFactory(RMIClientSocketFactory clientSocketFactory) { + this.clientSocketFactory = clientSocketFactory; + } + + public RMIServerSocketFactory getServerSocketFactory() { + return serverSocketFactory; + } + + public void setServerSocketFactory(RMIServerSocketFactory serverSocketFactory) { + this.serverSocketFactory = serverSocketFactory; + } + + public Registry getRegistry() { + return registry; + } + + public void setRegistry(Registry registry) { + this.registry = registry; + } + + public boolean isAlwaysCreate() { + return alwaysCreate; + } + + public void setAlwaysCreate(boolean alwaysCreate) { + this.alwaysCreate = alwaysCreate; + } + + public void afterPropertiesSet() throws Exception { + // Check socket factories for registry. + if (this.clientSocketFactory instanceof RMIServerSocketFactory) { + this.serverSocketFactory = (RMIServerSocketFactory) this.clientSocketFactory; + } + if ((this.clientSocketFactory != null && this.serverSocketFactory == null) || + (this.clientSocketFactory == null && this.serverSocketFactory != null)) { + throw new IllegalArgumentException( + "Both RMIClientSocketFactory and RMIServerSocketFactory or none required"); + } + + // Fetch RMI registry to expose. + this.registry = getRegistry(this.host, this.port, this.clientSocketFactory, this.serverSocketFactory); + } + + + /** + * Locate or create the RMI registry. + * @param registryHost the registry host to use (if this is specified, + * no implicit creation of a RMI registry will happen) + * @param registryPort the registry port to use + * @param clientSocketFactory the RMI client socket factory for the registry (if any) + * @param serverSocketFactory the RMI server socket factory for the registry (if any) + * @return the RMI registry + * @throws java.rmi.RemoteException if the registry couldn't be located or created + */ + protected Registry getRegistry(String registryHost, int registryPort, + RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) + throws RemoteException { + + if (registryHost != null) { + // Host explictly specified: only lookup possible. + if (logger.isInfoEnabled()) { + logger.info("Looking for RMI registry at port '" + registryPort + "' of host [" + registryHost + "]"); + } + Registry reg = LocateRegistry.getRegistry(registryHost, registryPort, clientSocketFactory); + testRegistry(reg); + return reg; + } + + else { + return getRegistry(registryPort, clientSocketFactory, serverSocketFactory); + } + } + + /** + * Locate or create the RMI registry. + * @param registryPort the registry port to use + * @param clientSocketFactory the RMI client socket factory for the registry (if any) + * @param serverSocketFactory the RMI server socket factory for the registry (if any) + * @return the RMI registry + * @throws RemoteException if the registry couldn't be located or created + */ + protected Registry getRegistry( + int registryPort, RMIClientSocketFactory clientSocketFactory, RMIServerSocketFactory serverSocketFactory) + throws RemoteException { + + if (clientSocketFactory != null) { + if (this.alwaysCreate) { + logger.info("Creating new RMI registry"); + this.created = true; + return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); + } + if (logger.isInfoEnabled()) { + logger.info("Looking for RMI registry at port '" + registryPort + "', using custom socket factory"); + } + synchronized (LocateRegistry.class) { + try { + // Retrieve existing registry. + Registry reg = LocateRegistry.getRegistry(null, registryPort, clientSocketFactory); + testRegistry(reg); + return reg; + } + catch (RemoteException ex) { + logger.debug("RMI registry access threw exception", ex); + logger.info("Could not detect RMI registry - creating new one"); + // Assume no registry found -> create new one. + this.created = true; + return LocateRegistry.createRegistry(registryPort, clientSocketFactory, serverSocketFactory); + } + } + } + + else { + return getRegistry(registryPort); + } + } + + /** + * Locate or create the RMI registry. + * @param registryPort the registry port to use + * @return the RMI registry + * @throws RemoteException if the registry couldn't be located or created + */ + protected Registry getRegistry(int registryPort) throws RemoteException { + if (this.alwaysCreate) { + logger.info("Creating new RMI registry"); + this.created = true; + return LocateRegistry.createRegistry(registryPort); + } + if (logger.isInfoEnabled()) { + logger.info("Looking for RMI registry at port '" + registryPort + "'"); + } + synchronized (LocateRegistry.class) { + try { + // Retrieve existing registry. + Registry reg = LocateRegistry.getRegistry(registryPort); + testRegistry(reg); + return reg; + } + catch (RemoteException ex) { + logger.debug("RMI registry access threw exception", ex); + logger.info("Could not detect RMI registry - creating new one"); + // Assume no registry found -> create new one. + this.created = true; + return LocateRegistry.createRegistry(registryPort); + } + } + } + + /** + * Test the given RMI registry, calling some operation on it to + * check whether it is still active. + * <p>Default implementation calls <code>Registry.list()</code>. + * @param registry the RMI registry to test + * @throws RemoteException if thrown by registry methods + * @see java.rmi.registry.Registry#list() + */ + protected void testRegistry(Registry registry) throws RemoteException { + registry.list(); + } + + + public Registry getObject() throws Exception { + return this.registry; + } + + public Class<? extends Registry> getObjectType() { + return (this.registry != null ? this.registry.getClass() : Registry.class); + } + + public boolean isSingleton() { + return true; + } + + + /** + * Unexport the RMI registry on bean factory shutdown, + * provided that this bean actually created a registry. + */ + public void destroy() throws RemoteException { + if (this.created) { + logger.info("Unexporting RMI registry"); + UnicastRemoteObject.unexportObject(this.registry, true); + } + } + +} diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml index dce9f19f6e5..ee577d112e2 100644 --- a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml +++ b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/management/jmxInstrumentationWithConnector.xml @@ -55,7 +55,7 @@ <property name="defaultDomain" value="org.apache.camel.test"/> </bean> - <bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"> + <bean id="registry" class="org.apache.camel.spring.rmi.RmiRegistryFactoryBean"> <property name="port" value="9877"/> </bean> diff --git a/components/pom.xml b/components/pom.xml index 52b6d92ee65..867b4e14f54 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -308,7 +308,7 @@ <module>camel-stream</module> <module>camel-stringtemplate</module> <module>camel-stitch</module> - <module>camel-swagger-java</module> + <!--module>camel-swagger-java</module--> <module>camel-swift</module> <module>camel-openapi-java</module> <module>camel-syslog</module> diff --git a/parent/pom.xml b/parent/pom.xml index f105b9db803..ebe73b8bba3 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -2882,7 +2882,7 @@ </dependency> <dependency> <groupId>com.fasterxml.jackson.module</groupId> - <artifactId>jackson-module-jaxb-annotations</artifactId> + <artifactId>jackson-module-jakarta-xmlbind-annotations</artifactId> <version>${jackson2-version}</version> </dependency> <dependency> diff --git a/tooling/openapi-rest-dsl-generator/src/test/resources/SpringBootRestController.txt b/tooling/openapi-rest-dsl-generator/src/test/resources/SpringBootRestController.txt index d3a09f0dbd7..cefdbaaf4da 100644 --- a/tooling/openapi-rest-dsl-generator/src/test/resources/SpringBootRestController.txt +++ b/tooling/openapi-rest-dsl-generator/src/test/resources/SpringBootRestController.txt @@ -1,8 +1,8 @@ package com.foo; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import javax.annotation.processing.Generated; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/tooling/swagger-rest-dsl-generator/src/test/resources/SpringBootRestController.txt b/tooling/swagger-rest-dsl-generator/src/test/resources/SpringBootRestController.txt index 8f69fe76cf6..53d05b86c48 100644 --- a/tooling/swagger-rest-dsl-generator/src/test/resources/SpringBootRestController.txt +++ b/tooling/swagger-rest-dsl-generator/src/test/resources/SpringBootRestController.txt @@ -1,8 +1,8 @@ package com.foo; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; import javax.annotation.processing.Generated; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;
