001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.transport.tcp.client;
038:
039: import com.sun.istack.NotNull;
040: import com.sun.xml.ws.api.message.Packet;
041: import com.sun.xml.ws.api.pipe.ClientPipeAssemblerContext;
042: import com.sun.xml.ws.api.pipe.ContentType;
043: import com.sun.xml.ws.api.pipe.Pipe;
044: import com.sun.xml.ws.api.pipe.PipeCloner;
045: import com.sun.xml.ws.transport.tcp.resources.MessagesMessages;
046: import com.sun.xml.ws.transport.tcp.util.ChannelContext;
047: import com.sun.xml.ws.transport.tcp.util.ConnectionSession;
048: import com.sun.xml.ws.transport.tcp.util.TCPConstants;
049: import com.sun.xml.ws.transport.tcp.util.WSTCPException;
050: import java.io.InputStream;
051: import java.util.logging.Level;
052: import java.util.logging.Logger;
053: import javax.xml.ws.WebServiceException;
054:
055: /**
056: * @author Alexey Stashok
057: */
058: public final class ServiceChannelTransportPipe extends TCPTransportPipe {
059: private static final Logger logger = Logger
060: .getLogger(com.sun.xml.ws.transport.tcp.util.TCPConstants.LoggingDomain
061: + ".client");
062:
063: public ServiceChannelTransportPipe(@NotNull
064: final ClientPipeAssemblerContext context) {
065: super (context);
066: }
067:
068: private ServiceChannelTransportPipe(
069: final ServiceChannelTransportPipe that,
070: final PipeCloner cloner) {
071: super (that, cloner);
072: }
073:
074: public Packet process(final Packet packet) {
075: if (logger.isLoggable(Level.FINE)) {
076: logger
077: .log(
078: Level.FINE,
079: MessagesMessages
080: .WSTCP_1001_TCP_SERVICE_TP_PROCESS_ENTER(packet.endpointAddress));
081: }
082: ChannelContext channelContext = null;
083: final WSConnectionManager wsConnectionManager = WSConnectionManager
084: .getInstance();
085:
086: try {
087: final ContentType ct = defaultCodec
088: .getStaticContentType(packet);
089:
090: channelContext = clientTransport.getConnectionContext();
091: if (channelContext != null) {
092: if (logger.isLoggable(Level.FINE)) {
093: logger
094: .log(
095: Level.FINE,
096: MessagesMessages
097: .WSTCP_1002_TCP_SERVICE_TP_PROCESS_TRANSPORT_REUSE());
098: }
099: wsConnectionManager.lockConnection(channelContext
100: .getConnectionSession());
101: } else {
102: // Initiate new connection session
103: if (logger.isLoggable(Level.FINE)) {
104: logger
105: .log(
106: Level.FINE,
107: MessagesMessages
108: .WSTCP_1003_TCP_SERVICE_TP_PROCESS_TRANSPORT_CREATE());
109: }
110: final ConnectionSession connectionSession = (ConnectionSession) packet.invocationProperties
111: .get(TCPConstants.TCP_SESSION);
112: channelContext = connectionSession
113: .getServiceChannelContext();
114: clientTransport.setup(channelContext);
115: }
116:
117: clientTransport.setContentType(ct.getContentType());
118: /* write transport SOAPAction header if required
119: * in HTTP this param is sent as HTTP header, in SOAP/TCP
120: * it is part of content-type (similar to SOAP 1.2) */
121: writeTransportSOAPActionHeaderIfRequired(channelContext,
122: ct, packet);
123:
124: if (logger.isLoggable(Level.FINE)) {
125: logger.log(Level.FINE, MessagesMessages
126: .WSTCP_1004_TCP_SERVICE_TP_PROCESS_ENCODE(ct
127: .getContentType()));
128: }
129: defaultCodec.encode(packet, clientTransport
130: .openOutputStream());
131:
132: if (logger.isLoggable(Level.FINE)) {
133: logger.log(Level.FINE, MessagesMessages
134: .WSTCP_1005_TCP_SERVICE_TP_PROCESS_SEND());
135: }
136: clientTransport.send();
137:
138: if (logger.isLoggable(Level.FINE)) {
139: logger
140: .log(
141: Level.FINE,
142: MessagesMessages
143: .WSTCP_1006_TCP_SERVICE_TP_PROCESS_OPEN_PREPARE_READING());
144: }
145: final InputStream replyInputStream = clientTransport
146: .openInputStream();
147:
148: if (logger.isLoggable(Level.FINE)) {
149: logger
150: .log(
151: Level.FINE,
152: MessagesMessages
153: .WSTCP_1007_TCP_SERVICE_TP_PROCESS_OPEN_PROCESS_READING(
154: clientTransport
155: .getStatus(),
156: clientTransport
157: .getContentType()));
158: }
159: if (clientTransport.getStatus() != TCPConstants.ERROR) {
160: final String contentTypeStr = clientTransport
161: .getContentType();
162:
163: final Packet reply = packet.createClientResponse(null);
164: defaultCodec.decode(replyInputStream, contentTypeStr,
165: reply);
166:
167: reply.addSatellite(clientTransport);
168: return reply;
169: } else {
170: logger
171: .log(
172: Level.SEVERE,
173: MessagesMessages
174: .WSTCP_0016_ERROR_WS_EXECUTION_ON_SERVER(clientTransport
175: .getError()));
176: throw new WSTCPException(clientTransport.getError());
177: }
178: } catch (WebServiceException wex) {
179: abortSession(channelContext);
180: throw wex;
181: } catch (Exception ex) {
182: abortSession(channelContext);
183: clientTransport.setup(null);
184:
185: logger.log(Level.SEVERE, MessagesMessages
186: .WSTCP_0017_ERROR_WS_EXECUTION_ON_CLIENT(), ex);
187: throw new WebServiceException(MessagesMessages
188: .WSTCP_0017_ERROR_WS_EXECUTION_ON_CLIENT(), ex);
189: }
190: }
191:
192: public Pipe copy(final PipeCloner cloner) {
193: return new ServiceChannelTransportPipe(this, cloner);
194: }
195:
196: }
|