HttpWsdl1Deployer.java :  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » http » Java Open Source

Java Open Source » ESB » cbesb 1.2 
cbesb 1.2 » com » bostechcorp » cbesb » runtime » component » http » HttpWsdl1Deployer.java
/*
 * ChainBuilder ESB
 *     Visual Enterprise Integration
 * 
 * Copyright (C) 2007 Bostech Corporation
 * 
 * This program is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by the 
 * Free Software Foundation; either version 2 of the License, or (at your option) 
 * any later version.
 *
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
 * for more details.
 * 
 * You should have received a copy of the GNU General Public License along with 
 * this program; if not, write to the Free Software Foundation, Inc., 
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 *
 * $Id: HttpWsdl1Deployer.java 11318 2008-01-10 20:23:21Z mpreston $
 */
package com.bostechcorp.cbesb.runtime.component.http;

import javax.wsdl.extensions.ExtensibilityElement;
import javax.wsdl.extensions.ExtensionRegistry;
import javax.wsdl.extensions.http.HTTPAddress;
import javax.wsdl.extensions.http.HTTPBinding;
import javax.wsdl.extensions.soap.SOAPAddress;
import javax.wsdl.extensions.soap.SOAPBinding;
import javax.wsdl.extensions.soap12.SOAP12Address;
import javax.wsdl.extensions.soap12.SOAP12Binding;

import com.bostechcorp.cbesb.common.util.EsbPathHelper;
import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbEndpoint;
import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer;
import com.bostechcorp.cbesb.runtime.component.http.wsdl.HttpConfig;
import com.bostechcorp.cbesb.runtime.component.http.wsdl.HttpConfigExtension;

public class HttpWsdl1Deployer extends Wsdl1Deployer {

  HttpComponent httpComponent;
  
  /**
   * @param component
   */
  public HttpWsdl1Deployer(HttpComponent component) 
  {
    super(component);
    this.httpComponent = component;
  }

  /* (non-Javadoc)
   * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer#createEndpoint(javax.wsdl.extensions.ExtensibilityElement[], javax.wsdl.extensions.ExtensibilityElement[])
   */
  @Override
  protected CbEndpoint createEndpoint(ExtensibilityElement[] portElements,
      ExtensibilityElement[] bindingElements) 
  {
      HttpEndpoint endpoint = null;
      HttpConfig httpConfig = null;
      ExtensibilityElement portElement = null;
      ExtensibilityElement bindingElement = null;
      
      for (int i=0; i < portElements.length; i++) {
        if (portElements[i] instanceof HttpConfig) {
          httpConfig = (HttpConfig)portElements[i];
        } else if (portElements[i] instanceof HTTPAddress ||
            portElements[i] instanceof SOAPAddress ||
            portElements[i] instanceof SOAP12Address) {
          portElement = portElements[i];
        }
      }
      if (bindingElements.length == 1) {
        bindingElement = bindingElements[0];
      }
      
    if (httpConfig == null) {
          throw new UnsupportedOperationException("no config found in http endpoint for \""+portElement+"\"");
    }
    
        endpoint = new HttpEndpoint(httpComponent);

         endpoint.setRole(httpConfig.getRole());
         endpoint.setDefaultMep(httpConfig.getDefaultMep());
         endpoint.setDefaultOperation(httpConfig.getDefaultOperation());
      
        if (portElement instanceof HTTPAddress && bindingElement instanceof HTTPBinding) {
            if (!"POST".equals(((HTTPBinding) bindingElement).getVerb())) {
                throw new UnsupportedOperationException(((HTTPBinding) bindingElement).getVerb() + " not supported");
            }
            endpoint.setSoap(false);
            endpoint.setLocationURI(((HTTPAddress) portElement).getLocationURI());
            endpoint.setBinding(bindingElement);
        } else if (portElement instanceof SOAPAddress && bindingElement instanceof SOAPBinding) {
            endpoint.setSoap(true);
            endpoint.setLocationURI(((SOAPAddress) portElement).getLocationURI());
            endpoint.setBinding(bindingElement);
            endpoint.setSoapVersion("1.1");
            logger.debug("Using SOAP 1.1");
        } else if (portElement instanceof SOAP12Address && bindingElement instanceof SOAP12Binding) {
            endpoint.setSoap(true);
            endpoint.setLocationURI(((SOAP12Address) portElement).getLocationURI());
            endpoint.setBinding(bindingElement);
            endpoint.setSoapVersion("1.2");
            logger.debug("Using SOAP 1.2");
        } else {
          throw new UnsupportedOperationException("no valid HTTP or SOAP address and binding found for \""+portElement+"\"");
        }

         endpoint.setWsdlResource(httpConfig.getWsdlResource());
      endpoint.setMarshaller(httpConfig.getMarshaller());
      endpoint.setTimeout(httpConfig.getTimeout());
      endpoint.setAttachmentMode(httpConfig.getAttachmentMode());

    endpoint.setSslProtocol(httpConfig.getSslProtocol());
    endpoint.setUsePrivateKey(httpConfig.isUsePrivateKey());
    if (httpConfig.getKeyStoreFile() != null) {
      endpoint.setKeyStoreFile(processKeyStorePath(httpConfig.getKeyStoreFile()));
    }
    endpoint.setKeyStorePassword(httpConfig.getKeyStorePassword());
    if (httpConfig.getTrustStoreFile() != null) {
      endpoint.setTrustStoreFile(processKeyStorePath(httpConfig.getTrustStoreFile()));
    }
    endpoint.setTrustStorePassword(httpConfig.getTrustStorePassword());
    endpoint.setAuthenticateClient(httpConfig.isAuthenticateClient());
    endpoint.setAuthenticateServer(httpConfig.isAuthenticateServer());
      endpoint.setAllowAnonymous(httpConfig.isAllowAnonymous());
      
      endpoint.setAuthMode(httpConfig.getAuthMode());
      endpoint.setAuthUser(httpConfig.getAuthUser());
      endpoint.setAuthPassword(httpConfig.getAuthPassword());
    
    endpoint.setProxyHost(httpConfig.getProxyHost());
    endpoint.setProxyPort(httpConfig.getProxyPort());
    endpoint.setProxyUser(httpConfig.getProxyUser());
    endpoint.setProxyPassword(httpConfig.getProxyPassword());
      
    endpoint.setTargetService(httpConfig.getTargetService());
    endpoint.setTargetPort(httpConfig.getTargetPort());
    endpoint.setTargetOperation(httpConfig.getTargetOperation());
    
        return endpoint;
  }

    private String processKeyStorePath(String fileSpec) {
      try {
        return "file:" + EsbPathHelper.getFullPathForDef(fileSpec);
      }
      catch (Exception e) {
        logger.error("Exception occurred locating file: " + fileSpec, e);
        return null;
      }
    }

  /* (non-Javadoc)
   * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer#filterBindingElement(javax.wsdl.extensions.ExtensibilityElement)
   */
  @Override
  protected boolean filterBindingElement(ExtensibilityElement element) 
  {
        return element instanceof HTTPBinding || element instanceof SOAPBinding 
      || element instanceof SOAP12Binding;
  }

  /* (non-Javadoc)
   * @see com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.Wsdl1Deployer#filterPortElement(javax.wsdl.extensions.ExtensibilityElement)
   */
  @Override
  protected boolean filterPortElement(ExtensibilityElement element) 
  {
        if (element instanceof HTTPAddress) {
            return true;
        }
        if (element instanceof SOAPAddress) {
            String uri = ((SOAPAddress) element).getLocationURI();
            if (uri.startsWith("http://") || uri.startsWith("https://")) {
                return true;
            }
        }
        if (element instanceof SOAP12Address) {
            String uri = ((SOAP12Address) element).getLocationURI();
            if (uri.startsWith("http://") || uri.startsWith("https://")) {
                return true;
            }
        }
        if (element instanceof HttpConfig) {
          return true;
        }
        return false;
  }

  /*
   * (non-Javadoc)
   * 
   * @see org.apache.servicemix.common.wsdl.AbstractWsdlDeployer#registerExtensions(javax.wsdl.extensions.ExtensionRegistry)
   */
  protected void registerExtensions(ExtensionRegistry registry) {
    super.registerExtensions(registry);
    HttpConfigExtension.register(registry);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.