001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: *
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * @author Mikhail A. Markov
021: * @version $Revision: 1.1.2.2 $
022: */package org.apache.harmony.rmi.transport.proxy;
023:
024: import java.io.DataOutputStream;
025: import java.io.IOException;
026: import java.net.Socket;
027: import java.rmi.ConnectIOException;
028: import java.rmi.RemoteException;
029:
030: import org.apache.harmony.rmi.client.ClientConnection;
031: import org.apache.harmony.rmi.common.RMILog;
032: import org.apache.harmony.rmi.internal.nls.Messages;
033: import org.apache.harmony.rmi.transport.Endpoint;
034:
035: /**
036: * HTTP proxy connection.
037: *
038: * @author Mikhail A. Markov
039: * @version $Revision: 1.1.2.2 $
040: */
041: public class HttpConnection extends ClientConnection implements
042: ProxyConstants {
043:
044: /**
045: * @see ClientConnection(Socket, Endpoint)
046: */
047: public HttpConnection(Socket s, Endpoint ep) throws RemoteException {
048: super (s, ep);
049: }
050:
051: /**
052: * Acknowledge protocol with server side.
053: *
054: * @return acknowledged protocol number
055: *
056: * @throws RemoteException if any I/O exception occurred during protocol
057: * acknowledgement
058: */
059: protected int serverProtocolAck() throws RemoteException {
060: try {
061: DataOutputStream dout = new DataOutputStream(out);
062:
063: // write RMI header and protocol version
064: writeHeader(dout);
065:
066: // write protocol type
067: dout.writeByte(SINGLEOP_PROTOCOL);
068: dout.flush();
069:
070: if (proxyTransportLog.isLoggable(RMILog.VERBOSE)) {
071: // rmi.log.130=Using singleop RMI protocol
072: proxyTransportLog.log(RMILog.VERBOSE, Messages
073: .getString("rmi.log.130")); //$NON-NLS-1$
074: }
075: dout.flush();
076: } catch (RemoteException re) {
077: close();
078: throw re;
079: } catch (IOException ioe) {
080: close();
081: // rmi.8E=Unable to acknowledge protocol with server
082: throw new ConnectIOException(
083: Messages.getString("rmi.8E"), ioe); //$NON-NLS-1$
084: }
085:
086: // protocol is agreed
087: return SINGLEOP_PROTOCOL;
088: }
089:
090: /**
091: * @see ClientConnection.done()
092: */
093: public void done() {
094: close();
095: }
096:
097: /**
098: * Closes output stream and read protocol ack data.
099: */
100: public void releaseOutputStream() throws IOException {
101: out.close();
102: }
103:
104: /**
105: * Always throws error because this connection is not reusable.
106: */
107: public boolean reuse() {
108: // rmi.8F={0} is not reusable.
109: throw new Error(Messages.getString("rmi.8F", toString())); //$NON-NLS-1$
110: }
111:
112: /**
113: * @see ClientConnection.isAvailable()
114: */
115: public boolean isAvailable() {
116: return false;
117: }
118:
119: /**
120: * Returns false because this connection could not be reused.
121: *
122: * @see ClientConnection.isReusable()
123: */
124: public boolean isReusable() {
125: return false;
126: }
127:
128: /**
129: * Always throws error because this connection is not reusable.
130: */
131: public long getExpiration() {
132: // rmi.8F={0} is not reusable.
133: throw new Error(Messages.getString("rmi.8F", toString())); //$NON-NLS-1$
134: }
135: }
|