1 17 package org.apache.servicemix.http; 18 19 import java.net.URI ; 20 21 import javax.jbi.component.ComponentLifeCycle; 22 import javax.jbi.servicedesc.ServiceEndpoint; 23 import javax.wsdl.Binding; 24 import javax.wsdl.Definition; 25 import javax.wsdl.Port; 26 import javax.wsdl.PortType; 27 import javax.wsdl.Service; 28 import javax.wsdl.extensions.ExtensibilityElement; 29 import javax.wsdl.extensions.http.HTTPAddress; 30 import javax.xml.namespace.QName ; 31 32 import org.apache.servicemix.common.ExchangeProcessor; 33 import org.apache.servicemix.http.processors.ConsumerProcessor; 34 import org.apache.servicemix.http.processors.ProviderProcessor; 35 import org.apache.servicemix.http.tools.PortTypeDecorator; 36 import org.apache.servicemix.jbi.security.auth.AuthenticationService; 37 import org.apache.servicemix.jbi.security.keystore.KeystoreManager; 38 import org.apache.servicemix.soap.SoapEndpoint; 39 40 import com.ibm.wsdl.extensions.http.HTTPAddressImpl; 41 42 50 public class HttpEndpoint extends SoapEndpoint { 51 52 protected ExtensibilityElement binding; 53 protected String locationURI; 54 protected SslParameters ssl; 55 protected String authMethod; 56 protected String soapAction; 57 protected BasicAuthCredentials basicAuthentication; 58 59 62 public String getSoapAction() { 63 return soapAction; 64 } 65 66 69 public void setSoapAction(String soapAction) { 70 this.soapAction = soapAction; 71 } 72 73 76 public String getAuthMethod() { 77 return authMethod; 78 } 79 80 83 public void setAuthMethod(String authMethod) { 84 this.authMethod = authMethod; 85 } 86 87 90 public SslParameters getSsl() { 91 return ssl; 92 } 93 94 97 public void setSsl(SslParameters ssl) { 98 this.ssl = ssl; 99 } 100 101 public ExtensibilityElement getBinding() { 102 return binding; 103 } 104 105 public void setBinding(ExtensibilityElement binding) { 106 this.binding = binding; 107 } 108 109 public String getLocationURI() { 110 return locationURI; 111 } 112 113 public void setLocationURI(String locationUri) { 114 this.locationURI = locationUri; 115 } 116 117 123 public BasicAuthCredentials getBasicAuthentication() { 124 return basicAuthentication; 125 } 126 127 130 public void setBasicAuthentication(BasicAuthCredentials basicAuthCredentials) { 131 this.basicAuthentication = basicAuthCredentials; 132 } 133 134 138 public void setRoleAsString(String role) { 139 super.setRoleAsString(role); 140 } 141 142 protected PortType getTargetPortType(Definition def) { 143 PortType portType = null; 144 if (def.getServices().size() == 0 && def.getPortTypes().size() == 1) { 146 if (logger.isDebugEnabled()) { 147 logger.debug("WSDL only defines a PortType, using this one"); 148 } 149 portType = (PortType) def.getPortTypes().values().iterator().next(); 150 } else if (targetInterfaceName != null) { 151 portType = def.getPortType(targetInterfaceName); 152 if (portType == null && logger.isDebugEnabled()) { 153 logger.debug("PortType for targetInterfaceName could not be found"); 154 } 155 } else if (targetService != null && targetEndpoint != null) { 156 Service svc = def.getService(targetService); 157 Port port = (svc != null) ? svc.getPort(targetEndpoint) : null; 158 portType = (port != null) ? port.getBinding().getPortType() : null; 159 if (portType == null && logger.isDebugEnabled()) { 160 logger.debug("PortType for targetService/targetEndpoint could not be found"); 161 } 162 } else if (targetService != null) { 163 Service svc = def.getService(targetService); 164 if (svc != null && svc.getPorts().size() == 1) { 165 Port port = (Port) svc.getPorts().values().iterator().next(); 166 portType = (port != null) ? port.getBinding().getPortType() : null; 167 } 168 if (portType == null && logger.isDebugEnabled()) { 169 logger.debug("Service for targetService could not be found"); 170 } 171 } else if (interfaceName != null) { 172 portType = def.getPortType(interfaceName); 173 if (portType == null && logger.isDebugEnabled()) { 174 logger.debug("Service for targetInterfaceName could not be found"); 175 } 176 } else { 177 Service svc = def.getService(service); 178 Port port = (svc != null) ? svc.getPort(endpoint) : null; 179 portType = (port != null && port.getBinding() != null) ? port.getBinding().getPortType() : null; 180 if (portType == null && logger.isDebugEnabled()) { 181 logger.debug("Port for service/endpoint could not be found"); 182 } 183 } 184 return portType; 185 } 186 187 protected void overrideDefinition(Definition def) throws Exception { 188 PortType portType = getTargetPortType(def); 189 if (portType != null) { 190 QName [] names = (QName []) def.getPortTypes().keySet().toArray(new QName [0]); 191 for (int i = 0; i < names.length; i++) { 192 if (!names[i].equals(portType.getQName())) { 193 def.removePortType(names[i]); 194 } 195 } 196 names = (QName []) def.getServices().keySet().toArray(new QName [0]); 197 for (int i = 0; i < names.length; i++) { 198 def.removeService(names[i]); 199 } 200 names = (QName []) def.getBindings().keySet().toArray(new QName [0]); 201 for (int i = 0; i < names.length; i++) { 202 def.removeBinding(names[i]); 203 } 204 String location = getLocationURI(); 205 if (!location.endsWith("/")) { 206 location += "/"; 207 } 208 HttpLifeCycle lf = (HttpLifeCycle) getServiceUnit().getComponent().getLifeCycle(); 209 if (lf.getConfiguration().isManaged()) { 210 location = "http://localhost" + lf.getConfiguration().getMapping() + new URI (location).getPath(); 212 } 213 if (portType.getQName().getNamespaceURI().equals(service.getNamespaceURI())) { 214 if (isSoap()) { 215 PortTypeDecorator.decorate( 216 def, 217 portType, 218 location, 219 endpoint + "Binding", 220 service.getLocalPart(), 221 endpoint); 222 definition = def; 223 } else { 224 Binding binding = def.createBinding(); 225 binding.setPortType(portType); 226 binding.setQName(new QName (service.getNamespaceURI(), endpoint + "Binding")); 227 binding.setUndefined(false); 228 def.addBinding(binding); 229 Port port = def.createPort(); 230 port.setName(endpoint); 231 port.setBinding(binding); 232 HTTPAddress address = new HTTPAddressImpl(); 233 address.setLocationURI(location); 234 port.addExtensibilityElement(address); 235 def.addNamespace("http", "http://schemas.xmlsoap.org/wsdl/http/"); 236 Service svc = def.createService(); 237 svc.setQName(service); 238 svc.addPort(port); 239 def.addService(svc); 240 definition = def; 241 } 242 } else { 243 definition = PortTypeDecorator.createImportDef(def, service.getNamespaceURI(), "porttypedef.wsdl"); 244 PortTypeDecorator.decorate( 245 definition, 246 portType, 247 location, 248 endpoint + "Binding", 249 service.getLocalPart(), 250 endpoint); 251 } 252 } 253 } 254 255 protected ExchangeProcessor createProviderProcessor() { 256 return new ProviderProcessor(this); 257 } 258 259 protected ExchangeProcessor createConsumerProcessor() { 260 return new ConsumerProcessor(this); 261 } 262 263 protected ServiceEndpoint createExternalEndpoint() { 264 return new HttpExternalEndpoint(this); 265 } 266 267 public AuthenticationService getAuthenticationService() { 268 ComponentLifeCycle lf = getServiceUnit().getComponent().getLifeCycle(); 269 return ((HttpLifeCycle) lf).getAuthenticationService(); 270 } 271 272 public KeystoreManager getKeystoreManager() { 273 ComponentLifeCycle lf = getServiceUnit().getComponent().getLifeCycle(); 274 return ((HttpLifeCycle) lf).getKeystoreManager(); 275 } 276 277 278 279 } 280 | Popular Tags |