├── modules └── httpcore-nio │ └── src │ ├── test │ ├── resources │ │ └── test.keystore │ └── java │ │ └── org │ │ └── apache │ │ └── http │ │ ├── OoopsieRuntimeException.java │ │ ├── nio │ │ ├── testserver │ │ │ ├── LoggingClientConnectionFactory.java │ │ │ ├── LoggingServerConnectionFactory.java │ │ │ ├── SimpleIOReactorExceptionHandler.java │ │ │ ├── LoggingSSLClientConnectionFactory.java │ │ │ └── LoggingSSLServerConnectionFactory.java │ │ ├── integration │ │ │ ├── RndTestPatternGenerator.java │ │ │ └── TestHttpsAsyncHandlers.java │ │ └── util │ │ │ ├── ContentDecoderMock.java │ │ │ └── ContentEncoderMock.java │ │ ├── impl │ │ └── nio │ │ │ ├── reactor │ │ │ ├── ExceptionEventTest.java │ │ │ └── TestDefaultIOReactorsSSL.java │ │ │ ├── codecs │ │ │ └── CodecTestUtils.java │ │ │ └── TestContentChannel.java │ │ └── ByteChannelMock.java │ └── main │ ├── resources │ └── org │ │ └── apache │ │ └── http │ │ └── nio │ │ └── version.properties │ ├── java │ └── org │ │ └── apache │ │ └── http │ │ ├── nio │ │ ├── params │ │ │ ├── package-info.java │ │ │ └── NIOReactorPNames.java │ │ ├── util │ │ │ ├── package-info.java │ │ │ ├── BufferInfo.java │ │ │ ├── ByteBufferAllocator.java │ │ │ ├── HeapByteBufferAllocator.java │ │ │ └── DirectByteBufferAllocator.java │ │ ├── reactor │ │ │ ├── ssl │ │ │ │ ├── package-info.java │ │ │ │ ├── SSLMode.java │ │ │ │ └── SSLSetupHandler.java │ │ │ ├── package-info.java │ │ │ ├── SocketAccessor.java │ │ │ ├── EventMask.java │ │ │ ├── IOReactorStatus.java │ │ │ ├── IOReactorException.java │ │ │ ├── SessionBufferStatus.java │ │ │ ├── SessionRequestCallback.java │ │ │ ├── IOReactorExceptionHandler.java │ │ │ └── ListenerEndpoint.java │ │ ├── package-info.java │ │ ├── pool │ │ │ ├── package-info.java │ │ │ ├── SocketAddressResolver.java │ │ │ └── NIOConnFactory.java │ │ ├── protocol │ │ │ ├── MessageState.java │ │ │ ├── package-info.java │ │ │ ├── HttpAsyncRequestHandlerMapper.java │ │ │ ├── HttpAsyncRequestHandlerResolver.java │ │ │ ├── HttpAsyncExpectationVerifier.java │ │ │ ├── NullRequestHandler.java │ │ │ ├── NullRequestConsumer.java │ │ │ └── BasicAsyncRequestHandler.java │ │ ├── entity │ │ │ ├── package-info.java │ │ │ ├── ConsumingNHttpEntity.java │ │ │ ├── ContentOutputStream.java │ │ │ ├── ProducingNHttpEntity.java │ │ │ └── ContentBufferEntity.java │ │ ├── NHttpConnectionFactory.java │ │ ├── NHttpMessageWriterFactory.java │ │ ├── NHttpMessageParserFactory.java │ │ ├── NHttpClientIOTarget.java │ │ ├── NHttpMessageWriter.java │ │ ├── NHttpServerIOTarget.java │ │ ├── ContentDecoderChannel.java │ │ ├── ContentEncoderChannel.java │ │ ├── FileContentEncoder.java │ │ ├── ContentDecoder.java │ │ ├── ContentEncoder.java │ │ ├── IOControl.java │ │ ├── FileContentDecoder.java │ │ ├── NHttpMessageParser.java │ │ ├── NHttpClientConnection.java │ │ └── NHttpServerConnection.java │ │ └── impl │ │ └── nio │ │ ├── package-info.java │ │ ├── reactor │ │ ├── package-info.java │ │ ├── SessionClosedCallback.java │ │ ├── InterestOpsCallback.java │ │ ├── ListenerEndpointClosedCallback.java │ │ ├── SessionRequestHandle.java │ │ ├── ExceptionEvent.java │ │ └── InterestOpEntry.java │ │ ├── pool │ │ ├── package-info.java │ │ └── BasicNIOPoolEntry.java │ │ ├── codecs │ │ ├── package-info.java │ │ ├── DefaultHttpRequestWriterFactory.java │ │ └── DefaultHttpResponseWriterFactory.java │ │ ├── SessionHttpContext.java │ │ └── SSLContextUtils.java │ └── java-deprecated │ └── org │ └── apache │ └── http │ ├── impl │ └── nio │ │ ├── reactor │ │ ├── SSLMode.java │ │ ├── SSLSetupHandlerAdaptor.java │ │ └── SSLIOSessionHandlerAdaptor.java │ │ └── codecs │ │ ├── HttpRequestWriter.java │ │ └── HttpResponseWriter.java │ └── nio │ ├── params │ └── NIOReactorParamBean.java │ ├── protocol │ ├── NHttpRequestHandlerResolver.java │ ├── SimpleNHttpRequestHandler.java │ ├── NHttpResponseTrigger.java │ ├── EventListener.java │ └── HttpAsyncRequestExecutionHandler.java │ └── entity │ ├── ContentListener.java │ └── SkipContentListener.java ├── .github ├── CODEOWNERS └── workflows │ ├── push_ubuntu_build.yml │ └── pull_request_ubuntu_build.yml ├── README.md ├── .gitignore ├── issue_template.md └── pull_request_template.md /modules/httpcore-nio/src/test/resources/test.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wso2/wso2-httpcore-nio/HEAD/modules/httpcore-nio/src/test/resources/test.keystore -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Lines starting with '#' are comments. 2 | # Each line is a file pattern followed by one or more owners. 3 | 4 | # See: https://help.github.com/articles/about-codeowners/ 5 | 6 | # These owners will be the default owners for everything in the repo. 7 | * @arunans23 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wso2-httpcore-nio 2 | 3 | ##Jenkins Build Status 4 | 5 | | Branch | Build Status | 6 | | :------------ |:------------- 7 | | wso2-httpcore-nio master | [![Build Status](https://wso2.org/jenkins/job/wso2-httpcore-nio/badge/icon)](https://wso2.org/jenkins/job/wso2-httpcore-nio) 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.class 2 | 3 | # Mobile Tools for Java (J2ME) 4 | .mtj.tmp/ 5 | 6 | # Package Files # 7 | *.jar 8 | *.war 9 | *.ear 10 | 11 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 12 | hs_err_pid* 13 | 14 | # ignore Intellij-IDEA files 15 | *.iml 16 | *.ipr 17 | *.iws 18 | *.classpath 19 | *.settings 20 | *.project 21 | *.idea 22 | 23 | 24 | # ignore logs 25 | *.log 26 | 27 | # ignore target directories 28 | target/ 29 | -------------------------------------------------------------------------------- /.github/workflows/push_ubuntu_build.yml: -------------------------------------------------------------------------------- 1 | name: CI - Push request - Ubuntu 2 | 3 | on: 4 | push: 5 | branches: [ "master" ] 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Set up JDK 11 15 | uses: actions/setup-java@v4 16 | with: 17 | java-version: '11' 18 | distribution: 'temurin' 19 | cache: maven 20 | - name: Build with Maven 21 | run: mvn clean install 22 | - name: Upload test coverage to Codecov 23 | uses: codecov/codecov-action@v4.0.1 24 | with: 25 | flags: unit_tests 26 | token: ${{ secrets.CODECOV_TOKEN }} 27 | -------------------------------------------------------------------------------- /.github/workflows/pull_request_ubuntu_build.yml: -------------------------------------------------------------------------------- 1 | name: CI - Pull request - Ubuntu 2 | 3 | on: 4 | pull_request: 5 | branches: [ "master" ] 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: Set up JDK 11 15 | uses: actions/setup-java@v4 16 | with: 17 | java-version: '11' 18 | distribution: 'temurin' 19 | cache: maven 20 | - name: Build with Maven 21 | run: mvn clean install 22 | - name: Upload test coverage to Codecov 23 | uses: codecov/codecov-action@v4.0.1 24 | with: 25 | flags: unit_tests 26 | token: ${{ secrets.CODECOV_TOKEN }} 27 | -------------------------------------------------------------------------------- /issue_template.md: -------------------------------------------------------------------------------- 1 | **Description:** 2 | 3 | 4 | **Suggested Labels:** 5 | 6 | 7 | **Suggested Assignees:** 8 | 9 | 10 | **Affected Product Version:** 11 | 12 | **OS, DB, other environment details and versions:** 13 | 14 | **Steps to reproduce:** 15 | 16 | 17 | **Related Issues:** 18 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/resources/org/apache/http/nio/version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 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 | info.module = Httpcore-nio 20 | info.release = ${pom.version} 21 | info.timestamp = ${mvn.timestamp} 22 | # timestamp requires Maven 2.1 23 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/params/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Deprecated. 30 | * @deprecated (4.3). 31 | */ 32 | package org.apache.http.nio.params; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/util/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Core utility classes for asynchronous, event driven communication. 30 | */ 31 | package org.apache.http.nio.util; 32 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * TLS/SSL support for asynchronous, event driven communication. 30 | */ 31 | package org.apache.http.nio.reactor.ssl; 32 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Core HTTP component APIs and primitives for asynchronous, event 30 | * driven communication. 31 | */ 32 | package org.apache.http.nio; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/pool/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Client side connection pools APIs for asynchronous, event driven 30 | * communication. 31 | */ 32 | package org.apache.http.nio.pool; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/MessageState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.protocol; 28 | 29 | enum MessageState { 30 | 31 | READY, INIT, ACK_EXPECTED, ACK, BODY_STREAM, COMPLETED 32 | 33 | } 34 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Default implementations of HTTP connections for asynchronous, 30 | * even driven communication. 31 | */ 32 | package org.apache.http.impl.nio; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/entity/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Core HTTP entity implementations with support for 30 | * asynchronous, event driven communication. 31 | */ 32 | package org.apache.http.nio.entity; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor.ssl; 29 | 30 | /** 31 | * @since 4.2 32 | */ 33 | public enum SSLMode { 34 | 35 | CLIENT, 36 | SERVER 37 | 38 | } 39 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Default implementation of event driven network communication APIs 30 | * based on Java NIO. 31 | */ 32 | package org.apache.http.impl.nio.reactor; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Default implementations of client side connection pools 30 | * for asynchronous, even driven communication. 31 | */ 32 | package org.apache.http.impl.nio.pool; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Default implementations of message parses and writers 30 | * for asynchronous, even driven communication. 31 | */ 32 | package org.apache.http.impl.nio.codecs; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Core HTTP protocol execution framework and HTTP protocol handlers 30 | * for asynchronous, event driven communication. 31 | */ 32 | package org.apache.http.nio.protocol; 33 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/impl/nio/reactor/SSLMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | /** 31 | * @since 4.0 32 | * 33 | * @deprecated (4.2) 34 | */ 35 | @Deprecated 36 | public enum SSLMode { 37 | 38 | CLIENT, 39 | SERVER 40 | 41 | } 42 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/OoopsieRuntimeException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http; 29 | 30 | public class OoopsieRuntimeException extends RuntimeException { 31 | 32 | private static final long serialVersionUID = 662807254163212266L; 33 | 34 | public OoopsieRuntimeException() { 35 | super("Ooopsie!!!"); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import org.apache.http.nio.reactor.IOSession; 31 | 32 | /** 33 | * Factory for {@link NHttpConnection} instances. 34 | * 35 | * @since 4.2 36 | */ 37 | public interface NHttpConnectionFactory { 38 | 39 | T createConnection(IOSession session); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/util/BufferInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.util; 29 | 30 | /** 31 | * Basic buffer properties. 32 | * 33 | * @since 4.0 34 | * 35 | * @deprecated (4.1) Use {@link org.apache.http.io.BufferInfo} 36 | */ 37 | @Deprecated 38 | public interface BufferInfo { 39 | 40 | int length(); 41 | 42 | int capacity(); 43 | 44 | int available(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionClosedCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import org.apache.http.nio.reactor.IOSession; 31 | 32 | /** 33 | * Session callback interface used internally by I/O reactor implementations. 34 | * 35 | * @since 4.0 36 | */ 37 | public interface SessionClosedCallback { 38 | 39 | void sessionClosed(IOSession session); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpsCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | /** 31 | * Callback interface used internally by I/O session implementations to delegate execution 32 | * of a {@link java.nio.channels.SelectionKey#interestOps(int)} operation to the I/O reactor. 33 | * 34 | * @since 4.1 35 | */ 36 | interface InterestOpsCallback { 37 | 38 | void addInterestOps(InterestOpEntry entry); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ListenerEndpointClosedCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import org.apache.http.nio.reactor.ListenerEndpoint; 31 | 32 | /** 33 | * Listener endpoint callback interface used internally by I/O reactor 34 | * implementations. 35 | * 36 | * @since 4.0 37 | */ 38 | public interface ListenerEndpointClosedCallback { 39 | 40 | void endpointClosed(ListenerEndpoint endpoint); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageWriterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import org.apache.http.HttpMessage; 31 | import org.apache.http.nio.reactor.SessionOutputBuffer; 32 | 33 | /** 34 | * Factory for {@link NHttpMessageWriter} instances. 35 | * 36 | * @since 4.3 37 | */ 38 | public interface NHttpMessageWriterFactory { 39 | 40 | NHttpMessageWriter create(SessionOutputBuffer buffer); 41 | 42 | } 43 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | /** 29 | * Event driven network communication APIs loosely based on 30 | Doug Lea's 31 | reactor pattern. 32 |

33 | This API is not specific to HTTP communication. However, it is minimal 34 | in the sense that it defines only what is required within the scope 35 | of HTTP protocol. 36 | */ 37 | package org.apache.http.nio.reactor; 38 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SocketAccessor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | import java.net.Socket; 31 | 32 | /** 33 | * Provides access to the underlying Socket. 34 | *

35 | * Remark: this interface will be removed in the next major release. 36 | */ 37 | public interface SocketAccessor { 38 | 39 | /** 40 | * Return the underlying socket 41 | * 42 | * @return - the underlying Socket, may be null. 43 | */ 44 | Socket getSocket(); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/util/ByteBufferAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.util; 29 | 30 | import java.nio.ByteBuffer; 31 | 32 | /** 33 | * Abstract interface to allocate {@link ByteBuffer} instances. 34 | * 35 | * @since 4.0 36 | */ 37 | public interface ByteBufferAllocator { 38 | 39 | /** 40 | * Allocates {@link ByteBuffer} of the given size. 41 | * 42 | * @param size the size of the buffer. 43 | * @return byte buffer. 44 | */ 45 | ByteBuffer allocate(int size); 46 | 47 | } 48 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageParserFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import org.apache.http.HttpMessage; 31 | import org.apache.http.config.MessageConstraints; 32 | import org.apache.http.nio.reactor.SessionInputBuffer; 33 | 34 | /** 35 | * Factory for {@link NHttpMessageParser} instances. 36 | * 37 | * @since 4.3 38 | */ 39 | public interface NHttpMessageParserFactory { 40 | 41 | NHttpMessageParser create(SessionInputBuffer buffer, MessageConstraints constraints); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/pool/SocketAddressResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.pool; 29 | 30 | import java.io.IOException; 31 | import java.net.SocketAddress; 32 | 33 | /** 34 | * Strategy that resolves an abstract connection route to a local or a remote {@link SocketAddress}. 35 | * . 36 | * @since 4.3 37 | */ 38 | public interface SocketAddressResolver { 39 | 40 | SocketAddress resolveLocalAddress(T route) throws IOException; 41 | 42 | SocketAddress resolveRemoteAddress(T route) throws IOException; 43 | 44 | } 45 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/pool/NIOConnFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.pool; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.nio.reactor.IOSession; 33 | 34 | /** 35 | * Factory for poolable non-blocking connections. 36 | * 37 | * @param the route type that represents the opposite endpoint of a pooled 38 | * connection. 39 | * @param the connection type. 40 | * @since 4.2 41 | */ 42 | public interface NIOConnFactory { 43 | 44 | C create(T route, IOSession session) throws IOException; 45 | 46 | } 47 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/testserver/LoggingClientConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.testserver; 28 | 29 | import org.apache.http.impl.nio.DefaultNHttpClientConnection; 30 | import org.apache.http.nio.NHttpConnectionFactory; 31 | import org.apache.http.nio.reactor.IOSession; 32 | 33 | public class LoggingClientConnectionFactory implements NHttpConnectionFactory { 34 | 35 | public LoggingClientConnectionFactory() { 36 | super(); 37 | } 38 | 39 | public DefaultNHttpClientConnection createConnection(final IOSession session) { 40 | return new LoggingNHttpClientConnection(session); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/testserver/LoggingServerConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.testserver; 28 | 29 | import org.apache.http.impl.nio.DefaultNHttpServerConnection; 30 | import org.apache.http.nio.NHttpConnectionFactory; 31 | import org.apache.http.nio.reactor.IOSession; 32 | 33 | public class LoggingServerConnectionFactory implements NHttpConnectionFactory { 34 | 35 | public LoggingServerConnectionFactory() { 36 | super(); 37 | } 38 | 39 | public DefaultNHttpServerConnection createConnection(final IOSession session) { 40 | return new LoggingNHttpServerConnection(session); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/EventMask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | import java.nio.channels.SelectionKey; 31 | 32 | /** 33 | * Type of I/O event notifications I/O sessions can declare interest in. 34 | * 35 | * @since 4.0 36 | */ 37 | public interface EventMask { 38 | 39 | /** 40 | * Interest in data input. 41 | */ 42 | public static final int READ = SelectionKey.OP_READ; 43 | 44 | /** 45 | * Interest in data output. 46 | */ 47 | public static final int WRITE = SelectionKey.OP_WRITE; 48 | 49 | /** 50 | * Interest in data input/output. 51 | */ 52 | public static final int READ_WRITE = READ | WRITE; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/util/HeapByteBufferAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.util; 29 | 30 | import java.nio.ByteBuffer; 31 | 32 | import org.apache.http.annotation.Immutable; 33 | 34 | /** 35 | * Allocates {@link ByteBuffer} instances using 36 | * {@link ByteBuffer#allocate(int)}. 37 | * 38 | * @since 4.0 39 | */ 40 | @Immutable 41 | public class HeapByteBufferAllocator implements ByteBufferAllocator { 42 | 43 | public static final HeapByteBufferAllocator INSTANCE = new HeapByteBufferAllocator(); 44 | 45 | public HeapByteBufferAllocator() { 46 | super(); 47 | } 48 | 49 | public ByteBuffer allocate(final int size) { 50 | return ByteBuffer.allocate(size); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/testserver/SimpleIOReactorExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.testserver; 28 | 29 | import java.io.IOException; 30 | 31 | import org.apache.http.OoopsieRuntimeException; 32 | import org.apache.http.nio.reactor.IOReactorExceptionHandler; 33 | 34 | public class SimpleIOReactorExceptionHandler implements IOReactorExceptionHandler { 35 | 36 | public boolean handle(final RuntimeException ex) { 37 | if (!(ex instanceof OoopsieRuntimeException)) { 38 | ex.printStackTrace(System.out); 39 | } 40 | return false; 41 | } 42 | 43 | public boolean handle(final IOException ex) { 44 | ex.printStackTrace(System.out); 45 | return false; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/util/DirectByteBufferAllocator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.util; 29 | 30 | import java.nio.ByteBuffer; 31 | 32 | import org.apache.http.annotation.Immutable; 33 | 34 | /** 35 | * Allocates {@link ByteBuffer} instances using 36 | * {@link ByteBuffer#allocateDirect(int)}. 37 | * 38 | * @since 4.0 39 | */ 40 | @Immutable 41 | public class DirectByteBufferAllocator implements ByteBufferAllocator { 42 | 43 | public static final DirectByteBufferAllocator INSTANCE = new DirectByteBufferAllocator(); 44 | 45 | public DirectByteBufferAllocator() { 46 | super(); 47 | } 48 | 49 | public ByteBuffer allocate(final int size) { 50 | return ByteBuffer.allocateDirect(size); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOReactorStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | /** 31 | * IOReactorStatus represents an internal status of an I/O reactor. 32 | * 33 | * @since 4.0 34 | */ 35 | public enum IOReactorStatus { 36 | 37 | /** 38 | * The reactor is inactive / has not been started 39 | */ 40 | INACTIVE, 41 | 42 | /** 43 | * The reactor is active / processing I/O events. 44 | */ 45 | ACTIVE, 46 | 47 | /** 48 | * Shutdown of the reactor has been requested. 49 | */ 50 | SHUTDOWN_REQUEST, 51 | 52 | /** 53 | * The reactor is shutting down. 54 | */ 55 | SHUTTING_DOWN, 56 | 57 | /** 58 | * The reactor has shut down. 59 | */ 60 | SHUT_DOWN 61 | 62 | } 63 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOReactorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | import java.io.IOException; 31 | 32 | /** 33 | * I/O exception that can be thrown by an I/O reactor. Usually exceptions 34 | * of this type are fatal and are not recoverable. 35 | * 36 | * @since 4.0 37 | */ 38 | public class IOReactorException extends IOException { 39 | 40 | private static final long serialVersionUID = -4248110651729635749L; 41 | 42 | public IOReactorException(final String message, final Exception cause) { 43 | super(message); 44 | if (cause != null) { 45 | initCause(cause); 46 | } 47 | } 48 | 49 | public IOReactorException(final String message) { 50 | super(message); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/integration/RndTestPatternGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.integration; 29 | 30 | import java.util.Random; 31 | 32 | final class RndTestPatternGenerator { 33 | 34 | private static final Random RND = new Random(); 35 | private static final String TEST_CHARS = "0123456789ABCDEF"; 36 | 37 | public static String generateText() { 38 | final StringBuilder buffer = new StringBuilder(); 39 | for (int i = 0; i < 5; i++) { 40 | final char rndchar = TEST_CHARS.charAt(RND.nextInt(TEST_CHARS.length() - 1)); 41 | buffer.append(rndchar); 42 | } 43 | return buffer.toString(); 44 | } 45 | 46 | public static int generateCount(final int max) { 47 | return RND.nextInt(max - 1) + 1; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import org.apache.http.HttpRequest; 31 | 32 | /** 33 | * HttpAsyncRequestHandlerMapper can be used to resolve an instance 34 | * of {@link HttpAsyncRequestHandler} matching a particular {@link HttpRequest}. 35 | * Usually the resolved request handler will be used to process the request. 36 | * 37 | * @since 4.3 38 | */ 39 | public interface HttpAsyncRequestHandlerMapper { 40 | 41 | /** 42 | * Looks up a handler matching the given request. 43 | * 44 | * @param request the request 45 | * @return HTTP request handler or null if no match 46 | * is found. 47 | */ 48 | HttpAsyncRequestHandler lookup(HttpRequest request); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionBufferStatus.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.reactor; 28 | 29 | /** 30 | * SessionBufferStatus interface is intended to query the status of session 31 | * I/O buffers. 32 | * 33 | * @since 4.0 34 | */ 35 | public interface SessionBufferStatus { 36 | 37 | /** 38 | * Determines if the session input buffer contains data. 39 | * 40 | * @return true if the session input buffer contains data, 41 | * false otherwise. 42 | */ 43 | boolean hasBufferedInput(); 44 | 45 | /** 46 | * Determines if the session output buffer contains data. 47 | * 48 | * @return true if the session output buffer contains data, 49 | * false otherwise. 50 | */ 51 | boolean hasBufferedOutput(); 52 | 53 | } 54 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/SessionHttpContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio; 29 | 30 | import org.apache.http.nio.reactor.IOSession; 31 | import org.apache.http.protocol.HttpContext; 32 | 33 | class SessionHttpContext implements HttpContext { 34 | 35 | private final IOSession iosession; 36 | 37 | public SessionHttpContext(final IOSession iosession) { 38 | super(); 39 | this.iosession = iosession; 40 | } 41 | 42 | public Object getAttribute(final String id) { 43 | return this.iosession.getAttribute(id); 44 | } 45 | 46 | public Object removeAttribute(final String id) { 47 | return this.iosession.removeAttribute(id); 48 | } 49 | 50 | public void setAttribute(final String id, final Object obj) { 51 | this.iosession.setAttribute(id, obj); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/params/NIOReactorParamBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.params; 29 | 30 | import org.apache.http.params.HttpAbstractParamBean; 31 | import org.apache.http.params.HttpParams; 32 | 33 | /** 34 | * @since 4.0 35 | * 36 | * @deprecated (4.2) use {@link org.apache.http.impl.nio.reactor.IOReactorConfig} 37 | */ 38 | @Deprecated 39 | public class NIOReactorParamBean extends HttpAbstractParamBean { 40 | 41 | public NIOReactorParamBean (final HttpParams params) { 42 | super(params); 43 | } 44 | 45 | public void setContentBufferSize (final int contentBufferSize) { 46 | NIOReactorParams.setContentBufferSize(params, contentBufferSize); 47 | } 48 | 49 | public void setSelectInterval (final long selectInterval) { 50 | NIOReactorParams.setSelectInterval(params, selectInterval); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/SSLContextUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.impl.nio; 28 | 29 | import javax.net.ssl.SSLContext; 30 | import java.security.NoSuchAlgorithmException; 31 | 32 | // TODO: to be replaced by SSLContext#getDefault() after upgrade to 1.6 33 | class SSLContextUtils { 34 | 35 | static SSLContext getDefault() { 36 | SSLContext sslcontext; 37 | try { 38 | try { 39 | sslcontext = SSLContext.getInstance("Default"); 40 | } catch (NoSuchAlgorithmException ex) { 41 | sslcontext = SSLContext.getInstance("TLS"); 42 | } 43 | sslcontext.init(null, null, null); 44 | } catch (final Exception ex) { 45 | throw new IllegalStateException("Failure initializing default SSL context", ex); 46 | } 47 | return sslcontext; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/protocol/NHttpRequestHandlerResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | /** 31 | * HttpRequestHandlerResolver can be used to resolve an instance of 32 | * {@link NHttpRequestHandler} matching a particular request URI. Usually the 33 | * resolved request handler will be used to process the request with the 34 | * specified request URI. 35 | * 36 | * @since 4.0 37 | * 38 | * @deprecated (4.2) use {@link HttpAsyncRequestHandlerResolver} 39 | */ 40 | @Deprecated 41 | public interface NHttpRequestHandlerResolver { 42 | 43 | /** 44 | * Looks up a handler matching the given request URI. 45 | * 46 | * @param requestURI the request URI 47 | * @return HTTP request handler or null if no match 48 | * is found. 49 | */ 50 | NHttpRequestHandler lookup(String requestURI); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncRequestHandlerResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | /** 31 | * HttpAsyncRequestHandlerResolver can be used to map an instance 32 | * of {@link HttpAsyncRequestHandler} matching a particular request URI. 33 | * Usually the mapped request handler will be used to process the request 34 | * with the specified request URI. 35 | * 36 | * @since 4.2 37 | * @deprecated see {@link HttpAsyncRequestHandlerMapper} 38 | */ 39 | @Deprecated 40 | public interface HttpAsyncRequestHandlerResolver { 41 | 42 | /** 43 | * Looks up a handler matching the given request URI. 44 | * 45 | * @param requestURI the request URI 46 | * @return HTTP request handler or null if no match 47 | * is found. 48 | */ 49 | HttpAsyncRequestHandler lookup(String requestURI); 50 | 51 | } 52 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientIOTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | /** 31 | * Extended version of the {@link NHttpClientConnection} used by 32 | * {@link org.apache.http.nio.reactor.IOEventDispatch} implementations 33 | * to inform client-side connection objects of I/O events. 34 | * 35 | * @since 4.0 36 | * 37 | * @deprecated (4.2) no longer used 38 | */ 39 | @Deprecated 40 | public interface NHttpClientIOTarget extends NHttpClientConnection { 41 | 42 | /** 43 | * Triggered when the connection is ready to consume input. 44 | * 45 | * @param handler the client protocol handler. 46 | */ 47 | void consumeInput(NHttpClientHandler handler); 48 | 49 | /** 50 | * Triggered when the connection is ready to produce output. 51 | * 52 | * @param handler the client protocol handler. 53 | */ 54 | void produceOutput(NHttpClientHandler handler); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.HttpMessage; 34 | 35 | /** 36 | * Abstract HTTP message writer for non-blocking connections. 37 | * 38 | * @since 4.0 39 | */ 40 | public interface NHttpMessageWriter { 41 | 42 | /** 43 | * Resets the writer. The writer will be ready to start serializing another 44 | * HTTP message. 45 | */ 46 | void reset(); 47 | 48 | /** 49 | * Serializes out the HTTP message head. 50 | * 51 | * @param message HTTP message. 52 | * @throws IOException in case of an I/O error. 53 | * @throws HttpException in case the HTTP message is malformed or 54 | * violates the HTTP protocol. 55 | */ 56 | void write(T message) throws IOException, HttpException; 57 | 58 | } 59 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerIOTarget.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | /** 31 | * Extended version of the {@link NHttpServerConnection} used by 32 | * {@link org.apache.http.nio.reactor.IOEventDispatch } implementations 33 | * to inform server-side connection objects of I/O events. 34 | * 35 | * @since 4.0 36 | * 37 | * @deprecated (4.2) no longer used 38 | */ 39 | @Deprecated 40 | public interface NHttpServerIOTarget extends NHttpServerConnection { 41 | 42 | /** 43 | * Triggered when the connection is ready to consume input. 44 | * 45 | * @param handler the server protocol handler. 46 | */ 47 | void consumeInput(NHttpServiceHandler handler); 48 | 49 | /** 50 | * Triggered when the connection is ready to produce output. 51 | * 52 | * @param handler the server protocol handler. 53 | */ 54 | void produceOutput(NHttpServiceHandler handler); 55 | 56 | } 57 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/ContentDecoderChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | import java.nio.channels.ReadableByteChannel; 33 | 34 | /** 35 | * A {@link ReadableByteChannel} that delegates to a {@link ContentDecoder}. 36 | * Attempts to close this channel are ignored, and {@link #isOpen} always 37 | * returns true. 38 | * 39 | * @since 4.0 40 | */ 41 | public class ContentDecoderChannel implements ReadableByteChannel { 42 | 43 | private final ContentDecoder decoder; 44 | 45 | public ContentDecoderChannel(final ContentDecoder decoder) { 46 | this.decoder = decoder; 47 | } 48 | 49 | public int read(final ByteBuffer dst) throws IOException { 50 | return decoder.read(dst); 51 | } 52 | 53 | public void close() {} 54 | 55 | public boolean isOpen() { 56 | return true; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/entity/ContentListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.entity; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.nio.ContentDecoder; 33 | import org.apache.http.nio.IOControl; 34 | 35 | /** 36 | * A listener for available data on a non-blocking {@link ConsumingNHttpEntity}. 37 | * 38 | * @since 4.0 39 | * 40 | * @deprecated (4.2) 41 | */ 42 | @Deprecated 43 | public interface ContentListener { 44 | 45 | /** 46 | * Notification that content is available to be read from the decoder. 47 | * 48 | * @param decoder content decoder. 49 | * @param ioctrl I/O control of the underlying connection. 50 | */ 51 | void contentAvailable(ContentDecoder decoder, IOControl ioctrl) 52 | throws IOException; 53 | 54 | /** 55 | * Notification that any resources allocated for reading can be released. 56 | */ 57 | void finished(); 58 | 59 | } 60 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/ContentEncoderChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | import java.nio.channels.WritableByteChannel; 33 | 34 | /** 35 | * A {@link WritableByteChannel} that delegates to a {@link ContentEncoder}. 36 | * Attempts to close this channel are ignored, and {@link #isOpen} always 37 | * returns true. 38 | * 39 | * @since 4.0 40 | */ 41 | public class ContentEncoderChannel implements WritableByteChannel { 42 | 43 | private final ContentEncoder contentEncoder; 44 | 45 | public ContentEncoderChannel(final ContentEncoder contentEncoder) { 46 | this.contentEncoder = contentEncoder; 47 | } 48 | 49 | public int write(final ByteBuffer src) throws IOException { 50 | return contentEncoder.write(src); 51 | } 52 | 53 | public void close() {} 54 | 55 | public boolean isOpen() { 56 | return true; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentDecoderMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.util; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | import java.nio.channels.ReadableByteChannel; 33 | 34 | import org.apache.http.nio.ContentDecoder; 35 | 36 | public class ContentDecoderMock implements ContentDecoder { 37 | 38 | private final ReadableByteChannel channel; 39 | private boolean completed; 40 | 41 | public ContentDecoderMock(final ReadableByteChannel channel) { 42 | super(); 43 | this.channel = channel; 44 | } 45 | 46 | public int read(final ByteBuffer dst) throws IOException { 47 | if (this.completed) { 48 | return -1; 49 | } 50 | final int bytesRead = this.channel.read(dst); 51 | if (bytesRead == -1) { 52 | this.completed = true; 53 | } 54 | return bytesRead; 55 | } 56 | 57 | public boolean isCompleted() { 58 | return this.completed; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/HttpAsyncExpectationVerifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.protocol.HttpContext; 34 | 35 | /** 36 | * HttpAsyncExpectationVerifier defines a strategy to verify whether 37 | * or not an incoming HTTP request meets the target server's expectations. 38 | *

39 | * A server that does not understand or is unable to comply with any of 40 | * the expectation values in the Expect field of a request MUST respond 41 | * with appropriate error status. The server MUST respond with a 417 42 | * (Expectation Failed) status if any of the expectations cannot be met 43 | * or, if there are other problems with the request, some other 4xx 44 | * status. 45 | * 46 | * @since 4.2 47 | */ 48 | public interface HttpAsyncExpectationVerifier { 49 | 50 | void verify( 51 | HttpAsyncExchange httpExchange, 52 | HttpContext context) throws HttpException, IOException; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/util/ContentEncoderMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.util; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | import java.nio.channels.WritableByteChannel; 33 | 34 | import org.apache.http.impl.io.HttpTransportMetricsImpl; 35 | import org.apache.http.impl.nio.codecs.AbstractContentEncoder; 36 | import org.apache.http.nio.reactor.SessionOutputBuffer; 37 | import org.apache.http.util.Asserts; 38 | 39 | public class ContentEncoderMock extends AbstractContentEncoder { 40 | 41 | public ContentEncoderMock( 42 | final WritableByteChannel channel, 43 | final SessionOutputBuffer buffer, 44 | final HttpTransportMetricsImpl metrics) { 45 | super(channel, buffer, metrics); 46 | } 47 | 48 | public int write(final ByteBuffer src) throws IOException { 49 | if (src == null) { 50 | return 0; 51 | } 52 | Asserts.check(!isCompleted(), "Decoding process already completed"); 53 | return this.channel.write(src); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/SessionRequestHandle.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import org.apache.http.annotation.Immutable; 31 | import org.apache.http.util.Args; 32 | 33 | /** 34 | * Session request handle class used by I/O reactor implementations to keep 35 | * a reference to a {@link org.apache.http.nio.reactor.SessionRequest} along 36 | * with the time the request was made. 37 | * 38 | * @since 4.0 39 | */ 40 | @Immutable 41 | public class SessionRequestHandle { 42 | 43 | private final SessionRequestImpl sessionRequest; 44 | private final long requestTime; 45 | 46 | public SessionRequestHandle(final SessionRequestImpl sessionRequest) { 47 | super(); 48 | Args.notNull(sessionRequest, "Session request"); 49 | this.sessionRequest = sessionRequest; 50 | this.requestTime = System.currentTimeMillis(); 51 | } 52 | 53 | public SessionRequestImpl getSessionRequest() { 54 | return this.sessionRequest; 55 | } 56 | 57 | public long getRequestTime() { 58 | return this.requestTime; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/FileContentEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.channels.FileChannel; 32 | 33 | /** 34 | * A content encoder capable of transferring data directly from a {@link FileChannel} 35 | * 36 | * @since 4.0 37 | */ 38 | public interface FileContentEncoder extends ContentEncoder { 39 | 40 | /** 41 | * Transfers a portion of entity content from the given file channel 42 | * to the underlying network channel. 43 | * 44 | * @param src the source FileChannel to transfer data from. 45 | * @param position 46 | * The position within the file at which the transfer is to begin; 47 | * must be non-negative 48 | * @param count 49 | * The maximum number of bytes to be transferred; must be 50 | * non-negative 51 | *@throws IOException, if some I/O error occurs. 52 | * @return The number of bytes, possibly zero, 53 | * that were actually transferred 54 | */ 55 | long transfer(FileChannel src, long position, long count) throws IOException; 56 | 57 | } 58 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/ContentDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | 33 | /** 34 | * Abstract HTTP content decoder. HTTP content decoders can be used 35 | * to read entity content from the underlying channel in small 36 | * chunks and apply the required coding transformation. 37 | * 38 | * @since 4.0 39 | */ 40 | public interface ContentDecoder { 41 | 42 | /** 43 | * Reads a portion of content from the underlying channel 44 | * 45 | * @param dst The buffer into which entity content is to be transferred 46 | * @return The number of bytes read, possibly zero, or -1 if the 47 | * channel has reached end-of-stream 48 | * @throws IOException if I/O error occurs while reading content 49 | */ 50 | int read(ByteBuffer dst) throws IOException; 51 | 52 | /** 53 | * Returns true if the entity has been received in its 54 | * entirety. 55 | * 56 | * @return true if all the content has been consumed, 57 | * false otherwise. 58 | */ 59 | boolean isCompleted(); 60 | 61 | } 62 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/ExceptionEventTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import java.util.Date; 31 | 32 | import org.junit.Assert; 33 | import org.junit.Test; 34 | 35 | public class ExceptionEventTest { 36 | 37 | @Test 38 | public void testGetCause() { 39 | final NullPointerException npe = new NullPointerException("npe"); 40 | ExceptionEvent ee = new ExceptionEvent(npe); 41 | Assert.assertSame(npe, ee.getCause()); 42 | ee = new ExceptionEvent(npe, new Date()); 43 | Assert.assertSame(npe, ee.getCause()); 44 | } 45 | 46 | @Test 47 | public void testGetTimestamp() { 48 | final NullPointerException npe = new NullPointerException("npe"); 49 | ExceptionEvent ee = new ExceptionEvent(npe); 50 | Assert.assertNotNull(ee.getTimestamp()); 51 | ee = new ExceptionEvent(npe, new Date(1234567890L)); 52 | Assert.assertEquals(new Date(1234567890L), ee.getTimestamp()); 53 | } 54 | 55 | @Test 56 | public void testToString() { 57 | Assert.assertNotNull(new ExceptionEvent(new NullPointerException())); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NullRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import org.apache.http.HttpRequest; 31 | import org.apache.http.HttpResponse; 32 | import org.apache.http.HttpStatus; 33 | import org.apache.http.entity.ContentType; 34 | import org.apache.http.nio.entity.NStringEntity; 35 | import org.apache.http.protocol.HttpContext; 36 | 37 | class NullRequestHandler implements HttpAsyncRequestHandler { 38 | 39 | public NullRequestHandler() { 40 | super(); 41 | } 42 | 43 | public HttpAsyncRequestConsumer processRequest( 44 | final HttpRequest request, final HttpContext context) { 45 | return new NullRequestConsumer(); 46 | } 47 | 48 | public void handle( 49 | final Object obj, 50 | final HttpAsyncExchange httpexchange, 51 | final HttpContext context) { 52 | final HttpResponse response = httpexchange.getResponse(); 53 | response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED); 54 | httpexchange.submitResponse(new ErrorResponseProducer( 55 | response, new NStringEntity("Service not implemented", ContentType.TEXT_PLAIN), true)); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/entity/SkipContentListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.entity; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | 33 | import org.apache.http.nio.ContentDecoder; 34 | import org.apache.http.nio.IOControl; 35 | import org.apache.http.nio.util.ByteBufferAllocator; 36 | import org.apache.http.util.Args; 37 | 38 | /** 39 | * A simple {@link ContentListener} that reads and ignores all content. 40 | * 41 | * @since 4.0 42 | * 43 | * @deprecated (4.2) 44 | */ 45 | @Deprecated 46 | public class SkipContentListener implements ContentListener { 47 | 48 | private final ByteBuffer buffer; 49 | 50 | public SkipContentListener(final ByteBufferAllocator allocator) { 51 | super(); 52 | Args.notNull(allocator, "ByteBuffer allocator"); 53 | this.buffer = allocator.allocate(2048); 54 | } 55 | 56 | public void contentAvailable( 57 | final ContentDecoder decoder, 58 | final IOControl ioctrl) throws IOException { 59 | int lastRead; 60 | do { 61 | buffer.clear(); 62 | lastRead = decoder.read(buffer); 63 | } while (lastRead > 0); 64 | } 65 | 66 | public void finished() { 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/impl/nio/reactor/SSLSetupHandlerAdaptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import javax.net.ssl.SSLEngine; 31 | import javax.net.ssl.SSLException; 32 | import javax.net.ssl.SSLSession; 33 | 34 | import org.apache.http.nio.reactor.IOSession; 35 | import org.apache.http.params.BasicHttpParams; 36 | import org.apache.http.params.HttpParams; 37 | 38 | /** 39 | * @deprecated (4.2) 40 | */ 41 | @Deprecated 42 | class SSLSetupHandlerAdaptor implements org.apache.http.nio.reactor.ssl.SSLSetupHandler { 43 | 44 | private final SSLSetupHandler handler; 45 | 46 | private HttpParams params; 47 | 48 | public SSLSetupHandlerAdaptor(final SSLSetupHandler handler) { 49 | super(); 50 | this.handler = handler; 51 | } 52 | 53 | public void initalize(final SSLEngine sslengine) throws SSLException { 54 | this.handler.initalize(sslengine, this.params != null ? this.params : new BasicHttpParams()); 55 | } 56 | 57 | public void verify(final IOSession iosession, final SSLSession sslsession) throws SSLException { 58 | this.handler.verify(iosession, sslsession); 59 | } 60 | 61 | public void setParams(final HttpParams params) { 62 | this.params = params; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/ExceptionEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import java.util.Date; 31 | 32 | import org.apache.http.annotation.Immutable; 33 | 34 | /** 35 | * A {@link Throwable} instance along with a time stamp. 36 | * 37 | * @since 4.0 38 | */ 39 | @Immutable 40 | public class ExceptionEvent { 41 | 42 | private final Throwable ex; 43 | private final long time; 44 | 45 | public ExceptionEvent(final Throwable ex, final Date timestamp) { 46 | super(); 47 | this.ex = ex; 48 | if (timestamp != null) { 49 | this.time = timestamp.getTime(); 50 | } else { 51 | this.time = 0; 52 | } 53 | } 54 | 55 | public ExceptionEvent(final Exception ex) { 56 | this(ex, new Date()); 57 | } 58 | 59 | public Throwable getCause() { 60 | return ex; 61 | } 62 | 63 | public Date getTimestamp() { 64 | return new Date(this.time); 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | final StringBuilder buffer = new StringBuilder(); 70 | buffer.append(new Date(this.time)); 71 | buffer.append(" "); 72 | buffer.append(this.ex); 73 | return buffer.toString(); 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/ContentEncoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | 33 | /** 34 | * Abstract HTTP content encoder. HTTP content encoders can be used 35 | * to apply the required coding transformation and write entity 36 | * content to the underlying channel in small chunks. 37 | * 38 | * @since 4.0 39 | */ 40 | public interface ContentEncoder { 41 | 42 | /** 43 | * Writes a portion of entity content to the underlying channel. 44 | * 45 | * @param src The buffer from which content is to be retrieved 46 | * @return The number of bytes read, possibly zero 47 | * @throws IOException if I/O error occurs while writing content 48 | */ 49 | int write(ByteBuffer src) throws IOException; 50 | 51 | /** 52 | * Terminates the content stream. 53 | * 54 | * @throws IOException if I/O error occurs while writing content 55 | */ 56 | void complete() throws IOException; 57 | 58 | /** 59 | * Returns true if the entity has been transferred in its 60 | * entirety. 61 | * 62 | * @return true if all the content has been produced, 63 | * false otherwise. 64 | */ 65 | boolean isCompleted(); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/impl/nio/reactor/SSLIOSessionHandlerAdaptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import javax.net.ssl.SSLEngine; 31 | import javax.net.ssl.SSLException; 32 | import javax.net.ssl.SSLSession; 33 | 34 | import org.apache.http.nio.reactor.IOSession; 35 | import org.apache.http.params.BasicHttpParams; 36 | import org.apache.http.params.HttpParams; 37 | 38 | /** 39 | * @deprecated (4.2) 40 | */ 41 | @Deprecated 42 | class SSLIOSessionHandlerAdaptor implements org.apache.http.nio.reactor.ssl.SSLSetupHandler { 43 | 44 | private final SSLIOSessionHandler handler; 45 | 46 | private HttpParams params; 47 | 48 | public SSLIOSessionHandlerAdaptor(final SSLIOSessionHandler handler) { 49 | super(); 50 | this.handler = handler; 51 | } 52 | 53 | public void initalize(final SSLEngine sslengine) throws SSLException { 54 | this.handler.initalize(sslengine, this.params != null ? this.params : new BasicHttpParams()); 55 | } 56 | 57 | public void verify(final IOSession iosession, final SSLSession sslsession) throws SSLException { 58 | this.handler.verify(iosession.getRemoteAddress(), sslsession); 59 | } 60 | 61 | public void setParams(final HttpParams params) { 62 | this.params = params; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/ByteChannelMock.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | import java.nio.channels.ByteChannel; 33 | 34 | public class ByteChannelMock implements ByteChannel { 35 | 36 | private final ReadableByteChannelMock readableChannel; 37 | private final WritableByteChannelMock writableChannel; 38 | private boolean closed; 39 | 40 | public ByteChannelMock( 41 | final ReadableByteChannelMock readableChannel, 42 | final WritableByteChannelMock writableChannel) { 43 | super(); 44 | this.readableChannel = readableChannel; 45 | this.writableChannel = writableChannel; 46 | } 47 | 48 | public int read(final ByteBuffer dst) throws IOException { 49 | return this.readableChannel.read(dst); 50 | } 51 | 52 | public int write(final ByteBuffer src) throws IOException { 53 | return this.writableChannel.write(src); 54 | } 55 | 56 | public boolean isOpen() { 57 | return !this.closed; 58 | } 59 | 60 | public void close() throws IOException { 61 | if (this.closed) { 62 | return; 63 | } 64 | this.closed = true; 65 | this.readableChannel.close(); 66 | this.writableChannel.close(); 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/integration/TestHttpsAsyncHandlers.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.integration; 29 | 30 | import org.apache.http.impl.nio.DefaultNHttpClientConnection; 31 | import org.apache.http.impl.nio.DefaultNHttpServerConnection; 32 | import org.apache.http.nio.NHttpConnectionFactory; 33 | import org.apache.http.nio.testserver.LoggingSSLClientConnectionFactory; 34 | import org.apache.http.nio.testserver.LoggingSSLServerConnectionFactory; 35 | import org.apache.http.nio.testserver.SSLTestContexts; 36 | import org.junit.Ignore; 37 | 38 | /** 39 | * HttpCore NIO integration tests for async handlers using SSL. 40 | */ 41 | // TODO: Enable after test failures are fixed. 42 | @Ignore("Disabled due to build failing in workflows") 43 | public class TestHttpsAsyncHandlers extends TestHttpAsyncHandlers { 44 | 45 | @Override 46 | protected NHttpConnectionFactory createServerConnectionFactory() throws Exception { 47 | return new LoggingSSLServerConnectionFactory(SSLTestContexts.createServerSSLContext()); 48 | } 49 | 50 | @Override 51 | protected NHttpConnectionFactory createClientConnectionFactory() throws Exception { 52 | return new LoggingSSLClientConnectionFactory(SSLTestContexts.createClientSSLContext()); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/impl/nio/reactor/TestDefaultIOReactorsSSL.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import org.apache.http.impl.nio.DefaultNHttpClientConnection; 31 | import org.apache.http.impl.nio.DefaultNHttpServerConnection; 32 | import org.apache.http.nio.NHttpConnectionFactory; 33 | import org.apache.http.nio.testserver.LoggingSSLClientConnectionFactory; 34 | import org.apache.http.nio.testserver.LoggingSSLServerConnectionFactory; 35 | import org.apache.http.nio.testserver.SSLTestContexts; 36 | import org.junit.Ignore; 37 | 38 | /** 39 | * Basic functionality tests for SSL I/O reactors. 40 | * 41 | */ 42 | // TODO: Enable after test failures are fixed. 43 | @Ignore("Disabled due to build failing in workflows") 44 | public class TestDefaultIOReactorsSSL extends TestDefaultIOReactors { 45 | 46 | @Override 47 | protected NHttpConnectionFactory createServerConnectionFactory() throws Exception { 48 | return new LoggingSSLServerConnectionFactory(SSLTestContexts.createServerSSLContext()); 49 | } 50 | 51 | @Override 52 | protected NHttpConnectionFactory createClientConnectionFactory() throws Exception { 53 | return new LoggingSSLClientConnectionFactory(SSLTestContexts.createClientSSLContext()); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpRequestWriterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.codecs; 29 | 30 | import org.apache.http.HttpRequest; 31 | import org.apache.http.annotation.Immutable; 32 | import org.apache.http.message.BasicLineFormatter; 33 | import org.apache.http.message.LineFormatter; 34 | import org.apache.http.nio.NHttpMessageWriter; 35 | import org.apache.http.nio.NHttpMessageWriterFactory; 36 | import org.apache.http.nio.reactor.SessionOutputBuffer; 37 | 38 | /** 39 | * Default factory for request message writers. 40 | * 41 | * @since 4.3 42 | */ 43 | @Immutable 44 | public class DefaultHttpRequestWriterFactory implements NHttpMessageWriterFactory { 45 | 46 | public static final DefaultHttpRequestWriterFactory INSTANCE = new DefaultHttpRequestWriterFactory(); 47 | 48 | private final LineFormatter lineFormatter; 49 | 50 | public DefaultHttpRequestWriterFactory(final LineFormatter lineFormatter) { 51 | super(); 52 | this.lineFormatter = lineFormatter != null ? lineFormatter : BasicLineFormatter.INSTANCE; 53 | } 54 | 55 | public DefaultHttpRequestWriterFactory() { 56 | this(null); 57 | } 58 | 59 | public NHttpMessageWriter create(final SessionOutputBuffer buffer) { 60 | return new DefaultHttpRequestWriter(buffer, lineFormatter); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/protocol/SimpleNHttpRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.HttpRequest; 34 | import org.apache.http.HttpResponse; 35 | import org.apache.http.annotation.Immutable; 36 | import org.apache.http.protocol.HttpContext; 37 | 38 | /** 39 | * A simple implementation of {@link NHttpRequestHandler} that abstracts away 40 | * the need to use {@link NHttpResponseTrigger}. Implementations need only to 41 | * implement {@link #handle(HttpRequest, HttpResponse, HttpContext)}. 42 | * 43 | * @since 4.0 44 | * 45 | * @deprecated (4.2) use {@link BasicAsyncRequestHandler} 46 | */ 47 | @Deprecated 48 | @Immutable 49 | public abstract class SimpleNHttpRequestHandler implements NHttpRequestHandler { 50 | 51 | public final void handle( 52 | final HttpRequest request, 53 | final HttpResponse response, 54 | final NHttpResponseTrigger trigger, 55 | final HttpContext context) throws HttpException, IOException { 56 | handle(request, response, context); 57 | trigger.submitResponse(response); 58 | } 59 | 60 | public abstract void handle(HttpRequest request, HttpResponse response, HttpContext context) 61 | throws HttpException, IOException; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/impl/nio/codecs/HttpRequestWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.codecs; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpMessage; 33 | import org.apache.http.HttpRequest; 34 | import org.apache.http.message.LineFormatter; 35 | import org.apache.http.nio.reactor.SessionOutputBuffer; 36 | import org.apache.http.params.HttpParams; 37 | import org.apache.http.util.CharArrayBuffer; 38 | 39 | /** 40 | * Default {@link org.apache.http.nio.NHttpMessageWriter} implementation 41 | * for {@link HttpRequest}s. 42 | * 43 | * @since 4.0 44 | * 45 | * @deprecated (4.1) use {@link DefaultHttpRequestWriter} 46 | */ 47 | @SuppressWarnings("rawtypes") 48 | @Deprecated 49 | public class HttpRequestWriter extends AbstractMessageWriter { 50 | 51 | public HttpRequestWriter(final SessionOutputBuffer buffer, 52 | final LineFormatter formatter, 53 | final HttpParams params) { 54 | super(buffer, formatter, params); 55 | } 56 | 57 | @Override 58 | protected void writeHeadLine(final HttpMessage message) 59 | throws IOException { 60 | 61 | final CharArrayBuffer buffer = lineFormatter.formatRequestLine 62 | (this.lineBuf, ((HttpRequest) message).getRequestLine()); 63 | this.sessionBuffer.writeLine(buffer); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/codecs/DefaultHttpResponseWriterFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.codecs; 29 | 30 | import org.apache.http.HttpResponse; 31 | import org.apache.http.annotation.Immutable; 32 | import org.apache.http.message.BasicLineFormatter; 33 | import org.apache.http.message.LineFormatter; 34 | import org.apache.http.nio.NHttpMessageWriter; 35 | import org.apache.http.nio.NHttpMessageWriterFactory; 36 | import org.apache.http.nio.reactor.SessionOutputBuffer; 37 | 38 | /** 39 | * Default factory for response message writers. 40 | * 41 | * @since 4.3 42 | */ 43 | @Immutable 44 | public class DefaultHttpResponseWriterFactory implements NHttpMessageWriterFactory { 45 | 46 | public static final DefaultHttpResponseWriterFactory INSTANCE = new DefaultHttpResponseWriterFactory(); 47 | 48 | private final LineFormatter lineFormatter; 49 | 50 | public DefaultHttpResponseWriterFactory(final LineFormatter lineFormatter) { 51 | super(); 52 | this.lineFormatter = lineFormatter != null ? lineFormatter : BasicLineFormatter.INSTANCE; 53 | } 54 | 55 | public DefaultHttpResponseWriterFactory() { 56 | this(null); 57 | } 58 | 59 | public NHttpMessageWriter create(final SessionOutputBuffer buffer) { 60 | return new DefaultHttpResponseWriter(buffer, lineFormatter); 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/impl/nio/codecs/HttpResponseWriter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.codecs; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpMessage; 33 | import org.apache.http.HttpResponse; 34 | import org.apache.http.message.LineFormatter; 35 | import org.apache.http.nio.reactor.SessionOutputBuffer; 36 | import org.apache.http.params.HttpParams; 37 | import org.apache.http.util.CharArrayBuffer; 38 | 39 | /** 40 | * Default {@link org.apache.http.nio.NHttpMessageWriter} implementation 41 | * for {@link HttpResponse}s. 42 | * 43 | * @since 4.0 44 | * 45 | * @deprecated (4.1) use {@link DefaultHttpResponseWriter} 46 | */ 47 | @SuppressWarnings("rawtypes") 48 | @Deprecated 49 | public class HttpResponseWriter extends AbstractMessageWriter { 50 | 51 | public HttpResponseWriter(final SessionOutputBuffer buffer, 52 | final LineFormatter formatter, 53 | final HttpParams params) { 54 | super(buffer, formatter, params); 55 | } 56 | 57 | @Override 58 | protected void writeHeadLine(final HttpMessage message) 59 | throws IOException { 60 | 61 | final CharArrayBuffer buffer = lineFormatter.formatStatusLine 62 | (this.lineBuf, ((HttpResponse) message).getStatusLine()); 63 | this.sessionBuffer.writeLine(buffer); 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/entity/ConsumingNHttpEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.entity; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpEntity; 33 | import org.apache.http.nio.ContentDecoder; 34 | import org.apache.http.nio.IOControl; 35 | 36 | /** 37 | * A non-blocking {@link HttpEntity} that allows content to be streamed from a 38 | * {@link ContentDecoder}. 39 | * 40 | * @since 4.0 41 | * 42 | * @deprecated use (4.2) 43 | * {@link org.apache.http.nio.protocol.BasicAsyncRequestProducer} 44 | * or {@link org.apache.http.nio.protocol.BasicAsyncResponseProducer} 45 | */ 46 | @Deprecated 47 | public interface ConsumingNHttpEntity extends HttpEntity { 48 | 49 | /** 50 | * Notification that content is available to be read from the decoder. 51 | * {@link IOControl} instance passed as a parameter to the method can be 52 | * used to suspend input events if the entity is temporarily unable to 53 | * allocate more storage to accommodate all incoming content. 54 | * 55 | * @param decoder content decoder. 56 | * @param ioctrl I/O control of the underlying connection. 57 | */ 58 | void consumeContent(ContentDecoder decoder, IOControl ioctrl) throws IOException; 59 | 60 | /** 61 | * Notification that any resources allocated for reading can be released. 62 | */ 63 | void finish() throws IOException; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/pool/BasicNIOPoolEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.impl.nio.pool; 28 | 29 | import java.io.IOException; 30 | 31 | import org.apache.http.HttpHost; 32 | import org.apache.http.annotation.ThreadSafe; 33 | import org.apache.http.nio.NHttpClientConnection; 34 | import org.apache.http.pool.PoolEntry; 35 | 36 | /** 37 | * A basic {@link PoolEntry} implementation that represents an entry 38 | * in a pool of non-blocking {@link NHttpClientConnection}s identified by 39 | * an {@link HttpHost} instance. 40 | * 41 | * @see HttpHost 42 | * @since 4.2 43 | */ 44 | @ThreadSafe 45 | public class BasicNIOPoolEntry extends PoolEntry { 46 | 47 | private volatile int socketTimeout; 48 | 49 | public BasicNIOPoolEntry(final String id, final HttpHost route, final NHttpClientConnection conn) { 50 | super(id, route, conn); 51 | } 52 | 53 | @Override 54 | public void close() { 55 | try { 56 | getConnection().close(); 57 | } catch (final IOException ignore) { 58 | } 59 | } 60 | 61 | @Override 62 | public boolean isClosed() { 63 | return !getConnection().isOpen(); 64 | } 65 | 66 | int getSocketTimeout() { 67 | return socketTimeout; 68 | } 69 | 70 | void setSocketTimeout(final int socketTimeout) { 71 | this.socketTimeout = socketTimeout; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/impl/nio/reactor/InterestOpEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.reactor; 29 | 30 | import java.nio.channels.SelectionKey; 31 | 32 | import org.apache.http.util.Args; 33 | 34 | /** 35 | * Helper class, representing an entry on an {@link java.nio.channels.SelectionKey#interestOps(int) 36 | * interestOps(int)} queue. 37 | * 38 | * @since 4.1 39 | */ 40 | class InterestOpEntry { 41 | 42 | private final SelectionKey key; 43 | private final int eventMask; 44 | 45 | public InterestOpEntry(final SelectionKey key, final int eventMask) { 46 | super(); 47 | Args.notNull(key, "Selection key"); 48 | this.key = key; 49 | this.eventMask = eventMask; 50 | } 51 | 52 | public SelectionKey getSelectionKey() { 53 | return this.key; 54 | } 55 | 56 | public int getEventMask() { 57 | return this.eventMask; 58 | } 59 | 60 | @Override 61 | public boolean equals(final Object obj) { 62 | if (this == obj) { 63 | return true; 64 | } 65 | if (obj instanceof InterestOpEntry) { 66 | final InterestOpEntry that = (InterestOpEntry) obj; 67 | return this.key.equals(that.key); 68 | } else { 69 | return false; 70 | } 71 | } 72 | 73 | @Override 74 | public int hashCode() { 75 | return this.key.hashCode(); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/impl/nio/codecs/CodecTestUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.impl.nio.codecs; 29 | 30 | import java.io.File; 31 | import java.io.FileInputStream; 32 | import java.io.InputStreamReader; 33 | import java.nio.ByteBuffer; 34 | 35 | import org.apache.http.util.EncodingUtils; 36 | 37 | class CodecTestUtils { 38 | 39 | public static ByteBuffer wrap(final String s) { 40 | return ByteBuffer.wrap(EncodingUtils.getAsciiBytes(s)); 41 | } 42 | 43 | public static String convert(final ByteBuffer src) { 44 | src.flip(); 45 | final StringBuilder buffer = new StringBuilder(src.remaining()); 46 | while (src.hasRemaining()) { 47 | buffer.append((char)(src.get() & 0xff)); 48 | } 49 | return buffer.toString(); 50 | } 51 | 52 | public static String readFromFile(final File file) throws Exception { 53 | final FileInputStream filestream = new FileInputStream(file); 54 | final InputStreamReader reader = new InputStreamReader(filestream); 55 | try { 56 | final StringBuilder buffer = new StringBuilder(); 57 | final char[] tmp = new char[2048]; 58 | int l; 59 | while ((l = reader.read(tmp)) != -1) { 60 | buffer.append(tmp, 0, l); 61 | } 62 | return buffer.toString(); 63 | } finally { 64 | reader.close(); 65 | } 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/IOControl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | 32 | /** 33 | * Connection input/output control interface. It can be used to control interest 34 | * in I/O event notifications for non-blocking HTTP connections. 35 | *

36 | * Implementations of this interface are expected to be threading safe. 37 | * Therefore it can be used to request / suspend I/O event notifications from 38 | * any thread of execution. 39 | * 40 | * @since 4.0 41 | */ 42 | public interface IOControl { 43 | 44 | /** 45 | * Requests event notifications to be triggered when the underlying 46 | * channel is ready for input operations. 47 | */ 48 | void requestInput(); 49 | 50 | /** 51 | * Suspends event notifications about the underlying channel being 52 | * ready for input operations. 53 | */ 54 | void suspendInput(); 55 | 56 | /** 57 | * Requests event notifications to be triggered when the underlying 58 | * channel is ready for output operations. 59 | */ 60 | void requestOutput(); 61 | 62 | /** 63 | * Suspends event notifications about the underlying channel being 64 | * ready for output operations. 65 | */ 66 | void suspendOutput(); 67 | 68 | /** 69 | * Shuts down the underlying channel. 70 | * 71 | * @throws IOException 72 | */ 73 | void shutdown() throws IOException; 74 | 75 | } 76 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/SessionRequestCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | /** 31 | * SessionRequestCallback interface can be used to get notifications of 32 | * completion of session requests asynchronously without having to wait 33 | * for it, blocking the current thread of execution. 34 | * 35 | * @since 4.0 36 | */ 37 | public interface SessionRequestCallback { 38 | 39 | /** 40 | * Triggered on successful completion of a {@link SessionRequest}. 41 | * The {@link SessionRequest#getSession()} method can now be used to obtain 42 | * the new I/O session. 43 | * 44 | * @param request session request. 45 | */ 46 | void completed(SessionRequest request); 47 | 48 | /** 49 | * Triggered on unsuccessful completion a {@link SessionRequest}. 50 | * The {@link SessionRequest#getException()} method can now be used to 51 | * obtain the cause of the error. 52 | * 53 | * @param request session request. 54 | */ 55 | void failed(SessionRequest request); 56 | 57 | /** 58 | * Triggered if a {@link SessionRequest} times out. 59 | * 60 | * @param request session request. 61 | */ 62 | void timeout(SessionRequest request); 63 | 64 | /** 65 | * Triggered on cancellation of a {@link SessionRequest}. 66 | * 67 | * @param request session request. 68 | */ 69 | void cancelled(SessionRequest request); 70 | 71 | } 72 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/FileContentDecoder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.channels.FileChannel; 32 | 33 | /** 34 | * A content decoder capable of transferring data directly to a {@link FileChannel} 35 | * 36 | * @since 4.0 37 | */ 38 | public interface FileContentDecoder extends ContentDecoder { 39 | 40 | /** 41 | * Transfers a portion of entity content from the underlying network channel 42 | * into the given file channel.
43 | * 44 | * Warning: Many implementations cannot write beyond the length of the file. 45 | * If the position exceeds the channel's size, some implementations 46 | * may throw an IOException. 47 | * 48 | * @param dst the target FileChannel to transfer data into. 49 | * @param position 50 | * The position within the file at which the transfer is to begin; 51 | * must be non-negative. 52 | * Must be less than or equal to the size of the file 53 | * @param count 54 | * The maximum number of bytes to be transferred; must be 55 | * non-negative 56 | * @throws IOException, if some I/O error occurs. 57 | * @return The number of bytes, possibly zero, 58 | * that were actually transferred 59 | */ 60 | long transfer(FileChannel dst, long position, long count) throws IOException; 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Purpose 2 | > Describe the problems, issues, or needs driving this feature/fix and include links to related issues in the following format: Resolves issue1, issue2, etc. 3 | 4 | ## Goals 5 | > Describe the solutions that this feature/fix will introduce to resolve the problems described above 6 | 7 | ## Approach 8 | > Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here. 9 | 10 | ## User stories 11 | > Summary of user stories addressed by this change> 12 | 13 | ## Release note 14 | > Brief description of the new feature or bug fix as it will appear in the release notes 15 | 16 | ## Documentation 17 | > Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact 18 | 19 | ## Training 20 | > Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable 21 | 22 | ## Certification 23 | > Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why. 24 | 25 | ## Marketing 26 | > Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable 27 | 28 | ## Automation tests 29 | - Unit tests 30 | > Code coverage information 31 | - Integration tests 32 | > Details about the test cases and coverage 33 | 34 | ## Security checks 35 | - Followed secure coding standards in http://wso2.com/technical-reports/wso2-secure-engineering-guidelines? yes/no 36 | - Ran FindSecurityBugs plugin and verified report? yes/no 37 | - Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets? yes/no 38 | 39 | ## Samples 40 | > Provide high-level details about the samples related to this feature 41 | 42 | ## Related PRs 43 | > List any other related PRs 44 | 45 | ## Migrations (if applicable) 46 | > Describe migration steps and platforms on which migration has been tested 47 | 48 | ## Test environment 49 | > List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested 50 | 51 | ## Learning 52 | > Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem. -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/IOReactorExceptionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | import java.io.IOException; 31 | 32 | /** 33 | * Abstract exception handler intended to deal with potentially recoverable 34 | * I/O exceptions thrown by an I/O reactor. 35 | * 36 | * @since 4.0 37 | */ 38 | public interface IOReactorExceptionHandler { 39 | 40 | /** 41 | * This method is expected to examine the I/O exception passed as 42 | * a parameter and decide whether it is safe to continue execution of 43 | * the I/O reactor. 44 | * 45 | * @param ex potentially recoverable I/O exception 46 | * @return true if it is safe to ignore the exception 47 | * and continue execution of the I/O reactor; false if the 48 | * I/O reactor must throw {@link IOReactorException} and terminate 49 | */ 50 | boolean handle(IOException ex); 51 | 52 | /** 53 | * This method is expected to examine the runtime exception passed as 54 | * a parameter and decide whether it is safe to continue execution of 55 | * the I/O reactor. 56 | * 57 | * @param ex potentially recoverable runtime exception 58 | * @return true if it is safe to ignore the exception 59 | * and continue execution of the I/O reactor; false if the 60 | * I/O reactor must throw {@link RuntimeException} and terminate 61 | */ 62 | boolean handle(RuntimeException ex); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentOutputStream.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.entity; 29 | 30 | import java.io.IOException; 31 | import java.io.OutputStream; 32 | 33 | import org.apache.http.annotation.NotThreadSafe; 34 | import org.apache.http.nio.util.ContentOutputBuffer; 35 | import org.apache.http.util.Args; 36 | 37 | /** 38 | * {@link OutputStream} adaptor for {@link ContentOutputBuffer}. 39 | * 40 | * @since 4.0 41 | */ 42 | @NotThreadSafe 43 | public class ContentOutputStream extends OutputStream { 44 | 45 | private final ContentOutputBuffer buffer; 46 | 47 | public ContentOutputStream(final ContentOutputBuffer buffer) { 48 | super(); 49 | Args.notNull(buffer, "Output buffer"); 50 | this.buffer = buffer; 51 | } 52 | 53 | @Override 54 | public void close() throws IOException { 55 | this.buffer.writeCompleted(); 56 | } 57 | 58 | @Override 59 | public void flush() throws IOException { 60 | } 61 | 62 | @Override 63 | public void write(final byte[] b, final int off, final int len) throws IOException { 64 | this.buffer.write(b, off, len); 65 | } 66 | 67 | @Override 68 | public void write(final byte[] b) throws IOException { 69 | if (b == null) { 70 | return; 71 | } 72 | this.buffer.write(b, 0, b.length); 73 | } 74 | 75 | @Override 76 | public void write(final int b) throws IOException { 77 | this.buffer.write(b); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/testserver/LoggingSSLClientConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.testserver; 28 | 29 | import javax.net.ssl.SSLContext; 30 | 31 | import org.apache.http.impl.nio.DefaultNHttpClientConnection; 32 | import org.apache.http.nio.NHttpConnectionFactory; 33 | import org.apache.http.nio.reactor.IOSession; 34 | import org.apache.http.nio.reactor.ssl.SSLIOSession; 35 | import org.apache.http.nio.reactor.ssl.SSLMode; 36 | import org.apache.http.nio.reactor.ssl.SSLSetupHandler; 37 | 38 | public class LoggingSSLClientConnectionFactory implements NHttpConnectionFactory { 39 | 40 | private final SSLContext sslcontext; 41 | private final SSLSetupHandler setupHandler; 42 | 43 | public LoggingSSLClientConnectionFactory( 44 | final SSLContext sslcontext, final SSLSetupHandler setupHandler) { 45 | super(); 46 | this.sslcontext = sslcontext; 47 | this.setupHandler = setupHandler; 48 | } 49 | 50 | public LoggingSSLClientConnectionFactory(final SSLContext sslcontext) { 51 | this(sslcontext, null); 52 | } 53 | 54 | public DefaultNHttpClientConnection createConnection(final IOSession iosession) { 55 | final SSLIOSession ssliosession = new SSLIOSession( 56 | iosession, SSLMode.CLIENT, this.sslcontext, this.setupHandler); 57 | iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession); 58 | return new LoggingNHttpClientConnection(ssliosession); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/nio/testserver/LoggingSSLServerConnectionFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.nio.testserver; 28 | 29 | import javax.net.ssl.SSLContext; 30 | 31 | import org.apache.http.impl.nio.DefaultNHttpServerConnection; 32 | import org.apache.http.nio.NHttpConnectionFactory; 33 | import org.apache.http.nio.reactor.IOSession; 34 | import org.apache.http.nio.reactor.ssl.SSLIOSession; 35 | import org.apache.http.nio.reactor.ssl.SSLMode; 36 | import org.apache.http.nio.reactor.ssl.SSLSetupHandler; 37 | 38 | public class LoggingSSLServerConnectionFactory implements NHttpConnectionFactory { 39 | 40 | private final SSLContext sslcontext; 41 | private final SSLSetupHandler setupHandler; 42 | 43 | public LoggingSSLServerConnectionFactory( 44 | final SSLContext sslcontext, final SSLSetupHandler setupHandler) { 45 | super(); 46 | this.sslcontext = sslcontext; 47 | this.setupHandler = setupHandler; 48 | } 49 | 50 | public LoggingSSLServerConnectionFactory(final SSLContext sslcontext) { 51 | this(sslcontext, null); 52 | } 53 | 54 | public DefaultNHttpServerConnection createConnection(final IOSession iosession) { 55 | final SSLIOSession ssliosession = new SSLIOSession( 56 | iosession, SSLMode.SERVER, this.sslcontext, this.setupHandler); 57 | iosession.setAttribute(SSLIOSession.SESSION_KEY, ssliosession); 58 | return new LoggingNHttpServerConnection(ssliosession); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/entity/ProducingNHttpEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.entity; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpEntity; 33 | import org.apache.http.nio.ContentEncoder; 34 | import org.apache.http.nio.IOControl; 35 | 36 | /** 37 | * An {@link HttpEntity} that can stream content out into a 38 | * {@link ContentEncoder}. 39 | * 40 | * @since 4.0 41 | * 42 | * @deprecated use (4.2) 43 | * {@link org.apache.http.nio.protocol.BasicAsyncRequestProducer} 44 | * or {@link org.apache.http.nio.protocol.BasicAsyncResponseProducer} 45 | */ 46 | @Deprecated 47 | public interface ProducingNHttpEntity extends HttpEntity { 48 | 49 | /** 50 | * Notification that content should be written to the encoder. 51 | * {@link IOControl} instance passed as a parameter to the method can be 52 | * used to suspend output events if the entity is temporarily unable to 53 | * produce more content. 54 | *

55 | * When all content is finished, this MUST call {@link ContentEncoder#complete()}. 56 | * Failure to do so could result in the entity never being written. 57 | * 58 | * @param encoder content encoder. 59 | * @param ioctrl I/O control of the underlying connection. 60 | */ 61 | void produceContent(ContentEncoder encoder, IOControl ioctrl) throws IOException; 62 | 63 | /** 64 | * Notification that any resources allocated for writing can be released. 65 | */ 66 | void finish() throws IOException; 67 | 68 | } 69 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpMessageParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | import java.nio.channels.ReadableByteChannel; 32 | 33 | import org.apache.http.HttpException; 34 | import org.apache.http.HttpMessage; 35 | 36 | /** 37 | * Abstract HTTP message parser for non-blocking connections. 38 | * 39 | * @since 4.0 40 | */ 41 | public interface NHttpMessageParser { 42 | 43 | /** 44 | * Resets the parser. The parser will be ready to start parsing another 45 | * HTTP message. 46 | */ 47 | void reset(); 48 | 49 | /** 50 | * Fills the internal buffer of the parser with input data from the 51 | * given {@link ReadableByteChannel}. 52 | * 53 | * @param channel the input channel 54 | * @return number of bytes read. 55 | * @throws IOException in case of an I/O error. 56 | */ 57 | int fillBuffer(ReadableByteChannel channel) 58 | throws IOException; 59 | 60 | /** 61 | * Attempts to parse a complete message head from the content of the 62 | * internal buffer. If the message in the input buffer is incomplete 63 | * this method will return null. 64 | * 65 | * @return HTTP message head, if available, null otherwise. 66 | * @throws IOException in case of an I/O error. 67 | * @throws HttpException in case the HTTP message is malformed or 68 | * violates the HTTP protocol. 69 | */ 70 | T parse() throws IOException, HttpException; 71 | 72 | } 73 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/protocol/NHttpResponseTrigger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.HttpResponse; 34 | 35 | /** 36 | * Callback interface to submit HTTP responses asynchronously. 37 | *

38 | * The {@link NHttpRequestHandler#handle(org.apache.http.HttpRequest, HttpResponse, NHttpResponseTrigger, org.apache.http.protocol.HttpContext)} 39 | * method does not have to submit a response immediately. It can defer 40 | * transmission of the HTTP response back to the client without blocking the 41 | * I/O thread by delegating the process of handling the HTTP request to a worker 42 | * thread. The worker thread in its turn can use the instance of 43 | * {@link NHttpResponseTrigger} passed as a parameter to submit a response as at 44 | * a later point of time once the response becomes available. 45 | * 46 | * @since 4.0 47 | * 48 | * @deprecated (4.2) use {@link HttpAsyncExchange} 49 | */ 50 | @Deprecated 51 | public interface NHttpResponseTrigger { 52 | 53 | /** 54 | * Submits a response to be sent back to the client as a result of 55 | * processing of the request. 56 | */ 57 | void submitResponse(HttpResponse response); 58 | 59 | /** 60 | * Reports a protocol exception thrown while processing the request. 61 | */ 62 | void handleException(HttpException ex); 63 | 64 | /** 65 | * Report an IOException thrown while processing the request. 66 | */ 67 | void handleException(IOException ex); 68 | 69 | } 70 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ssl/SSLSetupHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor.ssl; 29 | 30 | import javax.net.ssl.SSLEngine; 31 | import javax.net.ssl.SSLException; 32 | import javax.net.ssl.SSLSession; 33 | 34 | import org.apache.http.nio.reactor.IOSession; 35 | 36 | /** 37 | * Callback interface that can be used to customize various aspects of 38 | * the TLS/SSl protocol. 39 | * 40 | * @since 4.2 41 | */ 42 | public interface SSLSetupHandler { 43 | 44 | /** 45 | * Triggered when the SSL connection is being initialized. Custom handlers 46 | * can use this callback to customize properties of the {@link SSLEngine} 47 | * used to establish the SSL session. 48 | * 49 | * @param sslengine the SSL engine. 50 | * @throws SSLException if case of SSL protocol error. 51 | */ 52 | void initalize(SSLEngine sslengine) throws SSLException; 53 | 54 | /** 55 | * Triggered when the SSL connection has been established and initial SSL 56 | * handshake has been successfully completed. Custom handlers can use 57 | * this callback to verify properties of the {@link SSLSession}. 58 | * For instance this would be the right place to enforce SSL cipher 59 | * strength, validate certificate chain and do hostname checks. 60 | * 61 | * @param iosession the underlying IOSession for the SSL connection. 62 | * @param sslsession newly created SSL session. 63 | * @throws SSLException if case of SSL protocol error. 64 | */ 65 | void verify(IOSession iosession, SSLSession sslsession) throws SSLException; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpClientConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.HttpRequest; 34 | 35 | /** 36 | * Abstract non-blocking client-side HTTP connection interface. It can be used 37 | * to submit HTTP requests and asynchronously receive HTTP responses. 38 | * 39 | * @see NHttpConnection 40 | * 41 | * @since 4.0 42 | */ 43 | public interface NHttpClientConnection extends NHttpConnection { 44 | 45 | /** 46 | * Submits {@link HttpRequest} to be sent to the target server. 47 | * 48 | * @param request HTTP request 49 | * @throws IOException if I/O error occurs while submitting the request 50 | * @throws HttpException if the HTTP request violates the HTTP protocol. 51 | */ 52 | void submitRequest(HttpRequest request) throws IOException, HttpException; 53 | 54 | /** 55 | * Returns true if an HTTP request has been submitted to the 56 | * target server. 57 | * 58 | * @return true if an HTTP request has been submitted, 59 | * false otherwise. 60 | */ 61 | boolean isRequestSubmitted(); 62 | 63 | /** 64 | * Resets output state. This method can be used to prematurely terminate 65 | * processing of the outgoing HTTP request. 66 | */ 67 | void resetOutput(); 68 | 69 | /** 70 | * Resets input state. This method can be used to prematurely terminate 71 | * processing of the incoming HTTP response. 72 | */ 73 | void resetInput(); 74 | 75 | } 76 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/reactor/ListenerEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.reactor; 29 | 30 | import java.io.IOException; 31 | import java.net.SocketAddress; 32 | 33 | /** 34 | * ListenerEndpoint interface represents an endpoint used by an I/O reactor 35 | * to listen for incoming connection from remote clients. 36 | * 37 | * @since 4.0 38 | */ 39 | public interface ListenerEndpoint { 40 | 41 | /** 42 | * Returns the socket address of this endpoint. 43 | * 44 | * @return socket address. 45 | */ 46 | SocketAddress getAddress(); 47 | 48 | /** 49 | * Returns an instance of {@link IOException} thrown during initialization 50 | * of this endpoint or null, if initialization was successful. 51 | * 52 | * @return I/O exception object or null. 53 | */ 54 | IOException getException(); 55 | 56 | /** 57 | * Waits for completion of initialization process of this endpoint. 58 | * 59 | * @throws InterruptedException in case the initialization process was 60 | * interrupted. 61 | */ 62 | void waitFor() throws InterruptedException; 63 | 64 | /** 65 | * Determines if this endpoint has been closed and is no longer listens 66 | * for incoming connections. 67 | * 68 | * @return true if the endpoint has been closed, 69 | * false otherwise. 70 | */ 71 | boolean isClosed(); 72 | 73 | /** 74 | * Closes this endpoint. The endpoint will stop accepting incoming 75 | * connection. 76 | */ 77 | void close(); 78 | 79 | } 80 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/NHttpServerConnection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.HttpResponse; 34 | 35 | /** 36 | * Abstract non-blocking server-side HTTP connection interface. It can be used 37 | * to receive HTTP requests and asynchronously submit HTTP responses. 38 | * 39 | * @see NHttpConnection 40 | * 41 | * @since 4.0 42 | */ 43 | public interface NHttpServerConnection extends NHttpConnection { 44 | 45 | /** 46 | * Submits {link @HttpResponse} to be sent to the client. 47 | * 48 | * @param response HTTP response 49 | * 50 | * @throws IOException if I/O error occurs while submitting the response 51 | * @throws HttpException if the HTTP response violates the HTTP protocol. 52 | */ 53 | void submitResponse(HttpResponse response) throws IOException, HttpException; 54 | 55 | /** 56 | * Returns true if an HTTP response has been submitted to the 57 | * client. 58 | * 59 | * @return true if an HTTP response has been submitted, 60 | * false otherwise. 61 | */ 62 | boolean isResponseSubmitted(); 63 | 64 | /** 65 | * Resets output state. This method can be used to prematurely terminate 66 | * processing of the incoming HTTP request. 67 | */ 68 | void resetInput(); 69 | 70 | /** 71 | * Resets input state. This method can be used to prematurely terminate 72 | * processing of the outgoing HTTP response. 73 | */ 74 | void resetOutput(); 75 | 76 | } 77 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/NullRequestConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import java.io.IOException; 31 | import java.nio.ByteBuffer; 32 | 33 | import org.apache.http.HttpRequest; 34 | import org.apache.http.nio.ContentDecoder; 35 | import org.apache.http.nio.IOControl; 36 | import org.apache.http.protocol.HttpContext; 37 | 38 | class NullRequestConsumer implements HttpAsyncRequestConsumer { 39 | 40 | private final ByteBuffer buffer; 41 | private volatile boolean completed; 42 | 43 | NullRequestConsumer() { 44 | super(); 45 | this.buffer = ByteBuffer.allocate(2048); 46 | } 47 | 48 | public void requestReceived(final HttpRequest request) { 49 | } 50 | 51 | public void consumeContent( 52 | final ContentDecoder decoder, final IOControl ioctrl) throws IOException { 53 | int lastRead; 54 | do { 55 | this.buffer.clear(); 56 | lastRead = decoder.read(this.buffer); 57 | } while (lastRead > 0); 58 | } 59 | 60 | public void requestCompleted(final HttpContext context) { 61 | this.completed = true; 62 | } 63 | 64 | public void failed(final Exception ex) { 65 | this.completed = true; 66 | } 67 | 68 | public Object getResult() { 69 | return Boolean.valueOf(this.completed); 70 | } 71 | 72 | public Exception getException() { 73 | return null; 74 | } 75 | 76 | public void close() throws IOException { 77 | this.completed = true; 78 | } 79 | 80 | public boolean isDone() { 81 | return this.completed; 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/entity/ContentBufferEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.entity; 29 | 30 | import org.apache.http.Header; 31 | import org.apache.http.HttpEntity; 32 | import org.apache.http.annotation.NotThreadSafe; 33 | import org.apache.http.entity.BasicHttpEntity; 34 | import org.apache.http.nio.util.ContentInputBuffer; 35 | import org.apache.http.util.Args; 36 | 37 | /** 38 | * HTTP entity wrapper whose content is provided by a 39 | * {@link ContentInputBuffer}. 40 | * 41 | * @since 4.0 42 | */ 43 | @NotThreadSafe 44 | public class ContentBufferEntity extends BasicHttpEntity { 45 | 46 | private final HttpEntity wrappedEntity; 47 | 48 | /** 49 | * Creates new instance of ContentBufferEntity. 50 | * 51 | * @param entity the original entity. 52 | * @param buffer the content buffer. 53 | */ 54 | public ContentBufferEntity(final HttpEntity entity, final ContentInputBuffer buffer) { 55 | super(); 56 | Args.notNull(entity, "HTTP entity"); 57 | this.wrappedEntity = entity; 58 | setContent(new ContentInputStream(buffer)); 59 | } 60 | 61 | @Override 62 | public boolean isChunked() { 63 | return this.wrappedEntity.isChunked(); 64 | } 65 | 66 | @Override 67 | public long getContentLength() { 68 | return this.wrappedEntity.getContentLength(); 69 | } 70 | 71 | @Override 72 | public Header getContentType() { 73 | return this.wrappedEntity.getContentType(); 74 | } 75 | 76 | @Override 77 | public Header getContentEncoding() { 78 | return this.wrappedEntity.getContentEncoding(); 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/protocol/BasicAsyncRequestHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.HttpRequest; 34 | import org.apache.http.annotation.Immutable; 35 | import org.apache.http.protocol.HttpContext; 36 | import org.apache.http.protocol.HttpRequestHandler; 37 | import org.apache.http.util.Args; 38 | 39 | /** 40 | * Basic implementation of {@link HttpAsyncRequestHandler} that delegates 41 | * the process of request handling to a {@link HttpRequestHandler}. Please note 42 | * that this handler buffers request content in memory and should be used for 43 | * relatively small request messages. 44 | * 45 | * @since 4.2 46 | */ 47 | @Immutable 48 | public class BasicAsyncRequestHandler implements HttpAsyncRequestHandler { 49 | 50 | private final HttpRequestHandler handler; 51 | 52 | public BasicAsyncRequestHandler(final HttpRequestHandler handler) { 53 | super(); 54 | Args.notNull(handler, "Request handler"); 55 | this.handler = handler; 56 | } 57 | 58 | public HttpAsyncRequestConsumer processRequest(final HttpRequest request, 59 | final HttpContext context) { 60 | return new BasicAsyncRequestConsumer(); 61 | } 62 | 63 | public void handle( 64 | final HttpRequest request, 65 | final HttpAsyncExchange httpexchange, 66 | final HttpContext context) throws HttpException, IOException { 67 | this.handler.handle(request, httpexchange.getResponse(), context); 68 | httpexchange.submitResponse(); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/test/java/org/apache/http/impl/nio/TestContentChannel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | package org.apache.http.impl.nio; 28 | 29 | import static org.junit.Assert.assertTrue; 30 | import static org.mockito.Mockito.times; 31 | import static org.mockito.Mockito.verify; 32 | 33 | import java.nio.ByteBuffer; 34 | 35 | import org.apache.http.nio.ContentDecoder; 36 | import org.apache.http.nio.ContentDecoderChannel; 37 | import org.apache.http.nio.ContentEncoder; 38 | import org.apache.http.nio.ContentEncoderChannel; 39 | import org.junit.After; 40 | import org.junit.Before; 41 | import org.junit.Test; 42 | import org.mockito.Mock; 43 | import org.mockito.MockitoAnnotations; 44 | 45 | public class TestContentChannel { 46 | 47 | @Mock private ContentDecoder decoder; 48 | @Mock private ContentEncoder encoder; 49 | @Mock private ByteBuffer bb; 50 | 51 | @Before 52 | public void setUp() throws Exception { 53 | MockitoAnnotations.initMocks(this); 54 | } 55 | 56 | @After 57 | public void tearDown() throws Exception { 58 | } 59 | 60 | @Test 61 | public void testContentDecoder() throws Exception { 62 | final ContentDecoderChannel cdc = new ContentDecoderChannel(decoder); 63 | 64 | cdc.read(bb); 65 | verify(decoder, times(1)).read(bb); 66 | 67 | assertTrue(cdc.isOpen()); 68 | 69 | cdc.close(); 70 | } 71 | 72 | @Test 73 | public void testContentEncoder() throws Exception { 74 | final ContentEncoderChannel cec = new ContentEncoderChannel(encoder); 75 | 76 | cec.write(bb); 77 | verify(encoder, times(1)).write(bb); 78 | 79 | assertTrue(cec.isOpen()); 80 | 81 | cec.close(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/protocol/EventListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import java.io.IOException; 31 | 32 | import org.apache.http.HttpException; 33 | import org.apache.http.nio.NHttpConnection; 34 | 35 | /** 36 | * Event listener used by the HTTP protocol layer to report fatal exceptions 37 | * and events that may need to be logged using a logging toolkit. 38 | * 39 | * @since 4.0 40 | * 41 | * @deprecated (4.2) do not use 42 | */ 43 | @Deprecated 44 | public interface EventListener { 45 | 46 | /** 47 | * Triggered when an I/O error caused a connection to be terminated. 48 | * 49 | * @param ex the I/O exception. 50 | * @param conn the connection. 51 | */ 52 | void fatalIOException(IOException ex, NHttpConnection conn); 53 | 54 | /** 55 | * Triggered when an HTTP protocol error caused a connection to be 56 | * terminated. 57 | * 58 | * @param ex the protocol exception. 59 | * @param conn the connection. 60 | */ 61 | void fatalProtocolException(HttpException ex, NHttpConnection conn); 62 | 63 | /** 64 | * Triggered when a new connection has been established. 65 | * 66 | * @param conn the connection. 67 | */ 68 | void connectionOpen(NHttpConnection conn); 69 | 70 | /** 71 | * Triggered when a connection has been terminated. 72 | * 73 | * @param conn the connection. 74 | */ 75 | void connectionClosed(NHttpConnection conn); 76 | 77 | /** 78 | * Triggered when a connection has timed out. 79 | * 80 | * @param conn the connection. 81 | */ 82 | void connectionTimeout(NHttpConnection conn); 83 | 84 | } 85 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java-deprecated/org/apache/http/nio/protocol/HttpAsyncRequestExecutionHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.protocol; 29 | 30 | import org.apache.http.ConnectionReuseStrategy; 31 | import org.apache.http.protocol.HttpContext; 32 | import org.apache.http.protocol.HttpProcessor; 33 | 34 | /** 35 | * HttpAsyncRequestExecutionHandler represents a callback interface 36 | * that combines functionality of {@link HttpAsyncRequestProducer} and 37 | * {@link HttpAsyncResponseConsumer} and is capable of handling logically 38 | * related series of HTTP request / response exchanges. 39 | * 40 | * @param the result type of request execution. 41 | * @since 4.2 42 | * 43 | * @deprecated use {@link HttpAsyncClientExchangeHandler} 44 | */ 45 | @Deprecated 46 | public interface HttpAsyncRequestExecutionHandler 47 | extends HttpAsyncRequestProducer, HttpAsyncResponseConsumer { 48 | 49 | /** 50 | * Returns shared {@link HttpContext} instance. 51 | * 52 | * @return HTTP context 53 | */ 54 | HttpContext getContext(); 55 | 56 | /** 57 | * Returns {@link HttpProcessor} implementation to be used to process 58 | * HTTP request and response messages for protocol compliance. 59 | * 60 | * @return HTTP protocol processor. 61 | */ 62 | HttpProcessor getHttpProcessor(); 63 | 64 | /** 65 | * Returns {@link ConnectionReuseStrategy} implementation to be used 66 | * to determine whether or not the underlying connection can be kept alive 67 | * after a particular HTTP request / response exchange. 68 | * 69 | * @return connection re-use strategy. 70 | */ 71 | ConnectionReuseStrategy getConnectionReuseStrategy(); 72 | 73 | } 74 | -------------------------------------------------------------------------------- /modules/httpcore-nio/src/main/java/org/apache/http/nio/params/NIOReactorPNames.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================================== 3 | * Licensed to the Apache Software Foundation (ASF) under one 4 | * or more contributor license agreements. See the NOTICE file 5 | * distributed with this work for additional information 6 | * regarding copyright ownership. The ASF licenses this file 7 | * to you under the Apache License, Version 2.0 (the 8 | * "License"); you may not use this file except in compliance 9 | * with the License. You may obtain a copy of the License at 10 | * 11 | * http://www.apache.org/licenses/LICENSE-2.0 12 | * 13 | * Unless required by applicable law or agreed to in writing, 14 | * software distributed under the License is distributed on an 15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | * KIND, either express or implied. See the License for the 17 | * specific language governing permissions and limitations 18 | * under the License. 19 | * ==================================================================== 20 | * 21 | * This software consists of voluntary contributions made by many 22 | * individuals on behalf of the Apache Software Foundation. For more 23 | * information on the Apache Software Foundation, please see 24 | * . 25 | * 26 | */ 27 | 28 | package org.apache.http.nio.params; 29 | 30 | /** 31 | * Parameter names for I/O reactors. 32 | * 33 | * @since 4.0 34 | * 35 | * @deprecated (4.2) use {@link org.apache.http.impl.nio.reactor.IOReactorConfig} 36 | */ 37 | @Deprecated 38 | public interface NIOReactorPNames { 39 | 40 | /** 41 | * Determines the size of the content input/output buffers used 42 | * to buffer data while receiving or transmitting HTTP messages. 43 | *

44 | * This parameter expects a value of type {@link Integer}. 45 | *

46 | */ 47 | public static final String CONTENT_BUFFER_SIZE = "http.nio.content-buffer-size"; 48 | 49 | /** 50 | * Determines the time interval in milliseconds at which the 51 | * I/O reactor wakes up to check for timed out sessions and session requests. 52 | *

53 | * This parameter expects a value of type {@link Long}. 54 | *

55 | */ 56 | public static final String SELECT_INTERVAL = "http.nio.select-interval"; 57 | 58 | /** 59 | * Determines the grace period the I/O reactors are expected to block 60 | * waiting for individual worker threads to terminate cleanly. 61 | *

62 | * This parameter expects a value of type {@link Long}. 63 | *

64 | */ 65 | public static final String GRACE_PERIOD = "http.nio.grace-period"; 66 | 67 | /** 68 | * Determines whether interestOps() queueing is enabled for the I/O reactors. 69 | *

70 | * This parameter expects a value of type {@link Boolean}. 71 | *

72 | * 73 | * @since 4.1 74 | */ 75 | public static final String INTEREST_OPS_QUEUEING = "http.nio.interest-ops-queueing"; 76 | 77 | } 78 | --------------------------------------------------------------------------------