1 23 package com.sun.enterprise.admin.wsmgmt.transform; 24 25 import com.sun.enterprise.admin.wsmgmt.config.spi.Constants; 26 import com.sun.enterprise.admin.wsmgmt.config.spi.TransformationRule; 27 import com.sun.enterprise.admin.wsmgmt.filter.spi.Filter; 28 import com.sun.enterprise.admin.wsmgmt.filter.spi.FilterContext; 29 30 import com.sun.enterprise.admin.wsmgmt.config.spi.WebServiceConfig; 31 32 import java.util.concurrent.locks.ReentrantReadWriteLock ; 33 import java.util.concurrent.locks.Lock ; 34 35 import java.util.logging.Logger ; 36 import java.util.logging.Level ; 37 import com.sun.logging.LogDomains; 38 import com.sun.enterprise.util.i18n.StringManager; 39 40 41 42 45 public class TransformFilter implements Filter { 46 47 53 public TransformFilter(String appId, String endpoint) { 54 _applicationId = appId; 55 _endpointId = endpoint; 56 _rwl = new ReentrantReadWriteLock (); 57 _readLock = _rwl.readLock(); 58 _writeLock = _rwl.writeLock(); 59 } 60 61 67 public TransformFilter(String appId, WebServiceConfig wsc) 68 throws TransformException { 69 _applicationId = appId; 70 _endpointId = wsc.getName(); 71 TransformationRule[] reqRules = wsc.getRequestTransformationRule(); 72 if ( reqRules != null) { 73 reqChain = new FilterChain(); 74 reqChain.addFilter(reqRules, false); 75 } else { 76 reqChain = null; 77 } 78 TransformationRule[] resRules = wsc.getResponseTransformationRule(); 79 if (resRules != null) { 80 resChain = new FilterChain(); 81 resChain.addFilter(resRules, true); 82 } else { 83 resChain = null; 84 } 85 _rwl = new ReentrantReadWriteLock (); 86 _readLock = _rwl.readLock(); 87 _writeLock = _rwl.writeLock(); 88 } 89 90 93 public void resetRequestChain(TransformationRule[] tRules) throws 94 TransformException { 95 _writeLock.lock(); 96 try { 97 reqChain = new FilterChain(); 98 reqChain.addFilter(tRules, false); 99 } finally { 100 _writeLock.unlock(); 101 } 102 } 103 104 public void resetResponseChain(TransformationRule[] tRules) throws 105 TransformException { 106 _writeLock.lock(); 107 try { 108 resChain = new FilterChain(); 109 resChain.addFilter(tRules, true); 110 } finally { 111 _writeLock.unlock(); 112 } 113 } 114 115 118 public String getName() { 119 return (NAME_PREFIX + _applicationId + DELIM + _endpointId); 120 } 121 122 125 static public String getName(String appId, WebServiceConfig wsc) { 126 return (NAME_PREFIX + appId + DELIM + wsc.getName()); 127 } 128 129 136 public void process(String stage, String endpoint, FilterContext context) { 137 138 _readLock.lock(); 139 try { 140 if ( stage.equals(Filter.PROCESS_REQUEST) ) { 142 if ( reqChain != null) { 144 reqChain.process(context); 145 } 146 } else if ( stage.equals(Filter.PROCESS_RESPONSE) ) { 148 if ( resChain != null) { 149 resChain.process(context); 150 } 151 } 152 } catch(Exception e) { 153 String msg = _stringMgr.getString("transform_failed", endpoint); 155 _logger.log(Level.INFO, msg, e); 156 } finally { 157 _readLock.unlock(); 158 } 159 160 } 161 162 private String _applicationId = null; 164 private String _endpointId = null; 165 private static final String DELIM = "#"; 166 private static final String NAME_PREFIX = "TRANSFORMFILTER_"; 167 private FilterChain reqChain = null; 168 private FilterChain resChain = null; 169 private ReentrantReadWriteLock _rwl = null; 170 private Lock _readLock = null; 171 private Lock _writeLock = null; 172 private static final Logger _logger = 173 Logger.getLogger(LogDomains.ADMIN_LOGGER); 174 private static final StringManager _stringMgr = 175 StringManager.getManager(TransformFilter.class); 176 177 178 } 179 | Popular Tags |