RequestMessage_1_2.java revision 608:7e06bf1dcb09
1132718Skan/*
2169689Skan * Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved.
3132718Skan * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4132718Skan *
5132718Skan * This code is free software; you can redistribute it and/or modify it
6132718Skan * under the terms of the GNU General Public License version 2 only, as
7132718Skan * published by the Free Software Foundation.  Oracle designates this
8132718Skan * particular file as subject to the "Classpath" exception as provided
9132718Skan * by Oracle in the LICENSE file that accompanied this code.
10132718Skan *
11132718Skan * This code is distributed in the hope that it will be useful, but WITHOUT
12132718Skan * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13132718Skan * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14132718Skan * version 2 for more details (a copy is included in the LICENSE file that
15132718Skan * accompanied this code).
16132718Skan *
17132718Skan * You should have received a copy of the GNU General Public License version
18132718Skan * 2 along with this work; if not, write to the Free Software Foundation,
19169689Skan * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20169689Skan *
21132718Skan * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22132718Skan * or visit www.oracle.com if you need additional information or have any
23132718Skan * questions.
24132718Skan */
25132718Skan
26132718Skanpackage com.sun.corba.se.impl.protocol.giopmsgheaders;
27132718Skan
28132718Skanimport org.omg.CORBA.Principal;
29132718Skanimport com.sun.corba.se.spi.servicecontext.ServiceContexts;
30132718Skanimport com.sun.corba.se.spi.ior.iiop.GIOPVersion;
31132718Skanimport com.sun.corba.se.spi.orb.ORB;
32132718Skanimport com.sun.corba.se.spi.ior.ObjectKey;
33132718Skanimport com.sun.corba.se.impl.encoding.CDRInputStream;
34169689Skanimport com.sun.corba.se.impl.encoding.CDROutputStream;
35132718Skanimport com.sun.corba.se.impl.orbutil.ORBConstants;
36132718Skanimport com.sun.corba.se.impl.encoding.CDRInputStream_1_2;
37169689Skanimport com.sun.corba.se.impl.encoding.CDROutputStream_1_2;
38132718Skan
39132718Skanimport com.sun.corba.se.spi.logging.CORBALogDomains ;
40132718Skanimport com.sun.corba.se.impl.logging.ORBUtilSystemException ;
41132718Skan
42132718Skan/**
43132718Skan * This implements the GIOP 1.2 Request header.
44132718Skan *
45169689Skan * @author Ram Jeyaraman 05/14/2000
46132718Skan */
47132718Skan
48132718Skanpublic final class RequestMessage_1_2 extends Message_1_2
49132718Skan        implements RequestMessage {
50132718Skan
51132718Skan    // Instance variables
52132718Skan
53132718Skan    private ORB orb = null;
54132718Skan    private ORBUtilSystemException wrapper = null ;
55132718Skan    private byte response_flags = (byte) 0;
56132718Skan    private byte reserved[] = null;
57132718Skan    private TargetAddress target = null;
58132718Skan    private String operation = null;
59132718Skan    private ServiceContexts service_contexts = null;
60132718Skan    private ObjectKey objectKey = null;
61132718Skan
62132718Skan    // Constructors
63132718Skan
64132718Skan    RequestMessage_1_2(ORB orb) {
65132718Skan        this.orb = orb;
66132718Skan        this.wrapper = ORBUtilSystemException.get( orb,
67132718Skan            CORBALogDomains.RPC_PROTOCOL ) ;
68132718Skan    }
69132718Skan
70132718Skan    RequestMessage_1_2(ORB orb, int _request_id, byte _response_flags,
71132718Skan            byte[] _reserved, TargetAddress _target,
72132718Skan            String _operation, ServiceContexts _service_contexts) {
73132718Skan        super(Message.GIOPBigMagic, GIOPVersion.V1_2, FLAG_NO_FRAG_BIG_ENDIAN,
74132718Skan            Message.GIOPRequest, 0);
75132718Skan        this.orb = orb;
76132718Skan        this.wrapper = ORBUtilSystemException.get( orb,
77132718Skan            CORBALogDomains.RPC_PROTOCOL ) ;
78132718Skan        request_id = _request_id;
79132718Skan        response_flags = _response_flags;
80132718Skan        reserved = _reserved;
81132718Skan        target = _target;
82132718Skan        operation = _operation;
83132718Skan        service_contexts = _service_contexts;
84132718Skan    }
85132718Skan
86132718Skan    // Accessor methods (RequestMessage interface)
87132718Skan
88132718Skan    public int getRequestId() {
89132718Skan        return this.request_id;
90132718Skan    }
91132718Skan
92132718Skan    public boolean isResponseExpected() {
93169689Skan        /*
94132718Skan        case 1: LSBit[1] == 1
95132718Skan            not a oneway call (DII flag INV_NO_RESPONSE is false)  // Ox03
96132718Skan            LSBit[0] must be 1.
97132718Skan        case 2: LSBit[1] == 0
98132718Skan            if (LSB[0] == 0) // Ox00
99169689Skan                oneway call
100132718Skan            else if (LSB[0] == 1) // 0x01
101132718Skan                oneway call; but server may provide
102132718Skan                a location forward response or system exception response.
103132718Skan        */
104132718Skan
105132718Skan        if ( (this.response_flags & RESPONSE_EXPECTED_BIT) == RESPONSE_EXPECTED_BIT ) {
106132718Skan            return true;
107132718Skan        }
108132718Skan
109132718Skan        return false;
110132718Skan    }
111132718Skan
112132718Skan    public byte[] getReserved() {
113132718Skan        return this.reserved;
114132718Skan    }
115132718Skan
116132718Skan    public ObjectKey getObjectKey() {
117132718Skan        if (this.objectKey == null) {
118132718Skan            // this will raise a MARSHAL exception upon errors.
119132718Skan            this.objectKey = MessageBase.extractObjectKey(target, orb);
120132718Skan        }
121132718Skan
122132718Skan        return this.objectKey;
123132718Skan    }
124132718Skan
125132718Skan    public String getOperation() {
126132718Skan        return this.operation;
127132718Skan    }
128132718Skan
129132718Skan    public Principal getPrincipal() {
130132718Skan        // REVISIT Should we throw an exception or return null ?
131132718Skan        return null;
132132718Skan    }
133132718Skan
134132718Skan    public ServiceContexts getServiceContexts() {
135132718Skan        return this.service_contexts;
136132718Skan    }
137132718Skan
138132718Skan    // IO methods
139132718Skan
140132718Skan    public void read(org.omg.CORBA.portable.InputStream istream) {
141169689Skan        super.read(istream);
142132718Skan        this.request_id = istream.read_ulong();
143132718Skan        this.response_flags = istream.read_octet();
144132718Skan        this.reserved = new byte[3];
145132718Skan        for (int _o0 = 0;_o0 < (3); ++_o0) {
146132718Skan            this.reserved[_o0] = istream.read_octet();
147132718Skan        }
148132718Skan        this.target = TargetAddressHelper.read(istream);
149132718Skan        getObjectKey(); // this does AddressingDisposition check
150132718Skan        this.operation = istream.read_string();
151132718Skan        this.service_contexts
152132718Skan            = new ServiceContexts((org.omg.CORBA_2_3.portable.InputStream) istream);
153132718Skan
154132718Skan        // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
155132718Skan        // aligned on an 8 octet boundary.
156132718Skan        // Ensures that the first read operation called from the stub code,
157132718Skan        // during body deconstruction, would skip the header padding, that was
158132718Skan        // inserted to ensure that the body was aligned on an 8-octet boundary.
159132718Skan        ((CDRInputStream)istream).setHeaderPadding(true);
160132718Skan
161132718Skan    }
162132718Skan
163132718Skan    public void write(org.omg.CORBA.portable.OutputStream ostream) {
164132718Skan        super.write(ostream);
165132718Skan        ostream.write_ulong(this.request_id);
166132718Skan        ostream.write_octet(this.response_flags);
167132718Skan        nullCheck(this.reserved);
168132718Skan        if (this.reserved.length != (3)) {
169132718Skan            throw wrapper.badReservedLength(
170132718Skan                org.omg.CORBA.CompletionStatus.COMPLETED_MAYBE);
171132718Skan        }
172132718Skan        for (int _i0 = 0;_i0 < (3); ++_i0) {
173132718Skan            ostream.write_octet(this.reserved[_i0]);
174132718Skan        }
175132718Skan        nullCheck(this.target);
176132718Skan        TargetAddressHelper.write(ostream, this.target);
177132718Skan        ostream.write_string(this.operation);
178132718Skan        if (this.service_contexts != null) {
179132718Skan                service_contexts.write(
180132718Skan                (org.omg.CORBA_2_3.portable.OutputStream) ostream,
181132718Skan                GIOPVersion.V1_2);
182132718Skan            } else {
183132718Skan                ServiceContexts.writeNullServiceContext(
184132718Skan                (org.omg.CORBA_2_3.portable.OutputStream) ostream);
185132718Skan        }
186132718Skan
187132718Skan        // CORBA formal 00-11-0 15.4.2.2 GIOP 1.2 body must be
188132718Skan        // aligned on an 8 octet boundary.
189132718Skan        // Ensures that the first write operation called from the stub code,
190132718Skan        // during body construction, would insert a header padding, such that
191132718Skan        // the body is aligned on an 8-octet boundary.
192132718Skan        ((CDROutputStream)ostream).setHeaderPadding(true);
193132718Skan    }
194132718Skan
195132718Skan    public void callback(MessageHandler handler)
196132718Skan        throws java.io.IOException
197132718Skan    {
198132718Skan        handler.handleInput(this);
199132718Skan    }
200132718Skan} // class RequestMessage_1_2
201132718Skan