001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one or more
003     * contributor license agreements.  See the NOTICE file distributed with
004     * this work for additional information regarding copyright ownership.
005     * The ASF licenses this file to You under the Apache License, Version 2.0
006     * (the "License"); you may not use this file except in compliance with
007     * the License.  You may obtain a copy of the License at
008     *
009     *      http://www.apache.org/licenses/LICENSE-2.0
010     *
011     * Unless required by applicable law or agreed to in writing, software
012     * distributed under the License is distributed on an "AS IS" BASIS,
013     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     * See the License for the specific language governing permissions and
015     * limitations under the License.
016     */
017    package org.apache.servicemix.http;
018    
019    import javax.wsdl.extensions.ExtensibilityElement;
020    import javax.wsdl.extensions.http.HTTPAddress;
021    import javax.wsdl.extensions.http.HTTPBinding;
022    import javax.wsdl.extensions.soap.SOAPAddress;
023    import javax.wsdl.extensions.soap.SOAPBinding;
024    
025    import org.apache.servicemix.common.Endpoint;
026    import org.apache.servicemix.common.ServiceMixComponent;
027    import org.apache.servicemix.common.endpoints.AbstractEndpoint;
028    import org.apache.servicemix.common.wsdl1.AbstractWsdl1Deployer;
029    import org.apache.servicemix.common.wsdl1.JbiEndpoint;
030    
031    /**
032     * @author gnodet
033     * 
034     */
035    public class HttpWsdl1Deployer extends AbstractWsdl1Deployer {
036    
037        public HttpWsdl1Deployer(ServiceMixComponent component) {
038            super(component);
039        }
040    
041        /*
042         * (non-Javadoc)
043         * 
044         * @see org.servicemix.common.wsdl1.AbstractWsdl1Deployer#createEndpoint(javax.wsdl.extensions.ExtensibilityElement,
045         *      javax.wsdl.extensions.ExtensibilityElement)
046         */
047        protected AbstractEndpoint createEndpoint(ExtensibilityElement portElement, ExtensibilityElement bindingElement,
048                        JbiEndpoint jbiEndpoint) {
049            if (jbiEndpoint == null) {
050                return null;
051            }
052            if (portElement instanceof HTTPAddress && bindingElement instanceof HTTPBinding) {
053                if (!"POST".equals(((HTTPBinding) bindingElement).getVerb())) {
054                    throw new UnsupportedOperationException(((HTTPBinding) bindingElement).getVerb() + " not supported");
055                }
056                HttpEndpoint endpoint = new HttpEndpoint();
057                endpoint.setSoap(false);
058                endpoint.setRole(jbiEndpoint.getRole());
059                endpoint.setDefaultMep(jbiEndpoint.getDefaultMep());
060                endpoint.setDefaultOperation(jbiEndpoint.getDefaultOperation());
061                endpoint.setLocationURI(((HTTPAddress) portElement).getLocationURI());
062                return endpoint;
063            } else if (portElement instanceof SOAPAddress && bindingElement instanceof SOAPBinding) {
064                HttpEndpoint endpoint = new HttpEndpoint();
065                endpoint.setSoap(true);
066                endpoint.setRole(jbiEndpoint.getRole());
067                endpoint.setDefaultMep(jbiEndpoint.getDefaultMep());
068                endpoint.setDefaultOperation(jbiEndpoint.getDefaultOperation());
069                endpoint.setLocationURI(((SOAPAddress) portElement).getLocationURI());
070                return endpoint;
071            } else {
072                return null;
073            }
074        }
075    
076        /*
077         * (non-Javadoc)
078         * 
079         * @see org.servicemix.common.wsdl1.AbstractWsdl1Deployer#filterPortElement(javax.wsdl.extensions.ExtensibilityElement)
080         */
081        protected boolean filterPortElement(ExtensibilityElement element) {
082            if (element instanceof HTTPAddress) {
083                return true;
084            }
085            if (element instanceof SOAPAddress) {
086                String uri = ((SOAPAddress) element).getLocationURI();
087                if (uri.startsWith("http://") || uri.startsWith("https://")) {
088                    return true;
089                }
090            }
091            return false;
092        }
093    
094        /*
095         * (non-Javadoc)
096         * 
097         * @see org.servicemix.common.wsdl1.AbstractWsdl1Deployer#filterBindingElement(javax.wsdl.extensions.ExtensibilityElement)
098         */
099        protected boolean filterBindingElement(ExtensibilityElement element) {
100            return element instanceof HTTPBinding || element instanceof SOAPBinding;
101        }
102    
103    }