001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.binding.soap;
019:
020: import java.io.IOException;
021: import java.util.Collection;
022: import java.util.Iterator;
023: import java.util.List;
024: import javax.annotation.PostConstruct;
025: import javax.annotation.Resource;
026: import javax.wsdl.Port;
027: import javax.wsdl.WSDLException;
028: import javax.wsdl.extensions.ExtensionRegistry;
029: import javax.wsdl.factory.WSDLFactory;
030:
031: import org.apache.cxf.Bus;
032: import org.apache.cxf.BusException;
033: import org.apache.cxf.binding.soap.model.SoapBindingInfo;
034: import org.apache.cxf.binding.soap.wsdl11.SoapAddressPlugin;
035: import org.apache.cxf.service.Service;
036: import org.apache.cxf.service.model.BindingInfo;
037: import org.apache.cxf.service.model.EndpointInfo;
038: import org.apache.cxf.service.model.ServiceInfo;
039: import org.apache.cxf.tools.common.extensions.soap.SoapAddress;
040: import org.apache.cxf.tools.util.SOAPBindingUtil;
041: import org.apache.cxf.transport.AbstractTransportFactory;
042: import org.apache.cxf.transport.Conduit;
043: import org.apache.cxf.transport.ConduitInitiator;
044: import org.apache.cxf.transport.ConduitInitiatorManager;
045: import org.apache.cxf.transport.Destination;
046: import org.apache.cxf.transport.DestinationFactory;
047: import org.apache.cxf.transport.DestinationFactoryManager;
048: import org.apache.cxf.ws.addressing.EndpointReferenceType;
049: import org.apache.cxf.wsdl11.WSDLEndpointFactory;
050:
051: public class SoapTransportFactory extends AbstractTransportFactory
052: implements DestinationFactory, WSDLEndpointFactory,
053: ConduitInitiator {
054:
055: public static final String SOAP_11_HTTP_BINDING = "http://schemas.xmlsoap.org/soap/http";
056: public static final String SOAP_12_HTTP_BINDING = "http://www.w3.org/2003/05/soap/bindings/HTTP/";
057:
058: public static final String TRANSPORT_ID = "http://schemas.xmlsoap.org/soap/";
059:
060: private Bus bus;
061: private Collection<String> activationNamespaces;
062:
063: public SoapTransportFactory() {
064: super ();
065: }
066:
067: public Destination getDestination(EndpointInfo ei)
068: throws IOException {
069: SoapBindingInfo binding = (SoapBindingInfo) ei.getBinding();
070: DestinationFactory destinationFactory;
071: try {
072: destinationFactory = bus.getExtension(
073: DestinationFactoryManager.class)
074: .getDestinationFactory(binding.getTransportURI());
075: return destinationFactory.getDestination(ei);
076: } catch (BusException e) {
077: throw new RuntimeException(
078: "Could not find destination factory for transport "
079: + binding.getTransportURI());
080: }
081: }
082:
083: public void createPortExtensors(EndpointInfo ei, Service service) {
084: if (ei.getBinding() instanceof SoapBindingInfo) {
085: SoapBindingInfo bi = (SoapBindingInfo) ei.getBinding();
086: createSoapExtensors(ei, bi,
087: bi.getSoapVersion() instanceof Soap12);
088: }
089: }
090:
091: private void createSoapExtensors(EndpointInfo ei,
092: SoapBindingInfo bi, boolean isSoap12) {
093: try {
094: // We need to populate the soap extensibilityelement proxy for soap11 and soap12
095: ExtensionRegistry extensionRegistry = WSDLFactory
096: .newInstance().newPopulatedExtensionRegistry();
097: SoapAddressPlugin addresser = new SoapAddressPlugin();
098: addresser.setExtensionRegistry(extensionRegistry);
099: //SoapAddress soapAddress = SOAPBindingUtil.createSoapAddress(extensionRegistry, isSoap12);
100: String address = ei.getAddress();
101: if (address == null) {
102: address = "http://localhost:9090";
103: }
104:
105: //soapAddress.setLocationURI(address);
106: ei
107: .addExtensor(addresser.createExtension(isSoap12,
108: address));
109:
110: //createSoapBinding(isSoap12, extensionRegistry, bi);
111:
112: } catch (WSDLException e) {
113: e.printStackTrace();
114: }
115: }
116:
117: public EndpointInfo createEndpointInfo(ServiceInfo serviceInfo,
118: BindingInfo b, Port port) {
119: String transportURI = "http://schemas.xmlsoap.org/wsdl/soap/";
120: if (b instanceof SoapBindingInfo) {
121: SoapBindingInfo sbi = (SoapBindingInfo) b;
122: transportURI = sbi.getTransportURI();
123: }
124: if (port != null) {
125: List ees = port.getExtensibilityElements();
126: for (Iterator itr = ees.iterator(); itr.hasNext();) {
127: Object extensor = itr.next();
128:
129: if (SOAPBindingUtil.isSOAPAddress(extensor)) {
130: final SoapAddress sa = SOAPBindingUtil
131: .getSoapAddress(extensor);
132:
133: EndpointInfo info = new SoapEndpointInfo(
134: serviceInfo, transportURI);
135: info.addExtensor(sa);
136: info.setAddress(sa.getLocationURI());
137: return info;
138: }
139: }
140: }
141: return new SoapEndpointInfo(serviceInfo, transportURI);
142: }
143:
144: public Conduit getConduit(EndpointInfo ei,
145: EndpointReferenceType target) throws IOException {
146: return getConduit(ei);
147: }
148:
149: public Conduit getConduit(EndpointInfo ei) throws IOException {
150: SoapBindingInfo binding = (SoapBindingInfo) ei.getBinding();
151: ConduitInitiator conduitInit;
152: try {
153: conduitInit = bus.getExtension(
154: ConduitInitiatorManager.class).getConduitInitiator(
155: binding.getTransportURI());
156:
157: return conduitInit.getConduit(ei);
158: } catch (BusException e) {
159: throw new RuntimeException(
160: "Could not find conduit initiator for transport "
161: + binding.getTransportURI());
162: }
163: }
164:
165: public Bus getBus() {
166: return bus;
167: }
168:
169: @Resource(name="bus")
170: public void setBus(Bus bus) {
171: this .bus = bus;
172: }
173:
174: @Resource(name="activationNamespaces")
175: public void setActivationNamespaces(Collection<String> ans) {
176: activationNamespaces = ans;
177: }
178:
179: @PostConstruct
180: void registerWithBindingManager() {
181: if (null == bus) {
182: return;
183: }
184:
185: DestinationFactoryManager dfm = bus
186: .getExtension(DestinationFactoryManager.class);
187: if (null != dfm) {
188: for (String ns : activationNamespaces) {
189: dfm.registerDestinationFactory(ns, this );
190: }
191: }
192: }
193:
194: private static class SoapEndpointInfo extends EndpointInfo {
195: SoapAddress saddress;
196:
197: SoapEndpointInfo(ServiceInfo serv, String trans) {
198: super (serv, trans);
199: }
200:
201: public void setAddress(String s) {
202: super .setAddress(s);
203: if (saddress != null) {
204: saddress.setLocationURI(s);
205: }
206: }
207:
208: public void addExtensor(Object el) {
209: super .addExtensor(el);
210: if (el instanceof SoapAddress) {
211: saddress = (SoapAddress) el;
212: }
213: }
214: }
215:
216: }
|