This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 10.1.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push: new f5125d0353 Code clean-up - formatting. No functional change f5125d0353 is described below commit f5125d035373e5974109cf6906bc064146157042 Author: Mark Thomas <ma...@apache.org> AuthorDate: Thu Apr 3 17:28:05 2025 +0100 Code clean-up - formatting. No functional change --- java/org/apache/naming/factory/BeanFactory.java | 33 ++++----- java/org/apache/naming/factory/Constants.java | 3 +- .../naming/factory/DataSourceLinkFactory.java | 44 ++++++------ java/org/apache/naming/factory/EjbFactory.java | 8 +-- java/org/apache/naming/factory/FactoryBase.java | 40 +++++------ java/org/apache/naming/factory/LookupFactory.java | 25 ++++--- .../apache/naming/factory/MailSessionFactory.java | 38 +++++----- java/org/apache/naming/factory/OpenEjbFactory.java | 16 ++--- .../org/apache/naming/factory/ResourceFactory.java | 16 ++--- .../apache/naming/factory/ResourceLinkFactory.java | 41 ++++++----- .../org/apache/naming/factory/SendMailFactory.java | 80 ++++++++++------------ .../naming/factory/webservices/ServiceProxy.java | 19 +++-- .../factory/webservices/ServiceRefFactory.java | 28 ++++---- 13 files changed, 190 insertions(+), 201 deletions(-) diff --git a/java/org/apache/naming/factory/BeanFactory.java b/java/org/apache/naming/factory/BeanFactory.java index faf0cf8382..3975455c70 100644 --- a/java/org/apache/naming/factory/BeanFactory.java +++ b/java/org/apache/naming/factory/BeanFactory.java @@ -37,10 +37,11 @@ import org.apache.naming.StringManager; /** * Object factory for any Resource conforming to the JavaBean spec. + * <p> + * This factory can be configured in a <code><Context></code> element in your <code>conf/server.xml</code> + * configuration file. An example of factory configuration is: + * </p> * - * <p>This factory can be configured in a <code><Context></code> element - * in your <code>conf/server.xml</code> - * configuration file. An example of factory configuration is:</p> * <pre> * <Resource name="jdbc/myDataSource" * auth="SERVLET" @@ -68,11 +69,13 @@ public class BeanFactory implements ObjectFactory { /** * Create a new Bean instance. * - * @param obj The reference object describing the Bean - * @param name the bound name - * @param nameCtx unused + * @param obj The reference object describing the Bean + * @param name the bound name + * @param nameCtx unused * @param environment unused + * * @return the object instance + * * @throws NamingException if an error occur creating the instance */ @Override @@ -92,7 +95,7 @@ public class BeanFactory implements ObjectFactory { } else { beanClass = Class.forName(beanClassName); } - } catch(ClassNotFoundException cnfe) { + } catch (ClassNotFoundException cnfe) { NamingException ne = new NamingException(sm.getString("beanFactory.classNotFound", beanClassName)); ne.initCause(cnfe); throw ne; @@ -117,14 +120,12 @@ public class BeanFactory implements ObjectFactory { ra = e.nextElement(); String propName = ra.getType(); - if (propName.equals(Constants.FACTORY) || - propName.equals("scope") || propName.equals("auth") || - propName.equals("forceString") || - propName.equals("singleton")) { + if (propName.equals(Constants.FACTORY) || propName.equals("scope") || propName.equals("auth") || + propName.equals("forceString") || propName.equals("singleton")) { continue; } - value = (String)ra.getContent(); + value = (String) ra.getContent(); Object[] valueArray = new Object[1]; @@ -162,12 +163,12 @@ public class BeanFactory implements ObjectFactory { setProp = bean.getClass().getMethod(setterName, String.class); valueArray[0] = value; } catch (NoSuchMethodException nsme) { - throw new NamingException(sm.getString( - "beanFactory.noStringConversion", propName, propType.getName())); + throw new NamingException(sm.getString("beanFactory.noStringConversion", propName, + propType.getName())); } } else { - throw new NamingException(sm.getString( - "beanFactory.noStringConversion", propName, propType.getName())); + throw new NamingException( + sm.getString("beanFactory.noStringConversion", propName, propType.getName())); } if (setProp != null) { diff --git a/java/org/apache/naming/factory/Constants.java b/java/org/apache/naming/factory/Constants.java index b8690af3bc..d2255b088d 100644 --- a/java/org/apache/naming/factory/Constants.java +++ b/java/org/apache/naming/factory/Constants.java @@ -37,8 +37,7 @@ public final class Constants { public static final String DEFAULT_HANDLER_FACTORY = Package + ".HandlerFactory"; - public static final String DBCP_DATASOURCE_FACTORY = - "org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"; + public static final String DBCP_DATASOURCE_FACTORY = "org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory"; public static final String OPENEJB_EJB_FACTORY = Package + ".OpenEjbFactory"; diff --git a/java/org/apache/naming/factory/DataSourceLinkFactory.java b/java/org/apache/naming/factory/DataSourceLinkFactory.java index b38681d6b1..148160644f 100644 --- a/java/org/apache/naming/factory/DataSourceLinkFactory.java +++ b/java/org/apache/naming/factory/DataSourceLinkFactory.java @@ -31,10 +31,10 @@ import javax.naming.Reference; import javax.sql.DataSource; - /** - * <p>Object factory for resource links for shared data sources.</p> - * + * <p> + * Object factory for resource links for shared data sources. + * </p> */ public class DataSourceLinkFactory extends ResourceLinkFactory { @@ -46,14 +46,15 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { @Override public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) - throws NamingException { + throws NamingException { Object result = super.getObjectInstance(obj, name, nameCtx, environment); // Can we process this request? - if (result!=null) { + if (result != null) { Reference ref = (Reference) obj; RefAddr userAttr = ref.get("username"); RefAddr passAttr = ref.get("password"); - if (userAttr != null && passAttr != null && userAttr.getContent() != null && passAttr.getContent() != null) { + if (userAttr != null && passAttr != null && userAttr.getContent() != null && + passAttr.getContent() != null) { result = wrapDataSource(result, userAttr.getContent().toString(), passAttr.getContent().toString()); } } @@ -62,11 +63,10 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { protected Object wrapDataSource(Object datasource, String username, String password) throws NamingException { try { - DataSourceHandler handler = - new DataSourceHandler((DataSource)datasource, username, password); - return Proxy.newProxyInstance(datasource.getClass().getClassLoader(), - datasource.getClass().getInterfaces(), handler); - }catch (Exception x) { + DataSourceHandler handler = new DataSourceHandler((DataSource) datasource, username, password); + return Proxy.newProxyInstance(datasource.getClass().getClassLoader(), datasource.getClass().getInterfaces(), + handler); + } catch (Exception x) { if (x instanceof InvocationTargetException) { Throwable cause = x.getCause(); if (cause instanceof ThreadDeath) { @@ -80,7 +80,7 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { } } if (x instanceof NamingException) { - throw (NamingException)x; + throw (NamingException) x; } else { NamingException nx = new NamingException(x.getMessage()); nx.initCause(x); @@ -90,8 +90,8 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { } /** - * Simple wrapper class that will allow a user to configure a ResourceLink for a data source - * so that when {@link javax.sql.DataSource#getConnection()} is called, it will invoke + * Simple wrapper class that will allow a user to configure a ResourceLink for a data source so that when + * {@link javax.sql.DataSource#getConnection()} is called, it will invoke * {@link javax.sql.DataSource#getConnection(String, String)} with the preconfigured username and password. */ public static class DataSourceHandler implements InvocationHandler { @@ -99,6 +99,7 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { private final String username; private final String password; private final Method getConnection; + public DataSourceHandler(DataSource ds, String username, String password) throws Exception { this.ds = ds; this.username = username; @@ -109,17 +110,16 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - if ("getConnection".equals(method.getName()) && (args==null || args.length==0)) { - args = new String[] {username,password}; + if ("getConnection".equals(method.getName()) && (args == null || args.length == 0)) { + args = new String[] { username, password }; method = getConnection; } else if ("unwrap".equals(method.getName())) { - return unwrap((Class<?>)args[0]); + return unwrap((Class<?>) args[0]); } try { - return method.invoke(ds,args); - }catch (Throwable t) { - if (t instanceof InvocationTargetException - && t.getCause() != null) { + return method.invoke(ds, args); + } catch (Throwable t) { + if (t instanceof InvocationTargetException && t.getCause() != null) { throw t.getCause(); } else { throw t; @@ -138,7 +138,5 @@ public class DataSourceLinkFactory extends ResourceLinkFactory { } - - } diff --git a/java/org/apache/naming/factory/EjbFactory.java b/java/org/apache/naming/factory/EjbFactory.java index 74c2d87f91..2218a84f0d 100644 --- a/java/org/apache/naming/factory/EjbFactory.java +++ b/java/org/apache/naming/factory/EjbFactory.java @@ -43,12 +43,10 @@ public class EjbFactory extends FactoryBase { protected ObjectFactory getDefaultFactory(Reference ref) throws NamingException { ObjectFactory factory; - String javaxEjbFactoryClassName = System.getProperty( - "jakarta.ejb.Factory", Constants.OPENEJB_EJB_FACTORY); + String javaxEjbFactoryClassName = System.getProperty("jakarta.ejb.Factory", Constants.OPENEJB_EJB_FACTORY); try { - factory = (ObjectFactory) - Class.forName(javaxEjbFactoryClassName).getConstructor().newInstance(); - } catch(Throwable t) { + factory = (ObjectFactory) Class.forName(javaxEjbFactoryClassName).getConstructor().newInstance(); + } catch (Throwable t) { if (t instanceof NamingException) { throw (NamingException) t; } diff --git a/java/org/apache/naming/factory/FactoryBase.java b/java/org/apache/naming/factory/FactoryBase.java index 9f23f3a4be..abff559d6e 100644 --- a/java/org/apache/naming/factory/FactoryBase.java +++ b/java/org/apache/naming/factory/FactoryBase.java @@ -28,16 +28,16 @@ import javax.naming.spi.ObjectFactory; import org.apache.naming.StringManager; /** - * Abstract base class that provides common functionality required by - * subclasses. This class exists primarily to reduce code duplication. + * Abstract base class that provides common functionality required by subclasses. This class exists primarily to reduce + * code duplication. */ public abstract class FactoryBase implements ObjectFactory { private static final StringManager sm = StringManager.getManager(FactoryBase.class); @Override - public final Object getObjectInstance(Object obj, Name name, Context nameCtx, - Hashtable<?,?> environment) throws Exception { + public final Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) + throws Exception { if (isReferenceTypeSupported(obj)) { Reference ref = (Reference) obj; @@ -61,14 +61,14 @@ public abstract class FactoryBase implements ObjectFactory { } else { factoryClass = Class.forName(factoryClassName); } - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { NamingException ex = new NamingException(sm.getString("factoryBase.factoryClassError")); ex.initCause(e); throw ex; } try { factory = (ObjectFactory) factoryClass.getConstructor().newInstance(); - } catch(Throwable t) { + } catch (Throwable t) { if (t instanceof NamingException) { throw (NamingException) t; } @@ -99,37 +99,33 @@ public abstract class FactoryBase implements ObjectFactory { /** - * Determines if this factory supports processing the provided reference - * object. + * Determines if this factory supports processing the provided reference object. * - * @param obj The object to be processed + * @param obj The object to be processed * - * @return <code>true</code> if this factory can process the object, - * otherwise <code>false</code> + * @return <code>true</code> if this factory can process the object, otherwise <code>false</code> */ protected abstract boolean isReferenceTypeSupported(Object obj); /** - * If a default factory is available for the given reference type, create - * the default factory. + * If a default factory is available for the given reference type, create the default factory. * - * @param ref The reference object to be processed + * @param ref The reference object to be processed * - * @return The default factory for the given reference object or - * <code>null</code> if no default factory exists. + * @return The default factory for the given reference object or <code>null</code> if no default factory exists. * - * @throws NamingException If the default factory cannot be created + * @throws NamingException If the default factory cannot be created */ - protected abstract ObjectFactory getDefaultFactory(Reference ref) - throws NamingException; + protected abstract ObjectFactory getDefaultFactory(Reference ref) throws NamingException; /** * If this reference is a link to another JNDI object, obtain that object. * - * @param ref The reference object to be processed + * @param ref The reference object to be processed + * + * @return The linked object or <code>null</code> if linked objects are not supported by or not configured for this + * reference object * - * @return The linked object or <code>null</code> if linked objects are - * not supported by or not configured for this reference object * @throws NamingException Error accessing linked object */ protected abstract Object getLinked(Reference ref) throws NamingException; diff --git a/java/org/apache/naming/factory/LookupFactory.java b/java/org/apache/naming/factory/LookupFactory.java index 711314ef19..881b14d6f2 100644 --- a/java/org/apache/naming/factory/LookupFactory.java +++ b/java/org/apache/naming/factory/LookupFactory.java @@ -46,16 +46,18 @@ public class LookupFactory implements ObjectFactory { /** * Create a new Resource env instance. * - * @param obj The reference object describing the DataSource - * @param name the bound name - * @param nameCtx unused + * @param obj The reference object describing the DataSource + * @param name the bound name + * @param nameCtx unused * @param environment unused + * * @return the object instance + * * @throws Exception if an error occur creating the instance */ @Override - public Object getObjectInstance(Object obj, Name name, Context nameCtx, - Hashtable<?, ?> environment) throws Exception { + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) + throws Exception { String lookupName = null; Object result = null; @@ -88,8 +90,7 @@ public class LookupFactory implements ObjectFactory { try { factoryClass = tcl.loadClass(factoryClassName); } catch (ClassNotFoundException e) { - NamingException ex = new NamingException( - sm.getString("lookupFactory.loadFailed")); + NamingException ex = new NamingException(sm.getString("lookupFactory.loadFailed")); ex.initCause(e); throw ex; } @@ -97,8 +98,7 @@ public class LookupFactory implements ObjectFactory { try { factoryClass = Class.forName(factoryClassName); } catch (ClassNotFoundException e) { - NamingException ex = new NamingException( - sm.getString("lookupFactory.loadFailed")); + NamingException ex = new NamingException(sm.getString("lookupFactory.loadFailed")); ex.initCause(e); throw ex; } @@ -107,8 +107,7 @@ public class LookupFactory implements ObjectFactory { try { factory = (ObjectFactory) factoryClass.getConstructor().newInstance(); } catch (Throwable t) { - NamingException ex = new NamingException( - sm.getString("lookupFactory.createFailed")); + NamingException ex = new NamingException(sm.getString("lookupFactory.createFailed")); ex.initCause(t); throw ex; } @@ -127,8 +126,8 @@ public class LookupFactory implements ObjectFactory { Class<?> clazz = Class.forName(ref.getClassName()); if (result != null && !clazz.isAssignableFrom(result.getClass())) { - String msg = sm.getString("lookupFactory.typeMismatch", - name, ref.getClassName(), lookupName, result.getClass().getName()); + String msg = sm.getString("lookupFactory.typeMismatch", name, ref.getClassName(), lookupName, + result.getClass().getName()); NamingException ne = new NamingException(msg); log.warn(msg, ne); // Close the resource we no longer need if we know how to do so diff --git a/java/org/apache/naming/factory/MailSessionFactory.java b/java/org/apache/naming/factory/MailSessionFactory.java index 1093769c7b..0052b4971d 100644 --- a/java/org/apache/naming/factory/MailSessionFactory.java +++ b/java/org/apache/naming/factory/MailSessionFactory.java @@ -33,19 +33,20 @@ import jakarta.mail.PasswordAuthentication; import jakarta.mail.Session; /** - * <p>Factory class that creates a JNDI named JavaMail Session factory, - * which can be used for managing inbound and outbound electronic mail - * messages via JavaMail APIs. All messaging environment properties - * described in the JavaMail Specification may be passed to the Session - * factory; however the following properties are the most commonly used:</p> + * <p> + * Factory class that creates a JNDI named JavaMail Session factory, which can be used for managing inbound and outbound + * electronic mail messages via JavaMail APIs. All messaging environment properties described in the JavaMail + * Specification may be passed to the Session factory; however the following properties are the most commonly used: + * </p> * <ul> - * <li><strong>mail.smtp.host</strong> - Hostname for outbound transport - * connections. Defaults to <code>localhost</code> if not specified.</li> + * <li><strong>mail.smtp.host</strong> - Hostname for outbound transport connections. Defaults to <code>localhost</code> + * if not specified.</li> * </ul> + * <p> + * This factory can be configured in a <code><Context></code> element in your <code>conf/server.xml</code> + * configuration file. An example of factory configuration is: + * </p> * - * <p>This factory can be configured in a - * <code><Context></code> element in your <code>conf/server.xml</code> - * configuration file. An example of factory configuration is:</p> * <pre> * <Resource name="mail/smtp" * auth="CONTAINER" @@ -66,8 +67,7 @@ public class MailSessionFactory implements ObjectFactory { @Override - public Object getObjectInstance(Object refObj, Name name, Context context, - Hashtable<?,?> env) throws Exception { + public Object getObjectInstance(Object refObj, Name name, Context context, Hashtable<?,?> env) throws Exception { // Return null if we cannot create an object of the requested type final Reference ref = (Reference) refObj; @@ -107,18 +107,18 @@ public class MailSessionFactory implements ObjectFactory { Authenticator auth = null; if (password != null) { String user = props.getProperty("mail.smtp.user"); - if(user == null) { + if (user == null) { user = props.getProperty("mail.user"); } - if(user != null) { + if (user != null) { final PasswordAuthentication pa = new PasswordAuthentication(user, password); auth = new Authenticator() { - @Override - protected PasswordAuthentication getPasswordAuthentication() { - return pa; - } - }; + @Override + protected PasswordAuthentication getPasswordAuthentication() { + return pa; + } + }; } } diff --git a/java/org/apache/naming/factory/OpenEjbFactory.java b/java/org/apache/naming/factory/OpenEjbFactory.java index 788a01174e..e901f38b46 100644 --- a/java/org/apache/naming/factory/OpenEjbFactory.java +++ b/java/org/apache/naming/factory/OpenEjbFactory.java @@ -40,8 +40,7 @@ public class OpenEjbFactory implements ObjectFactory { // -------------------------------------------------------------- Constants - protected static final String DEFAULT_OPENEJB_FACTORY = - "org.openejb.client.LocalInitialContextFactory"; + protected static final String DEFAULT_OPENEJB_FACTORY = "org.openejb.client.LocalInitialContextFactory"; // -------------------------------------------------- ObjectFactory Methods @@ -50,17 +49,18 @@ public class OpenEjbFactory implements ObjectFactory { /** * Create a new EJB instance using OpenEJB. * - * @param obj The reference object describing the DataSource - * @param name the bound name - * @param nameCtx unused + * @param obj The reference object describing the DataSource + * @param name the bound name + * @param nameCtx unused * @param environment unused + * * @return the object instance + * * @throws Exception if an error occur creating the instance */ @Override - public Object getObjectInstance(Object obj, Name name, Context nameCtx, - Hashtable<?,?> environment) - throws Exception { + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) + throws Exception { Object beanObj = null; diff --git a/java/org/apache/naming/factory/ResourceFactory.java b/java/org/apache/naming/factory/ResourceFactory.java index 00c3b8b400..b14db8770a 100644 --- a/java/org/apache/naming/factory/ResourceFactory.java +++ b/java/org/apache/naming/factory/ResourceFactory.java @@ -44,11 +44,10 @@ public class ResourceFactory extends FactoryBase { if (ref.getClassName().equals("javax.sql.DataSource")) { String javaxSqlDataSourceFactoryClassName = - System.getProperty("javax.sql.DataSource.Factory", - Constants.DBCP_DATASOURCE_FACTORY); + System.getProperty("javax.sql.DataSource.Factory", Constants.DBCP_DATASOURCE_FACTORY); try { - factory = (ObjectFactory) Class.forName( - javaxSqlDataSourceFactoryClassName).getConstructor().newInstance(); + factory = (ObjectFactory) Class.forName(javaxSqlDataSourceFactoryClassName).getConstructor() + .newInstance(); } catch (Exception e) { NamingException ex = new NamingException(sm.getString("resourceFactory.factoryCreationError")); ex.initCause(e); @@ -56,12 +55,11 @@ public class ResourceFactory extends FactoryBase { } } else if (ref.getClassName().equals("jakarta.mail.Session")) { String javaxMailSessionFactoryClassName = - System.getProperty("jakarta.mail.Session.Factory", - "org.apache.naming.factory.MailSessionFactory"); + System.getProperty("jakarta.mail.Session.Factory", "org.apache.naming.factory.MailSessionFactory"); try { - factory = (ObjectFactory) Class.forName( - javaxMailSessionFactoryClassName).getConstructor().newInstance(); - } catch(Throwable t) { + factory = + (ObjectFactory) Class.forName(javaxMailSessionFactoryClassName).getConstructor().newInstance(); + } catch (Throwable t) { if (t instanceof NamingException) { throw (NamingException) t; } diff --git a/java/org/apache/naming/factory/ResourceLinkFactory.java b/java/org/apache/naming/factory/ResourceLinkFactory.java index aced4a6b5d..93204b1934 100644 --- a/java/org/apache/naming/factory/ResourceLinkFactory.java +++ b/java/org/apache/naming/factory/ResourceLinkFactory.java @@ -32,7 +32,9 @@ import org.apache.naming.ResourceLinkRef; import org.apache.naming.StringManager; /** - * <p>Object factory for resource links.</p> + * <p> + * Object factory for resource links. + * </p> * * @author Remy Maucherat */ @@ -47,8 +49,7 @@ public class ResourceLinkFactory implements ObjectFactory { */ private static Context globalContext = null; - private static final Map<ClassLoader,Map<String,String>> globalResourceRegistrations = - new ConcurrentHashMap<>(); + private static final Map<ClassLoader,Map<String,String>> globalResourceRegistrations = new ConcurrentHashMap<>(); // --------------------------------------------------------- Public Methods @@ -60,15 +61,13 @@ public class ResourceLinkFactory implements ObjectFactory { public static void setGlobalContext(Context newGlobalContext) { SecurityManager sm = System.getSecurityManager(); if (sm != null) { - sm.checkPermission(new RuntimePermission( - ResourceLinkFactory.class.getName() + ".setGlobalContext")); + sm.checkPermission(new RuntimePermission(ResourceLinkFactory.class.getName() + ".setGlobalContext")); } globalContext = newGlobalContext; } - public static void registerGlobalResourceAccess(Context globalContext, String localName, - String globalName) { + public static void registerGlobalResourceAccess(Context globalContext, String localName, String globalName) { validateGlobalContext(globalContext); ClassLoader cl = Thread.currentThread().getContextClassLoader(); // Web application initialization is single threaded so this is @@ -95,8 +94,7 @@ public class ResourceLinkFactory implements ObjectFactory { private static void validateGlobalContext(Context globalContext) { - if (ResourceLinkFactory.globalContext != null && - ResourceLinkFactory.globalContext != globalContext) { + if (ResourceLinkFactory.globalContext != null && ResourceLinkFactory.globalContext != globalContext) { throw new SecurityException(sm.getString("resourceLinkFactory.invalidGlobalContext")); } } @@ -120,15 +118,17 @@ public class ResourceLinkFactory implements ObjectFactory { /** * Create a new resource instance. * - * @param name the bound name - * @param nameCtx unused + * @param name the bound name + * @param nameCtx unused * @param environment unused + * * @return the object instance + * * @throws NamingException if an error occur creating the instance */ @Override - public Object getObjectInstance(Object obj, Name name, Context nameCtx, - Hashtable<?,?> environment) throws NamingException { + public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?,?> environment) + throws NamingException { if (!(obj instanceof ResourceLinkRef)) { return null; @@ -151,19 +151,18 @@ public class ResourceLinkFactory implements ObjectFactory { // Check the expected type String expectedClassName = ref.getClassName(); if (expectedClassName == null) { - throw new IllegalArgumentException( - sm.getString("resourceLinkFactory.nullType", name, globalName)); + throw new IllegalArgumentException(sm.getString("resourceLinkFactory.nullType", name, globalName)); } try { - Class<?> expectedClazz = Class.forName( - expectedClassName, true, Thread.currentThread().getContextClassLoader()); + Class<?> expectedClazz = + Class.forName(expectedClassName, true, Thread.currentThread().getContextClassLoader()); if (!expectedClazz.isAssignableFrom(result.getClass())) { - throw new IllegalArgumentException(sm.getString("resourceLinkFactory.wrongType", - name, globalName, expectedClassName, result.getClass().getName())); + throw new IllegalArgumentException(sm.getString("resourceLinkFactory.wrongType", name, globalName, + expectedClassName, result.getClass().getName())); } } catch (ClassNotFoundException e) { - throw new IllegalArgumentException(sm.getString("resourceLinkFactory.unknownType", - name, globalName, expectedClassName), e); + throw new IllegalArgumentException( + sm.getString("resourceLinkFactory.unknownType", name, globalName, expectedClassName), e); } return result; } diff --git a/java/org/apache/naming/factory/SendMailFactory.java b/java/org/apache/naming/factory/SendMailFactory.java index 4c99895e72..638d59f577 100644 --- a/java/org/apache/naming/factory/SendMailFactory.java +++ b/java/org/apache/naming/factory/SendMailFactory.java @@ -34,13 +34,13 @@ import jakarta.mail.internet.MimeMessage; import jakarta.mail.internet.MimePartDataSource; /** - * Factory class that creates a JNDI named javamail MimePartDataSource - * object which can be used for sending email using SMTP. + * Factory class that creates a JNDI named javamail MimePartDataSource object which can be used for sending email using + * SMTP. * <p> - * Can be configured in the Context scope - * of your server.xml configuration file. + * Can be configured in the Context scope of your server.xml configuration file. * <p> * Example: + * * <pre> * <Resource name="mail/send" * auth="CONTAINER" @@ -58,54 +58,50 @@ import jakarta.mail.internet.MimePartDataSource; * @author Glenn Nielsen Rich Catlett */ -public class SendMailFactory implements ObjectFactory -{ +public class SendMailFactory implements ObjectFactory { // The class name for the javamail MimeMessageDataSource - protected static final String DataSourceClassName = - "jakarta.mail.internet.MimePartDataSource"; + protected static final String DataSourceClassName = "jakarta.mail.internet.MimePartDataSource"; @Override - public Object getObjectInstance(Object refObj, Name name, Context ctx, - Hashtable<?,?> env) throws Exception { - final Reference ref = (Reference)refObj; + public Object getObjectInstance(Object refObj, Name name, Context ctx, Hashtable<?,?> env) throws Exception { + final Reference ref = (Reference) refObj; // Creation of the DataSource is wrapped inside a doPrivileged // so that javamail can read its default properties without // throwing Security Exceptions if (ref.getClassName().equals(DataSourceClassName)) { - return AccessController.doPrivileged( - (PrivilegedAction<MimePartDataSource>) () -> { - // set up the smtp session that will send the message - Properties props = new Properties(); - // enumeration of all refaddr - Enumeration<RefAddr> list = ref.getAll(); - // current refaddr to be set - RefAddr refaddr; - // set transport to smtp - props.put("mail.transport.protocol", "smtp"); + return AccessController.doPrivileged((PrivilegedAction<MimePartDataSource>) () -> { + // set up the smtp session that will send the message + Properties props = new Properties(); + // enumeration of all refaddr + Enumeration<RefAddr> list = ref.getAll(); + // current refaddr to be set + RefAddr refaddr; + // set transport to smtp + props.put("mail.transport.protocol", "smtp"); - while (list.hasMoreElements()) { - refaddr = list.nextElement(); + while (list.hasMoreElements()) { + refaddr = list.nextElement(); - // set property - props.put(refaddr.getType(), refaddr.getContent()); - } - MimeMessage message = new MimeMessage( - Session.getInstance(props)); - try { - RefAddr fromAddr = ref.get("mail.from"); - String from = null; - if (fromAddr != null) { - from = (String) fromAddr.getContent(); - } - if (from != null) { - message.setFrom(new InternetAddress(from)); - } - message.setSubject(""); - } catch (Exception e) {/*Ignore*/} - MimePartDataSource mds = new MimePartDataSource(message); - return mds; - }); + // set property + props.put(refaddr.getType(), refaddr.getContent()); + } + MimeMessage message = new MimeMessage(Session.getInstance(props)); + try { + RefAddr fromAddr = ref.get("mail.from"); + String from = null; + if (fromAddr != null) { + from = (String) fromAddr.getContent(); + } + if (from != null) { + message.setFrom(new InternetAddress(from)); + } + message.setSubject(""); + } catch (Exception e) { + /* Ignore */} + MimePartDataSource mds = new MimePartDataSource(message); + return mds; + }); } else { // We can't create an instance of the DataSource return null; } diff --git a/java/org/apache/naming/factory/webservices/ServiceProxy.java b/java/org/apache/naming/factory/webservices/ServiceProxy.java index d6c03b1cef..0de209c9cc 100644 --- a/java/org/apache/naming/factory/webservices/ServiceProxy.java +++ b/java/org/apache/naming/factory/webservices/ServiceProxy.java @@ -39,8 +39,7 @@ public class ServiceProxy implements InvocationHandler { private static final StringManager sm = StringManager.getManager(ServiceProxy.class); /** - * Service object. - * used for delegation + * Service object. used for delegation */ private final Service service; @@ -61,14 +60,16 @@ public class ServiceProxy implements InvocationHandler { /** * Constructs a new ServiceProxy wrapping given Service instance. + * * @param service the wrapped Service instance + * * @throws ServiceException should be never thrown */ public ServiceProxy(Service service) throws ServiceException { this.service = service; try { - portQNameClass = Service.class.getDeclaredMethod("getPort", new Class[]{QName.class, Class.class}); - portClass = Service.class.getDeclaredMethod("getPort", new Class[]{Class.class}); + portQNameClass = Service.class.getDeclaredMethod("getPort", new Class[] { QName.class, Class.class }); + portClass = Service.class.getDeclaredMethod("getPort", new Class[] { Class.class }); } catch (Exception e) { throw new ServiceException(e); } @@ -78,8 +79,7 @@ public class ServiceProxy implements InvocationHandler { * @see InvocationHandler#invoke(Object, Method, Object[]) */ @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (portQNameClass.equals(method)) { return getProxyPortQNameClass(args); @@ -98,7 +98,9 @@ public class ServiceProxy implements InvocationHandler { /** * @param args Method call arguments + * * @return Returns the correct Port + * * @throws ServiceException if port's QName is an unknown Port (not defined in WSDL). */ private Object getProxyPortQNameClass(Object[] args) throws ServiceException { @@ -106,7 +108,8 @@ public class ServiceProxy implements InvocationHandler { String nameString = name.getLocalPart(); Class<?> serviceendpointClass = (Class<?>) args[1]; - for (@SuppressWarnings("unchecked") Iterator<QName> ports = service.getPorts(); ports.hasNext();) { + for (@SuppressWarnings("unchecked") + Iterator<QName> ports = service.getPorts(); ports.hasNext();) { QName portName = ports.next(); String portnameString = portName.getLocalPart(); if (portnameString.equals(nameString)) { @@ -127,7 +130,9 @@ public class ServiceProxy implements InvocationHandler { /** * @param args Method call arguments + * * @return Returns the correct Port + * * @throws ServiceException if port's QName is an unknown Port */ private Remote getProxyPortClass(Object[] args) throws ServiceException { diff --git a/java/org/apache/naming/factory/webservices/ServiceRefFactory.java b/java/org/apache/naming/factory/webservices/ServiceRefFactory.java index d58933c8ce..619c3c01be 100644 --- a/java/org/apache/naming/factory/webservices/ServiceRefFactory.java +++ b/java/org/apache/naming/factory/webservices/ServiceRefFactory.java @@ -117,7 +117,7 @@ public class ServiceRefFactory implements ObjectFactory { } try { if (wsdlRefAddr == null) { - service = factory.createService( serviceQname ); + service = factory.createService(serviceQname); } else { service = factory.createService(new URI(wsdlRefAddr).toURL(), serviceQname); } @@ -130,7 +130,7 @@ public class ServiceRefFactory implements ObjectFactory { // Loading service Interface try { serviceInterfaceClass = tcl.loadClass(serviceInterface); - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { NamingException ex = new NamingException("Could not load service Interface"); ex.initCause(e); throw ex; @@ -145,8 +145,8 @@ public class ServiceRefFactory implements ObjectFactory { } service = factory.loadService(serviceInterfaceClass); } else { - service = factory.loadService( - new URI(wsdlRefAddr).toURL(), serviceInterfaceClass, new Properties()); + service = factory.loadService(new URI(wsdlRefAddr).toURL(), serviceInterfaceClass, + new Properties()); } } catch (Exception e) { NamingException ex = new NamingException("Could not create service"); @@ -174,7 +174,7 @@ public class ServiceRefFactory implements ObjectFactory { for (String portName : ports.keySet()) { Port port = wsdlservice.getPort(portName); String endpoint = getSOAPLocation(port); - m.invoke(service, new Object[]{port.getName(), endpoint}); + m.invoke(service, new Object[] { port.getName(), endpoint }); portComponentRef.put(endpoint, new QName(port.getName())); } } catch (Exception e) { @@ -242,7 +242,7 @@ public class ServiceRefFactory implements ObjectFactory { Class<?> handlerClass = null; try { handlerClass = tcl.loadClass((String) tmp.getContent()); - } catch(ClassNotFoundException e) { + } catch (ClassNotFoundException e) { break; } @@ -289,12 +289,11 @@ public class ServiceRefFactory implements ObjectFactory { if (!portNames.isEmpty()) { for (String portName : portNames) { - initHandlerChain(new QName(portName), handlerRegistry, - handlerInfo, soaproles); + initHandlerChain(new QName(portName), handlerRegistry, handlerInfo, soaproles); } } else { Enumeration<QName> e = portComponentRef.elements(); - while(e.hasMoreElements()) { + while (e.hasMoreElements()) { initHandlerChain(e.nextElement(), handlerRegistry, handlerInfo, soaproles); } } @@ -311,6 +310,7 @@ public class ServiceRefFactory implements ObjectFactory { /** * @param port analyzed port + * * @return Returns the endpoint URL of the given Port */ private String getSOAPLocation(Port port) { @@ -327,8 +327,8 @@ public class ServiceRefFactory implements ObjectFactory { } - private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry, - HandlerInfo handlerInfo, List<String> soaprolesToAdd) { + private void initHandlerChain(QName portName, HandlerRegistry handlerRegistry, HandlerInfo handlerInfo, + List<String> soaprolesToAdd) { HandlerChain handlerChain = (HandlerChain) handlerRegistry.getHandlerChain(portName); @SuppressWarnings("unchecked") // Can't change the API Iterator<Handler> iter = handlerChain.iterator(); @@ -337,13 +337,13 @@ public class ServiceRefFactory implements ObjectFactory { handler.init(handlerInfo); } String[] soaprolesRegistered = handlerChain.getRoles(); - String [] soaproles = new String[soaprolesRegistered.length + soaprolesToAdd.size()]; + String[] soaproles = new String[soaprolesRegistered.length + soaprolesToAdd.size()]; int i; - for (i = 0;i < soaprolesRegistered.length; i++) { + for (i = 0; i < soaprolesRegistered.length; i++) { soaproles[i] = soaprolesRegistered[i]; } for (int j = 0; j < soaprolesToAdd.size(); j++) { - soaproles[i+j] = soaprolesToAdd.get(j); + soaproles[i + j] = soaprolesToAdd.get(j); } handlerChain.setRoles(soaproles); handlerRegistry.setHandlerChain(portName, handlerChain); --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org