001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.ejb.burlap;
030:
031: import com.caucho.burlap.io.BurlapInput;
032: import com.caucho.burlap.io.BurlapOutput;
033: import com.caucho.hessian.io.HessianRemoteResolver;
034: import com.caucho.util.CharBuffer;
035: import com.caucho.vfs.ReadStream;
036:
037: import java.io.OutputStream;
038:
039: public class BurlapWriter extends BurlapOutput {
040: private ReadStream _is;
041: private HessianRemoteResolver _resolver;
042:
043: /**
044: * Creates a new Burlap output stream, initialized with an
045: * underlying output stream.
046: *
047: * @param os the underlying output stream.
048: */
049: public BurlapWriter(ReadStream is, OutputStream os) {
050: super (os);
051:
052: _is = is;
053: }
054:
055: /**
056: * Creates a new Burlap output stream, initialized with an
057: * underlying output stream.
058: *
059: * @param os the underlying output stream.
060: */
061: public BurlapWriter(OutputStream os) {
062: super (os);
063: }
064:
065: /**
066: * Creates an uninitialized Burlap output stream.
067: */
068: public BurlapWriter() {
069: }
070:
071: /**
072: * Initializes the output
073: */
074: public void init(OutputStream os) {
075: _serializerFactory = new BurlapSerializerFactory();
076:
077: super .init(os);
078: }
079:
080: public void setRemoteResolver(HessianRemoteResolver resolver) {
081: _resolver = resolver;
082: }
083:
084: public BurlapInput doCall() throws Throwable {
085: completeCall();
086:
087: String status = (String) _is.getAttribute("status");
088:
089: if (!"200".equals(status)) {
090: CharBuffer cb = new CharBuffer();
091:
092: int ch;
093: while ((ch = _is.readChar()) >= 0)
094: cb.append((char) ch);
095:
096: throw new BurlapProtocolException("exception: " + cb);
097: }
098:
099: BurlapInput in = new BurlapReader();
100: in.setSerializerFactory(_serializerFactory);
101: in.setRemoteResolver(_resolver);
102: in.init(_is);
103:
104: in.startReply();
105:
106: return in;
107: }
108:
109: public void close() {
110: try {
111: os.close();
112: _is.close();
113: } catch (Exception e) {
114: }
115: }
116: }
|