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.jbi;
019:
020: import java.io.IOException;
021: import java.io.OutputStream;
022: import java.util.logging.Logger;
023:
024: import javax.jbi.messaging.DeliveryChannel;
025: import javax.jbi.messaging.MessageExchange;
026:
027: import org.apache.cxf.common.logging.LogUtils;
028: import org.apache.cxf.message.Message;
029: import org.apache.cxf.service.model.EndpointInfo;
030: import org.apache.cxf.transport.AbstractConduit;
031: import org.apache.cxf.transport.AbstractDestination;
032: import org.apache.cxf.transport.Conduit;
033: import org.apache.cxf.transport.MessageObserver;
034: import org.apache.cxf.ws.addressing.EndpointReferenceType;
035: import org.apache.cxf.wsdl.EndpointReferenceUtils;
036:
037: public class JBIDestination extends AbstractDestination {
038:
039: private static final Logger LOG = LogUtils
040: .getL7dLogger(JBIDestination.class);
041: private JBIDispatcherUtil dispatcherUtil;
042: private DeliveryChannel channel;
043:
044: public JBIDestination(EndpointInfo info,
045: JBIDispatcherUtil dispatcher, DeliveryChannel dc) {
046: super (getTargetReference(info, null), info);
047: this .dispatcherUtil = dispatcher;
048: this .channel = dc;
049: }
050:
051: public void setDeliveryChannel(DeliveryChannel dc) {
052: this .channel = dc;
053: }
054:
055: public DeliveryChannel getDeliveryChannel() {
056: return this .channel;
057: }
058:
059: protected Logger getLogger() {
060: return LOG;
061: }
062:
063: /**
064: * @param inMessage the incoming message
065: * @return the inbuilt backchannel
066: */
067: protected Conduit getInbuiltBackChannel(Message inMessage) {
068: return new BackChannelConduit(EndpointReferenceUtils
069: .getAnonymousEndpointReference(), inMessage);
070: }
071:
072: public void shutdown() {
073: dispatcherUtil.deactivateDispatch();
074: }
075:
076: public void deactivate() {
077: dispatcherUtil.deactivateDispatch();
078: }
079:
080: public void activate() {
081: dispatcherUtil.activateDispatch();
082: }
083:
084: public JBIDispatcherUtil getJBIDispatcherUtil() {
085: return dispatcherUtil;
086: }
087:
088: // this should deal with the cxf message
089: protected class BackChannelConduit extends AbstractConduit {
090:
091: protected Message inMessage;
092: protected JBIDestination jbiDestination;
093:
094: BackChannelConduit(EndpointReferenceType ref, Message message) {
095: super (ref);
096: inMessage = message;
097: }
098:
099: /**
100: * Register a message observer for incoming messages.
101: *
102: * @param observer the observer to notify on receipt of incoming
103: */
104: public void setMessageObserver(MessageObserver observer) {
105: // shouldn't be called for a back channel conduit
106: }
107:
108: /**
109: * Send an outbound message, assumed to contain all the name-value
110: * mappings of the corresponding input message (if any).
111: *
112: * @param message the message to be sent.
113: */
114: public void prepare(Message message) throws IOException {
115: // setup the message to be send back
116: DeliveryChannel dc = channel;
117: message.put(MessageExchange.class, inMessage
118: .get(MessageExchange.class));
119: message.setContent(OutputStream.class,
120: new JBIDestinationOutputStream(inMessage, dc));
121: }
122:
123: protected Logger getLogger() {
124: return LOG;
125: }
126: }
127:
128: }
|