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.transport;
019:
020: import java.net.URI;
021: import java.net.URISyntaxException;
022:
023: import javax.xml.namespace.QName;
024:
025: import org.apache.cxf.Bus;
026: import org.apache.cxf.binding.Binding;
027: import org.apache.cxf.endpoint.Endpoint;
028: import org.apache.cxf.message.Exchange;
029: import org.apache.cxf.message.ExchangeImpl;
030: import org.apache.cxf.message.Message;
031: import org.apache.cxf.phase.PhaseChainCache;
032: import org.apache.cxf.phase.PhaseInterceptorChain;
033: import org.apache.cxf.phase.PhaseManager;
034: import org.apache.cxf.service.Service;
035: import org.apache.cxf.service.model.EndpointInfo;
036:
037: public class ChainInitiationObserver implements MessageObserver {
038: protected Endpoint endpoint;
039: protected Bus bus;
040:
041: private PhaseChainCache chainCache = new PhaseChainCache();
042:
043: public ChainInitiationObserver(Endpoint endpoint, Bus bus) {
044: super ();
045: this .endpoint = endpoint;
046: this .bus = bus;
047: }
048:
049: public void onMessage(Message m) {
050: Message message = getBinding().createMessage(m);
051: Exchange exchange = message.getExchange();
052: if (exchange == null) {
053: exchange = new ExchangeImpl();
054: exchange.setInMessage(message);
055: }
056: setExchangeProperties(exchange, message);
057:
058: // setup chain
059: PhaseInterceptorChain chain = chainCache.get(bus.getExtension(
060: PhaseManager.class).getInPhases(), bus
061: .getInInterceptors(), endpoint.getInInterceptors(),
062: getBinding().getInInterceptors(), endpoint.getService()
063: .getInInterceptors());
064:
065: message.setInterceptorChain(chain);
066:
067: chain.setFaultObserver(endpoint.getOutFaultObserver());
068:
069: chain.doIntercept(message);
070: }
071:
072: protected Binding getBinding() {
073: return endpoint.getBinding();
074: }
075:
076: protected void setExchangeProperties(Exchange exchange, Message m) {
077: exchange.put(Endpoint.class, endpoint);
078: exchange.put(Service.class, endpoint.getService());
079: exchange.put(Binding.class, getBinding());
080: exchange.put(Bus.class, bus);
081: if (exchange.getDestination() == null) {
082: exchange.setDestination(m.getDestination());
083: }
084: if (endpoint != null) {
085:
086: EndpointInfo endpointInfo = endpoint.getEndpointInfo();
087:
088: QName serviceQName = endpointInfo.getService().getName();
089: exchange.put(Message.WSDL_SERVICE, serviceQName);
090:
091: QName interfaceQName = endpointInfo.getService()
092: .getInterface().getName();
093: exchange.put(Message.WSDL_INTERFACE, interfaceQName);
094:
095: QName portQName = endpointInfo.getName();
096: exchange.put(Message.WSDL_PORT, portQName);
097: URI wsdlDescription = endpointInfo.getProperty("URI",
098: URI.class);
099: if (wsdlDescription == null) {
100: String address = endpointInfo.getAddress();
101: try {
102: wsdlDescription = new URI(address + "?wsdl");
103: } catch (URISyntaxException e) {
104: // do nothing
105: }
106: endpointInfo.setProperty("URI", wsdlDescription);
107: }
108: exchange.put(Message.WSDL_DESCRIPTION, wsdlDescription);
109: }
110: }
111:
112: public Endpoint getEndpoint() {
113: return endpoint;
114: }
115:
116: }
|