001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2007 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id: HttpWsdl1Deployer.java 11318 2008-01-10 20:23:21Z mpreston $
023: */
024: package com.bostechcorp.cbesb.runtime.component.http;
025:
026: import javax.wsdl.extensions.ExtensibilityElement;
027: import javax.wsdl.extensions.ExtensionRegistry;
028: import javax.wsdl.extensions.http.HTTPAddress;
029: import javax.wsdl.extensions.http.HTTPBinding;
030: import javax.wsdl.extensions.soap.SOAPAddress;
031: import javax.wsdl.extensions.soap.SOAPBinding;
032: import javax.wsdl.extensions.soap12.SOAP12Address;
033: import javax.wsdl.extensions.soap12.SOAP12Binding;
034:
035: import com.bostechcorp.cbesb.common.util.EsbPathHelper;
036: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbEndpoint;
037: import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer;
038: import com.bostechcorp.cbesb.runtime.component.http.wsdl.HttpConfig;
039: import com.bostechcorp.cbesb.runtime.component.http.wsdl.HttpConfigExtension;
040:
041: public class HttpWsdl1Deployer extends Wsdl1Deployer {
042:
043: HttpComponent httpComponent;
044:
045: /**
046: * @param component
047: */
048: public HttpWsdl1Deployer(HttpComponent component) {
049: super (component);
050: this .httpComponent = component;
051: }
052:
053: /* (non-Javadoc)
054: * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer#createEndpoint(javax.wsdl.extensions.ExtensibilityElement[], javax.wsdl.extensions.ExtensibilityElement[])
055: */
056: @Override
057: protected CbEndpoint createEndpoint(
058: ExtensibilityElement[] portElements,
059: ExtensibilityElement[] bindingElements) {
060: HttpEndpoint endpoint = null;
061: HttpConfig httpConfig = null;
062: ExtensibilityElement portElement = null;
063: ExtensibilityElement bindingElement = null;
064:
065: for (int i = 0; i < portElements.length; i++) {
066: if (portElements[i] instanceof HttpConfig) {
067: httpConfig = (HttpConfig) portElements[i];
068: } else if (portElements[i] instanceof HTTPAddress
069: || portElements[i] instanceof SOAPAddress
070: || portElements[i] instanceof SOAP12Address) {
071: portElement = portElements[i];
072: }
073: }
074: if (bindingElements.length == 1) {
075: bindingElement = bindingElements[0];
076: }
077:
078: if (httpConfig == null) {
079: throw new UnsupportedOperationException(
080: "no config found in http endpoint for \""
081: + portElement + "\"");
082: }
083:
084: endpoint = new HttpEndpoint(httpComponent);
085:
086: endpoint.setRole(httpConfig.getRole());
087: endpoint.setDefaultMep(httpConfig.getDefaultMep());
088: endpoint.setDefaultOperation(httpConfig.getDefaultOperation());
089:
090: if (portElement instanceof HTTPAddress
091: && bindingElement instanceof HTTPBinding) {
092: if (!"POST"
093: .equals(((HTTPBinding) bindingElement).getVerb())) {
094: throw new UnsupportedOperationException(
095: ((HTTPBinding) bindingElement).getVerb()
096: + " not supported");
097: }
098: endpoint.setSoap(false);
099: endpoint.setLocationURI(((HTTPAddress) portElement)
100: .getLocationURI());
101: endpoint.setBinding(bindingElement);
102: } else if (portElement instanceof SOAPAddress
103: && bindingElement instanceof SOAPBinding) {
104: endpoint.setSoap(true);
105: endpoint.setLocationURI(((SOAPAddress) portElement)
106: .getLocationURI());
107: endpoint.setBinding(bindingElement);
108: endpoint.setSoapVersion("1.1");
109: logger.debug("Using SOAP 1.1");
110: } else if (portElement instanceof SOAP12Address
111: && bindingElement instanceof SOAP12Binding) {
112: endpoint.setSoap(true);
113: endpoint.setLocationURI(((SOAP12Address) portElement)
114: .getLocationURI());
115: endpoint.setBinding(bindingElement);
116: endpoint.setSoapVersion("1.2");
117: logger.debug("Using SOAP 1.2");
118: } else {
119: throw new UnsupportedOperationException(
120: "no valid HTTP or SOAP address and binding found for \""
121: + portElement + "\"");
122: }
123:
124: endpoint.setWsdlResource(httpConfig.getWsdlResource());
125: endpoint.setMarshaller(httpConfig.getMarshaller());
126: endpoint.setTimeout(httpConfig.getTimeout());
127: endpoint.setAttachmentMode(httpConfig.getAttachmentMode());
128:
129: endpoint.setSslProtocol(httpConfig.getSslProtocol());
130: endpoint.setUsePrivateKey(httpConfig.isUsePrivateKey());
131: if (httpConfig.getKeyStoreFile() != null) {
132: endpoint.setKeyStoreFile(processKeyStorePath(httpConfig
133: .getKeyStoreFile()));
134: }
135: endpoint.setKeyStorePassword(httpConfig.getKeyStorePassword());
136: if (httpConfig.getTrustStoreFile() != null) {
137: endpoint.setTrustStoreFile(processKeyStorePath(httpConfig
138: .getTrustStoreFile()));
139: }
140: endpoint.setTrustStorePassword(httpConfig
141: .getTrustStorePassword());
142: endpoint.setAuthenticateClient(httpConfig
143: .isAuthenticateClient());
144: endpoint.setAuthenticateServer(httpConfig
145: .isAuthenticateServer());
146: endpoint.setAllowAnonymous(httpConfig.isAllowAnonymous());
147:
148: endpoint.setAuthMode(httpConfig.getAuthMode());
149: endpoint.setAuthUser(httpConfig.getAuthUser());
150: endpoint.setAuthPassword(httpConfig.getAuthPassword());
151:
152: endpoint.setProxyHost(httpConfig.getProxyHost());
153: endpoint.setProxyPort(httpConfig.getProxyPort());
154: endpoint.setProxyUser(httpConfig.getProxyUser());
155: endpoint.setProxyPassword(httpConfig.getProxyPassword());
156:
157: endpoint.setTargetService(httpConfig.getTargetService());
158: endpoint.setTargetPort(httpConfig.getTargetPort());
159: endpoint.setTargetOperation(httpConfig.getTargetOperation());
160:
161: return endpoint;
162: }
163:
164: private String processKeyStorePath(String fileSpec) {
165: try {
166: return "file:" + EsbPathHelper.getFullPathForDef(fileSpec);
167: } catch (Exception e) {
168: logger.error("Exception occurred locating file: "
169: + fileSpec, e);
170: return null;
171: }
172: }
173:
174: /* (non-Javadoc)
175: * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer#filterBindingElement(javax.wsdl.extensions.ExtensibilityElement)
176: */
177: @Override
178: protected boolean filterBindingElement(ExtensibilityElement element) {
179: return element instanceof HTTPBinding
180: || element instanceof SOAPBinding
181: || element instanceof SOAP12Binding;
182: }
183:
184: /* (non-Javadoc)
185: * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer#filterPortElement(javax.wsdl.extensions.ExtensibilityElement)
186: */
187: @Override
188: protected boolean filterPortElement(ExtensibilityElement element) {
189: if (element instanceof HTTPAddress) {
190: return true;
191: }
192: if (element instanceof SOAPAddress) {
193: String uri = ((SOAPAddress) element).getLocationURI();
194: if (uri.startsWith("http://") || uri.startsWith("https://")) {
195: return true;
196: }
197: }
198: if (element instanceof SOAP12Address) {
199: String uri = ((SOAP12Address) element).getLocationURI();
200: if (uri.startsWith("http://") || uri.startsWith("https://")) {
201: return true;
202: }
203: }
204: if (element instanceof HttpConfig) {
205: return true;
206: }
207: return false;
208: }
209:
210: /*
211: * (non-Javadoc)
212: *
213: * @see org.apache.servicemix.common.wsdl.AbstractWsdlDeployer#registerExtensions(javax.wsdl.extensions.ExtensionRegistry)
214: */
215: protected void registerExtensions(ExtensionRegistry registry) {
216: super.registerExtensions(registry);
217: HttpConfigExtension.register(registry);
218: }
219: }
|