~james-page/ubuntu/natty/tomcat6/fix-662588

« back to all changes in this revision

Viewing changes to java/org/apache/coyote/ajp/AjpAprProcessor.java

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Iulian Udrea
  • Date: 2009-06-09 12:35:19 UTC
  • mfrom: (1.2.1 upstream) (2.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090609123519-7owjbso5ttnka6ur
Tags: 6.0.20-1ubuntu1
[ Iulian Udrea ]
* Merge from debian unstable (LP: #385262), remaining changes:
  - debian/control, debian/rules: Use default-jdk to build
  - debian/control: Run using default-jre-headless by default

Show diffs side-by-side

added added

removed removed

Lines of Context:
86
86
        response.setOutputBuffer(new SocketOutputBuffer());
87
87
        request.setResponse(response);
88
88
 
 
89
        this.packetSize = packetSize;
89
90
        requestHeaderMessage = new AjpMessage(packetSize);
90
91
        responseHeaderMessage = new AjpMessage(packetSize);
91
92
        bodyMessage = new AjpMessage(packetSize);
92
 
        
 
93
 
 
94
        // Set the get body message buffer
 
95
        AjpMessage getBodyMessage = new AjpMessage(16);
 
96
        getBodyMessage.reset();
 
97
        getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
 
98
        // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
 
99
        getBodyMessage.appendInt(Constants.MAX_READ_SIZE + packetSize - Constants.MAX_PACKET_SIZE);
 
100
        getBodyMessage.end();
 
101
        getBodyMessageBuffer =
 
102
            ByteBuffer.allocateDirect(getBodyMessage.getLen());
 
103
        getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0,
 
104
                                 getBodyMessage.getLen());
 
105
 
93
106
        // Allocate input and output buffers
94
107
        inputBuffer = ByteBuffer.allocateDirect(packetSize * 2);
95
108
        inputBuffer.limit(0);
126
139
 
127
140
 
128
141
    /**
 
142
     * The socket timeout used when reading the first block of the request
 
143
     * header.
 
144
     */
 
145
    protected int packetSize;
 
146
 
 
147
    /**
129
148
     * Header message. Note that this header is merely the one used during the
130
149
     * processing of the first message of a "request", so it might not be a request
131
150
     * header. It will stay unchanged during the processing of the whole request.
238
257
    /**
239
258
     * Direct buffer used for sending right away a get body message.
240
259
     */
241
 
    protected static final ByteBuffer getBodyMessageBuffer;
 
260
    protected final ByteBuffer getBodyMessageBuffer;
242
261
 
243
262
 
244
263
    /**
263
282
 
264
283
    static {
265
284
 
266
 
        // Set the get body message buffer
267
 
        AjpMessage getBodyMessage = new AjpMessage(16);
268
 
        getBodyMessage.reset();
269
 
        getBodyMessage.appendByte(Constants.JK_AJP13_GET_BODY_CHUNK);
270
 
        getBodyMessage.appendInt(Constants.MAX_READ_SIZE);
271
 
        getBodyMessage.end();
272
 
        getBodyMessageBuffer =
273
 
            ByteBuffer.allocateDirect(getBodyMessage.getLen());
274
 
        getBodyMessageBuffer.put(getBodyMessage.getBuffer(), 0,
275
 
                getBodyMessage.getLen());
276
 
 
277
285
        // Set the read body message buffer
278
286
        AjpMessage pongMessage = new AjpMessage(16);
279
287
        pongMessage.reset();
706
714
                String n = tmpMB.toString();
707
715
                requestHeaderMessage.getBytes(tmpMB);
708
716
                String v = tmpMB.toString();
709
 
                request.setAttribute(n, v);
 
717
                /*
 
718
                 * AJP13 misses to forward the remotePort.
 
719
                 * Allow the AJP connector to add this info via
 
720
                 * a private request attribute.
 
721
                 * We will accept the forwarded data as the remote port,
 
722
                 * and remove it from the public list of request attributes.
 
723
                 */
 
724
                if(n.equals(Constants.SC_A_REQ_REMOTE_PORT)) {
 
725
                    try {
 
726
                        request.setRemotePort(Integer.parseInt(v));
 
727
                    } catch (NumberFormatException nfe) {
 
728
                    }
 
729
                } else {
 
730
                    request.setAttribute(n, v );
 
731
                }
710
732
                break;
711
733
 
712
734
            case Constants.SC_A_CONTEXT :
839
861
 
840
862
        if (valueMB == null || (valueMB != null && valueMB.isNull()) ) {
841
863
            // HTTP/1.0
842
 
            // Default is what the socket tells us. Overriden if a host is
843
 
            // found/parsed
844
 
            request.setServerPort(endpoint.getPort());
 
864
            request.setServerPort(request.getLocalPort());
 
865
            try {
 
866
                request.serverName().duplicate(request.localName());
 
867
            } catch (IOException e) {
 
868
                response.setStatus(400);
 
869
                error = true;
 
870
            }
845
871
            return;
846
872
        }
847
873
 
926
952
        } else {
927
953
            message = message.replace('\n', ' ').replace('\r', ' ');
928
954
        }
 
955
        if (message == null) {
 
956
            // mod_jk + httpd 2.x fails with a null status message - bug 45026
 
957
            message = Integer.toString(response.getStatus());
 
958
        }
929
959
        tmpMB.setString(message);
930
960
        responseHeaderMessage.appendBytes(tmpMB);
931
961
 
1258
1288
 
1259
1289
            int len = chunk.getLength();
1260
1290
            // 4 - hardcoded, byte[] marshalling overhead
1261
 
            int chunkSize = Constants.MAX_SEND_SIZE;
 
1291
            // Adjust allowed size if packetSize != default (Constants.MAX_PACKET_SIZE)
 
1292
            int chunkSize = Constants.MAX_SEND_SIZE + packetSize - Constants.MAX_PACKET_SIZE;
1262
1293
            int off = 0;
1263
1294
            while (len > 0) {
1264
1295
                int thisTime = len;