01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.transport.nhttp;
20:
21: import org.apache.http.impl.DefaultHttpRequestFactory;
22: import org.apache.http.impl.nio.DefaultNHttpServerConnection;
23: import org.apache.http.nio.NHttpServiceHandler;
24: import org.apache.http.nio.reactor.IOEventDispatch;
25: import org.apache.http.nio.reactor.IOSession;
26: import org.apache.http.nio.util.HeapByteBufferAllocator;
27: import org.apache.http.params.HttpParams;
28:
29: public class PlainServerIOEventDispatch implements IOEventDispatch {
30:
31: private static final String NHTTP_CONN = "AXIS2.NHTTP_CONN";
32:
33: private final NHttpServiceHandler handler;
34: private final HttpParams params;
35:
36: public PlainServerIOEventDispatch(
37: final NHttpServiceHandler handler, final HttpParams params) {
38: super ();
39: if (handler == null) {
40: throw new IllegalArgumentException(
41: "HTTP service handler may not be null");
42: }
43: if (params == null) {
44: throw new IllegalArgumentException(
45: "HTTP parameters may not be null");
46: }
47: // Decorate service handler with logging capabilities
48: this .handler = new LoggingNHttpServiceHandler(handler);
49: this .params = params;
50: }
51:
52: public void connected(final IOSession session) {
53: // Decorate I/O session with logging capabilities
54: LoggingNHttpServerConnection conn = new LoggingNHttpServerConnection(
55: new LoggingIOSession(session),
56: new DefaultHttpRequestFactory(),
57: new HeapByteBufferAllocator(), this .params);
58: session.setAttribute(NHTTP_CONN, conn);
59: this .handler.connected(conn);
60: }
61:
62: public void disconnected(final IOSession session) {
63: DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session
64: .getAttribute(NHTTP_CONN);
65: this .handler.closed(conn);
66: }
67:
68: public void inputReady(final IOSession session) {
69: DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session
70: .getAttribute(NHTTP_CONN);
71: conn.consumeInput(this .handler);
72: }
73:
74: public void outputReady(final IOSession session) {
75: DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session
76: .getAttribute(NHTTP_CONN);
77: conn.produceOutput(this .handler);
78: }
79:
80: public void timeout(final IOSession session) {
81: DefaultNHttpServerConnection conn = (DefaultNHttpServerConnection) session
82: .getAttribute(NHTTP_CONN);
83: this.handler.timeout(conn);
84: }
85:
86: }
|