01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.transport;
19:
20: import java.io.IOException;
21: import java.io.InputStream;
22: import java.io.OutputStream;
23:
24: import org.apache.cxf.message.Message;
25: import org.apache.cxf.ws.addressing.EndpointReferenceType;
26:
27: /**
28: * Abstract base class factoring out common Conduit logic,
29: * allowing non-decoupled transports to be written without any
30: * regard for the decoupled back-channel or partial response logic.
31: */
32: public abstract class AbstractConduit extends AbstractObservable
33: implements Conduit {
34:
35: protected final EndpointReferenceType target;
36:
37: public AbstractConduit(EndpointReferenceType t) {
38: target = t;
39: }
40:
41: /**
42: * @return the reference associated with the target Destination
43: */
44: public EndpointReferenceType getTarget() {
45: return target;
46: }
47:
48: /**
49: * Retreive the back-channel Destination.
50: *
51: * @return the backchannel Destination (or null if the backchannel is
52: * built-in)
53: */
54: public Destination getBackChannel() {
55: return null;
56: }
57:
58: /**
59: * @param message for which content should be closed.
60: */
61: public void close(Message msg) throws IOException {
62: OutputStream os = msg.getContent(OutputStream.class);
63: if (os != null) {
64: os.close();
65: }
66: InputStream in = msg.getContent(InputStream.class);
67: if (in != null) {
68: in.close();
69: }
70: }
71:
72: /**
73: * Close the conduit.
74: */
75: public void close() {
76: // nothing to do by default
77: }
78:
79: public String toString() {
80: return "conduit: "
81: + this .getClass()
82: + System.identityHashCode(this )
83: + "target: "
84: + ((getTarget() != null && getTarget().getAddress() != null) ? getTarget()
85: .getAddress().getValue()
86: : "null");
87: }
88: }
|