Author: asoldano
Date: 2014-08-08 09:59:56 -0400 (Fri, 08 Aug 2014)
New Revision: 18836
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityProviderConfig.java
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java
Log:
A couple of minor singleton optimizations, replaced usage of static synchronized methods
with lazy initialization holder class idiom
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityProviderConfig.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityProviderConfig.java 2014-08-08
13:59:27 UTC (rev 18835)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/configuration/SecurityProviderConfig.java 2014-08-08
13:59:56 UTC (rev 18836)
@@ -51,10 +51,23 @@
}
}
private static final boolean NO_LOCAL_BC =
SecurityActions.getBoolean(Constants.JBWS_CXF_NO_LOCAL_BC);
- private static Provider provider;
- private static synchronized Provider getBCProvider() {
- if (provider == null) {
+ public static void setup(Bus bus) {
+ if (!NO_LOCAL_BC && !BC_GLOBALLY_AVAILABLE) {
+ if (Holder.provider != null) {
+ bus.getInInterceptors().add(Holder.inInterceptor);
+ bus.getOutInterceptors().add(Holder.outInterceptor);
+ }
+ }
+ }
+
+ private static class Holder {
+ static final Provider provider = getBCProvider();
+ static final Interceptor inInterceptor = new Interceptor(Phase.RECEIVE);
+ static final Interceptor outInterceptor = new Interceptor(Phase.SETUP);
+
+ private static Provider getBCProvider() {
+ Provider provider = null;
try {
Class<?> clazz =
SecurityProviderConfig.class.getClassLoader().loadClass("org.bouncycastle.jce.provider.BouncyCastleProvider");
provider = (Provider)clazz.newInstance();
@@ -64,21 +77,10 @@
} catch (Throwable t) {
Loggers.ROOT_LOGGER.cannotLoadBouncyCastleProvider(Constants.JBWS_CXF_NO_LOCAL_BC, t);
}
+ return provider;
}
- return provider;
}
-
- public static void setup(Bus bus) {
- if (!NO_LOCAL_BC && !BC_GLOBALLY_AVAILABLE) {
- Provider p = getBCProvider();
- if (p != null) {
- bus.getInInterceptors().add(new Interceptor(Phase.RECEIVE));
- bus.getOutInterceptors().add(new Interceptor(Phase.SETUP));
- }
- }
- }
-
private static class Interceptor extends AbstractPhaseInterceptor<Message> {
public Interceptor(String phase)
@@ -90,7 +92,7 @@
public void handleMessage(Message message) throws Fault
{
Exchange exchange = message.getExchange();
- exchange.put(Provider.class, getBCProvider());
+ exchange.put(Provider.class, Holder.provider);
}
}
Modified:
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java
===================================================================
---
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java 2014-08-08
13:59:27 UTC (rev 18835)
+++
stack/cxf/trunk/modules/client/src/main/java/org/jboss/wsf/stack/cxf/client/serviceref/CXFHandlerResolverImpl.java 2014-08-08
13:59:56 UTC (rev 18836)
@@ -91,11 +91,9 @@
@SuppressWarnings("rawtypes")
private final Map<PortInfo, List<Handler>> handlerMap = new
HashMap<PortInfo, List<Handler>>();
private final String handlerFile;
- private static JAXBContext context;
private final Class<?> clazz;
private final ClassLoader classLoader;
private final Bus bus;
- private static DocumentBuilder builder;
public CXFHandlerResolverImpl(Bus bus, String handlerFile, Class<?> clazz)
{
@@ -160,7 +158,7 @@
throw MESSAGES.handlerConfigFileNotFound(handlerFile);
}
- Document doc = getDocumentBuilder().parse(is);
+ Document doc = Holder.builder.parse(is);
Element el = doc.getDocumentElement();
if (!ParserConstants.JAVAEE_NS.equals(el.getNamespaceURI())
|| !ParserConstants.HANDLER_CHAINS.equals(el.getLocalName())) {
@@ -363,7 +361,7 @@
private void processHandlerElement(Element el, @SuppressWarnings("rawtypes")
List<Handler> chain) {
try {
- JAXBContext ctx = getContextForPortComponentHandlerType();
+ JAXBContext ctx = Holder.context;
PortComponentHandlerType pt = ctx.createUnmarshaller()
.unmarshal(el, PortComponentHandlerType.class).getValue();
chain.addAll(buildHandlerChain(pt, classLoader));
@@ -372,20 +370,16 @@
}
}
- private static synchronized JAXBContext getContextForPortComponentHandlerType()
- throws JAXBException {
- if (context == null) {
- context = JAXBContext.newInstance(PortComponentHandlerType.class);
- }
- return context;
- }
-
- private static synchronized DocumentBuilder getDocumentBuilder()
- {
- if (builder == null)
+ private static class Holder {
+
+ static final DocumentBuilder builder = getDocumentBuilder();
+ static final JAXBContext context = getContextForPortComponentHandlerType();
+
+ private static DocumentBuilder getDocumentBuilder()
{
final ClassLoader classLoader = SecurityActions.getContextClassLoader();
SecurityActions.setContextClassLoader(CXFHandlerResolverImpl.class.getClassLoader());
+ DocumentBuilder builder;
try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
@@ -406,8 +400,21 @@
{
SecurityActions.setContextClassLoader(classLoader);
}
+ return builder;
}
- return builder;
+
+ private static JAXBContext getContextForPortComponentHandlerType() {
+ JAXBContext context = null;
+ try {
+ context = JAXBContext.newInstance(PortComponentHandlerType.class);
+ } catch (JAXBException e) {
+ e.printStackTrace(); //TODO can this really happen?
+ }
+ return context;
+ }
+
}
+
+
}
Show replies by date