You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2015/11/23 15:15:01 UTC
[03/25] tomee git commit: Format, cleanup & check for null
Format, cleanup & check for null
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/05855aa3
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/05855aa3
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/05855aa3
Branch: refs/heads/tomee-1.7.3-prepare
Commit: 05855aa3f03804106a6767a39f6c83d81efd47c2
Parents: 3138570
Author: AndyGee <an...@gmx.de>
Authored: Wed Nov 18 19:46:49 2015 +0100
Committer: AndyGee <an...@gmx.de>
Committed: Wed Nov 18 19:46:49 2015 +0100
----------------------------------------------------------------------
.../java/org/apache/openejb/BeanContext.java | 8 +-
.../org/apache/openejb/ClientInjections.java | 8 +-
.../main/java/org/apache/openejb/Injector.java | 20 +-
.../cdi/CdiResourceInjectionService.java | 2 +-
.../typed/JmsConnectionFactoryBuilder.java | 1 +
.../org/apache/openejb/core/mdb/MdbInvoker.java | 92 +-
.../org/apache/openejb/core/mdb/MdbUtil.java | 30 +-
examples/injection-of-connectionfactory/pom.xml | 2 +-
.../org/superbiz/injection/jms/Messages.java | 8 +-
pom.xml | 4192 +++++++++---------
.../openejb/server/ejbd/JndiRequestHandler.java | 35 +-
tomee/tomee-juli/pom.xml | 3 +-
12 files changed, 2216 insertions(+), 2185 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java b/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
index 2c7414a..c33502b 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/BeanContext.java
@@ -92,7 +92,7 @@ import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Future;
-@SuppressWarnings("unchecked")
+@SuppressWarnings({"unchecked", "unused"})
public class BeanContext extends DeploymentContext {
private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB, BeanContext.class);
@@ -235,8 +235,8 @@ public class BeanContext extends DeploymentContext {
private final boolean localbean;
private Duration accessTimeout;
- private Set<Class<?>> asynchronousClasses = new HashSet<Class<?>>();
- private Set<String> asynchronousMethodSignatures = new HashSet<String>();
+ private final Set<Class<?>> asynchronousClasses = new HashSet<Class<?>>();
+ private final Set<String> asynchronousMethodSignatures = new HashSet<String>();
private Class<?> proxyClass;
private Mdb mdb;
@@ -1791,7 +1791,7 @@ public class BeanContext extends DeploymentContext {
private Class cmpImplClass;
private String abstractSchemaName;
private Class pkClass;
- private Set<String> remoteQueryResults = new TreeSet<String>();
+ private final Set<String> remoteQueryResults = new TreeSet<String>();
private boolean isReentrant;
private final Map<Method, Method> postCreateMethodMap = new HashMap<Method, Method>();
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/main/java/org/apache/openejb/ClientInjections.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/ClientInjections.java b/container/openejb-core/src/main/java/org/apache/openejb/ClientInjections.java
index d76911d..0754e19 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/ClientInjections.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/ClientInjections.java
@@ -39,7 +39,13 @@ public final class ClientInjections {
final Context clients;
try {
- clients = (Context) SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext()
+ final ContainerSystem component = SystemInstance.get().getComponent(ContainerSystem.class);
+
+ if(null == component){
+ throw new IllegalStateException("ContainerSystem has not been initialized");
+ }
+
+ clients = (Context) component.getJNDIContext()
.lookup("openejb/client/");
} catch (final NamingException e) {
throw new OpenEJBException(object.getClass().getName(), e);
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/Injector.java b/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
index 3d8b6bb..cf779e8 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/Injector.java
@@ -33,6 +33,7 @@ public class Injector {
private static Logger logger; // initialized lazily to get the logging config from properties
+ @SuppressWarnings("unchecked")
public static <T> T inject(final T object) {
assert object != null;
@@ -64,19 +65,20 @@ public class Injector {
}
private static <T> void cdiInjections(final BeanContext context, final T object) {
- ThreadContext oldContext = null;
if (context != null) {
+
final ThreadContext callContext = new ThreadContext(context, null, Operation.INJECTION);
- oldContext = ThreadContext.enter(callContext);
- }
- try {
- OWBInjector.inject(context.getWebBeansContext().getBeanManagerImpl(), object, null);
- } catch (final Throwable t) {
- logger().warning("an error occured while injecting the class '" + object.getClass().getName() + "': " + t.getMessage());
- } finally {
- if (context != null) {
+ final ThreadContext oldContext = ThreadContext.enter(callContext);
+
+ try {
+ OWBInjector.inject(context.getWebBeansContext().getBeanManagerImpl(), object, null);
+ } catch (final Throwable t) {
+ logger().warning("An error occurred injecting the class '" + object.getClass().getName() + "': " + t.getMessage());
+ } finally {
ThreadContext.exit(oldContext);
}
+ } else {
+ logger().warning("Provided BeanContext is null");
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
index 459e03b..e07acc5 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
@@ -42,7 +42,7 @@ import java.util.ArrayList;
import java.util.List;
public class CdiResourceInjectionService implements ResourceInjectionService {
- private Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), CdiResourceInjectionService.class);
+ private final Logger logger = Logger.getInstance(LogCategory.OPENEJB.createChild("cdi"), CdiResourceInjectionService.class);
private final CdiPlugin ejbPlugin;
private final List<BeanContext> compContexts = new ArrayList<BeanContext>();
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/main/java/org/apache/openejb/config/typed/JmsConnectionFactoryBuilder.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/main/java/org/apache/openejb/config/typed/JmsConnectionFactoryBuilder.java b/container/openejb-core/src/main/java/org/apache/openejb/config/typed/JmsConnectionFactoryBuilder.java
index 072e725..f7b455c 100644
--- a/container/openejb-core/src/main/java/org/apache/openejb/config/typed/JmsConnectionFactoryBuilder.java
+++ b/container/openejb-core/src/main/java/org/apache/openejb/config/typed/JmsConnectionFactoryBuilder.java
@@ -30,6 +30,7 @@ import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
+@SuppressWarnings("unused")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "JmsConnectionFactory")
public class JmsConnectionFactoryBuilder extends Resource {
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbInvoker.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbInvoker.java b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbInvoker.java
index 693093a..8a0ea2a 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbInvoker.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbInvoker.java
@@ -1,42 +1,39 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.openejb.core.mdb;
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.JMSException;
-import javax.jms.Message;
-import javax.jms.MessageListener;
-import javax.jms.MessageProducer;
-import javax.jms.ObjectMessage;
-import javax.jms.Session;
+import javax.jms.*;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
import java.util.TreeMap;
+import java.util.concurrent.locks.ReentrantLock;
+import java.lang.IllegalStateException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
public class MdbInvoker implements MessageListener {
+ private final ReentrantLock lock = new ReentrantLock();
private final Map<String, Method> signatures = new TreeMap<String, Method>();
private final Object target;
private Connection connection;
private Session session;
- private ConnectionFactory connectionFactory;
+ private final ConnectionFactory connectionFactory;
public MdbInvoker(final ConnectionFactory connectionFactory, final Object target) throws JMSException {
this.target = target;
@@ -47,45 +44,59 @@ public class MdbInvoker implements MessageListener {
}
}
- public synchronized void destroy() {
- MdbUtil.close(session);
- session = null;
- MdbUtil.close(connection);
- connection = null;
+ public void destroy() {
+
+ lock.lock();
+
+ try {
+ MdbUtil.close(session);
+ session = null;
+ MdbUtil.close(connection);
+ connection = null;
+ } finally {
+ lock.unlock();
+ }
}
- private synchronized Session getSession() throws JMSException {
- connection = connectionFactory.createConnection();
- connection.start();
- session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- return session;
+ private Session getSession() throws JMSException {
+ lock.lock();
+
+ try {
+ connection = connectionFactory.createConnection();
+ connection.start();
+ session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ return session;
+ } finally {
+ lock.unlock();
+ }
}
public void onMessage(final Message message) {
- if (!(message instanceof ObjectMessage)) return;
-
try {
+ if (message == null) throw new NullPointerException("request message is null");
+
+ if (!ObjectMessage.class.isInstance(message))
+ throw new IllegalArgumentException("Expected a ObjectMessage request but got a " + message.getClass().getName());
+
final Session session = getSession();
if (session == null) throw new IllegalStateException("Invoker has been destroyed");
- if (message == null) throw new NullPointerException("request message is null");
- if (!(message instanceof ObjectMessage))
- throw new IllegalArgumentException("Expected a ObjectMessage request but got a " + message.getClass().getName());
final ObjectMessage objectMessage = (ObjectMessage) message;
final Serializable object = objectMessage.getObject();
+
if (object == null) throw new NullPointerException("object in ObjectMessage is null");
+
if (!(object instanceof Map)) {
- if (message instanceof ObjectMessage)
- throw new IllegalArgumentException("Expected a Map contained in the ObjectMessage request but got a " + object.getClass().getName());
+ throw new IllegalArgumentException("Expected a Map contained in the ObjectMessage request but got a " + object.getClass().getName());
}
- final Map request = (Map) object;
+ final Map request = (Map) object;
final String signature = (String) request.get("method");
final Method method = signatures.get(signature);
final Object[] args = (Object[]) request.get("args");
-
boolean exception = false;
- Object result = null;
+ Object result;
+
try {
result = method.invoke(target, args);
} catch (final IllegalAccessException e) {
@@ -98,6 +109,7 @@ public class MdbInvoker implements MessageListener {
}
MessageProducer producer = null;
+
try {
// create response
final Map<String, Object> response = new TreeMap<String, Object>();
@@ -120,8 +132,8 @@ public class MdbInvoker implements MessageListener {
MdbUtil.close(producer);
destroy();
}
- } catch (final Throwable e) {
- e.printStackTrace();
+ } catch (final Exception e) {
+ Logger.getLogger(MdbInvoker.class.getName()).log(Level.WARNING, "MdbInvoker.onMessage: " + message, e);
}
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbUtil.java
----------------------------------------------------------------------
diff --git a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbUtil.java b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbUtil.java
index 15368b5..aa8c5d4 100644
--- a/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbUtil.java
+++ b/container/openejb-core/src/test/java/org/apache/openejb/core/mdb/MdbUtil.java
@@ -1,24 +1,22 @@
/**
- *
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * <p/>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p/>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.openejb.core.mdb;
import javax.jms.Connection;
-import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Session;
@@ -44,7 +42,8 @@ public class MdbUtil {
if (closeable != null) {
try {
closeable.close();
- } catch (final JMSException e) {
+ } catch (final Exception e) {
+ //no-op
}
}
}
@@ -53,7 +52,8 @@ public class MdbUtil {
if (closeable != null) {
try {
closeable.close();
- } catch (final JMSException e) {
+ } catch (final Exception e) {
+ //no-op
}
}
}
@@ -62,7 +62,8 @@ public class MdbUtil {
if (closeable != null) {
try {
closeable.close();
- } catch (final JMSException e) {
+ } catch (final Exception e) {
+ //no-op
}
}
}
@@ -71,7 +72,8 @@ public class MdbUtil {
if (closeable != null) {
try {
closeable.close();
- } catch (final JMSException e) {
+ } catch (final Exception e) {
+ //no-op
}
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/examples/injection-of-connectionfactory/pom.xml
----------------------------------------------------------------------
diff --git a/examples/injection-of-connectionfactory/pom.xml b/examples/injection-of-connectionfactory/pom.xml
index c55a37c..80cd016 100644
--- a/examples/injection-of-connectionfactory/pom.xml
+++ b/examples/injection-of-connectionfactory/pom.xml
@@ -35,7 +35,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
- <version>3.1</version>
+ <version>3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
http://git-wip-us.apache.org/repos/asf/tomee/blob/05855aa3/examples/injection-of-connectionfactory/src/main/java/org/superbiz/injection/jms/Messages.java
----------------------------------------------------------------------
diff --git a/examples/injection-of-connectionfactory/src/main/java/org/superbiz/injection/jms/Messages.java b/examples/injection-of-connectionfactory/src/main/java/org/superbiz/injection/jms/Messages.java
index f126c1a..edb36ff 100644
--- a/examples/injection-of-connectionfactory/src/main/java/org/superbiz/injection/jms/Messages.java
+++ b/examples/injection-of-connectionfactory/src/main/java/org/superbiz/injection/jms/Messages.java
@@ -38,7 +38,7 @@ public class Messages {
@Resource
private Queue chatQueue;
- public void sendMessage(String text) throws JMSException {
+ public void sendMessage(final String text) throws JMSException {
Connection connection = null;
Session session = null;
@@ -51,11 +51,11 @@ public class Messages {
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
// Create a MessageProducer from the Session to the Topic or Queue
- MessageProducer producer = session.createProducer(chatQueue);
+ final MessageProducer producer = session.createProducer(chatQueue);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
// Create a message
- TextMessage message = session.createTextMessage(text);
+ final TextMessage message = session.createTextMessage(text);
// Tell the producer to send the message
producer.send(message);
@@ -86,7 +86,7 @@ public class Messages {
consumer = session.createConsumer(chatQueue);
// Wait for a message
- TextMessage message = (TextMessage) consumer.receive(1000);
+ final TextMessage message = (TextMessage) consumer.receive(1000);
return message.getText();
} finally {