2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 package org.apache.catalina.connector;
21 import java.io.IOException;
23 import javax.servlet.ServletException;
24 import javax.servlet.http.HttpServletRequest;
25 import javax.servlet.http.HttpServletResponse;
27 import org.apache.catalina.comet.CometEvent;
28 import org.apache.tomcat.util.res.StringManager;
30 public class CometEventImpl implements CometEvent {
34 * The string manager for this package.
36 protected static final StringManager sm =
37 StringManager.getManager(Constants.Package);
40 public CometEventImpl(Request request, Response response) {
41 this.request = request;
42 this.response = response;
46 // ----------------------------------------------------- Instance Variables
52 protected Request request = null;
56 * Associated response.
58 protected Response response = null;
64 protected EventType eventType = EventType.BEGIN;
70 protected EventSubType eventSubType = null;
73 // --------------------------------------------------------- Public Methods
83 public void setEventType(EventType eventType) {
84 this.eventType = eventType;
87 public void setEventSubType(EventSubType eventSubType) {
88 this.eventSubType = eventSubType;
91 public void close() throws IOException {
92 if (request == null) {
93 throw new IllegalStateException(sm.getString("cometEvent.nullRequest"));
95 boolean iscomet = request.isComet();
96 request.setComet(false);
97 response.finishResponse();
98 if (iscomet) request.cometClose();
101 public EventSubType getEventSubType() {
105 public EventType getEventType() {
109 public HttpServletRequest getHttpServletRequest() {
110 return request.getRequest();
113 public HttpServletResponse getHttpServletResponse() {
114 return response.getResponse();
117 public void setTimeout(int timeout) throws IOException, ServletException,
118 UnsupportedOperationException {
119 if (request.getAttribute("org.apache.tomcat.comet.timeout.support") == Boolean.TRUE) {
120 request.setAttribute("org.apache.tomcat.comet.timeout", new Integer(timeout));
121 if (request.isComet()) request.setCometTimeout(timeout);
123 throw new UnsupportedOperationException();
128 public String toString() {
129 StringBuilder buf = new StringBuilder();
130 buf.append(super.toString());
131 buf.append("[EventType:");
132 buf.append(eventType);
133 buf.append(", EventSubType:");
134 buf.append(eventSubType);
136 return buf.toString();