1 23 package com.sun.enterprise.webservice; 24 25 import com.sun.enterprise.deployment.ServiceRefPortInfo; 26 import com.sun.enterprise.deployment.ServiceReferenceDescriptor; 27 import com.sun.xml.ws.spi.runtime.StubBase; 28 import com.sun.xml.ws.client.BindingProviderProperties; 29 import com.sun.xml.ws.spi.runtime.ClientTransportFactory; 30 import com.sun.logging.LogDomains; 31 import java.io.File ; 32 import java.io.FileInputStream ; 33 import java.io.IOException ; 34 import java.util.Map ; 35 import java.util.Properties ; 36 import javax.xml.namespace.QName ; 37 import javax.xml.ws.BindingProvider; 38 import java.util.logging.Logger ; 39 import java.util.logging.Level ; 40 45 public class ServiceEngineUtil { 46 47 public static String JBI_ENABLED = "jbi-enabled"; 48 private static final String SE_DISABLE_PROPERTY = "com.sun.enterprise.jbi.se.disable"; 49 private static String seDisablePropertyValue = null; 50 private static boolean seEnabledFlag = true; 51 52 private static Logger logger = 53 LogDomains.getLogger(LogDomains.SERVER_LOGGER); 54 55 public ServiceEngineUtil() { 56 } 57 58 public static boolean isServiceJBIEnabled(ServiceReferenceDescriptor desc) { 59 if(isServiceEngineEnabled()) { 60 java.util.Set portsInfo = desc.getPortsInfo(); 61 java.util.Iterator ports = portsInfo.iterator(); 62 while(ports.hasNext()) { 63 ServiceRefPortInfo portDesc = (ServiceRefPortInfo)ports.next(); 64 if(isPortJbiEnabled(portDesc)) 65 return true; 66 } 67 } 68 return false; 69 } 70 public static void setJBITransportFactory(ServiceReferenceDescriptor serviceRef, 71 Object stubObj, Class sei) { 72 if(isServiceEngineEnabled()) { 73 ServiceRefPortInfo portInfo = getPortInfo(sei, serviceRef); 74 boolean jbiEnabledFlag = isPortJbiEnabled(portInfo); 75 setJBITransportFactory(portInfo, stubObj, jbiEnabledFlag); 76 } else { 77 logger.log(Level.FINE, "Java EE Service Engine's functionality is disabled"); 78 } 79 } 80 81 82 public static void setJBITransportFactory(ServiceRefPortInfo portInfo, 83 Object stubObj, boolean jbiEnabled) { 84 if(isServiceEngineEnabled()) { 85 ServiceReferenceDescriptor serviceRef = portInfo.getServiceReference(); 86 if(serviceRef != null && stubObj != null) { 87 if (isServiceEngineEnabled() && jbiEnabled) { 88 if(serviceRef.getMappingFileUri() == null) { 89 setTransportFactory((com.sun.xml.ws.spi.runtime.StubBase)stubObj, portInfo); 90 } else { 91 92 setTransportFactory((com.sun.xml.rpc.spi.runtime.StubBase)stubObj, portInfo); 93 } 94 95 } 96 97 } 98 } else { 99 logger.log(Level.FINE, "Java EE Service Engine's functionality is disabled"); 100 } 101 102 } 103 104 public static boolean isServiceEngineEnabled() { 105 if(seDisablePropertyValue == null) { 107 seDisablePropertyValue = System.getProperty(SE_DISABLE_PROPERTY); 108 logger.log(Level.FINE,SE_DISABLE_PROPERTY ," value is " + seDisablePropertyValue); 109 if(seDisablePropertyValue != null) 110 seEnabledFlag = "false".equals(seDisablePropertyValue); 111 } 112 return seEnabledFlag; 113 } 114 115 116 private static ServiceRefPortInfo getPortInfo(Class sei, 117 ServiceReferenceDescriptor serviceRef) { 118 if(serviceRef != null) { 119 if(sei == null) { 120 try { 121 sei = Class.forName(serviceRef.getServiceInterface()); 122 }catch(Throwable cnfe) { 123 if (logger.isLoggable(Level.WARNING)) { 125 logger.log(Level.WARNING, 126 "Error during setting of transport factory"+cnfe.getMessage()); 127 } 128 return null; 129 } 130 } 131 return serviceRef.getPortInfo(sei.getName()); 132 } 133 return null; 134 } 135 136 private static boolean isPortJbiEnabled(Class sei, 137 ServiceReferenceDescriptor serviceRef) { 138 if(serviceRef != null) { 139 if(sei == null) { 140 try { 141 sei = Class.forName(serviceRef.getServiceInterface()); 142 }catch(Throwable cnfe) { 143 if (logger.isLoggable(Level.WARNING)) { 145 logger.log(Level.WARNING, 146 "Error during setting of transport factory"+cnfe.getMessage()); 147 } 148 return false; 149 } 150 } 151 return isPortJbiEnabled(serviceRef.getPortInfo(sei.getName())); 152 } 153 return false; 154 } 155 156 private static boolean isPortJbiEnabled(ServiceRefPortInfo portInfo) { 157 if(portInfo != null) { 158 String value = portInfo.getStubPropertyValue(JBI_ENABLED); 159 logger.log(Level.FINEST, "JBI_ENABLED flag value is : " + value); 160 return "true".equals(value); 161 } else { 162 } 165 return false; 166 } 167 168 private static void setTransportFactory( 169 com.sun.xml.ws.spi.runtime.StubBase stubObj, ServiceRefPortInfo portInfo) { 170 BindingProvider bindingProvider = (BindingProvider)stubObj; 171 172 Map <String ,Object > requestContext = bindingProvider.getRequestContext(); 173 String obj = (String )requestContext.get(com.sun.xml.ws.client.BindingProviderProperties.ONE_WAY_OPERATION); 174 boolean oneWay = Boolean.valueOf(obj).booleanValue(); 175 try { 176 com.sun.xml.ws.spi.runtime.ClientTransportFactory factory = 179 (com.sun.xml.ws.spi.runtime.ClientTransportFactory) 180 ServiceEngineRtObjectFactory.getInstance(). 181 getFacade().getTransportFactory(portInfo, 182 true, oneWay); 183 if (factory == null) 184 return ; 185 186 logger.log(Level.FINE, "Before setting setTransportFactory to NMR"); 187 stubObj._setTransportFactory(factory); 189 190 } catch(Exception e) { 191 if (logger.isLoggable(Level.WARNING)) { 193 logger.log(Level.WARNING, 194 "Error during setting of transport factory"+e.getMessage()); 195 } 196 } 197 } 198 199 private static void setTransportFactory( 200 com.sun.xml.rpc.spi.runtime.StubBase stubObj, ServiceRefPortInfo portInfo) { 201 try { 202 com.sun.xml.rpc.spi.runtime.ClientTransportFactory factory = 205 (com.sun.xml.rpc.spi.runtime.ClientTransportFactory) 206 ServiceEngineRtObjectFactory.getInstance(). 207 getFacade().getTransportFactory(portInfo, 208 false, true); 209 if (factory == null) 210 return ; 211 212 logger.log(Level.FINE, "Before setting setTransportFactory to NMR"); 213 stubObj._setTransportFactory(factory); 215 216 } catch(Exception e) { 217 if (logger.isLoggable(Level.WARNING)) { 219 logger.log(Level.WARNING, 220 "Error during setting of transport factory"+e.getMessage()); 221 } 222 } 223 } 224 } 225 | Popular Tags |