001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.http.client.support;
018
019import java.io.IOException;
020import java.net.URI;
021
022import org.apache.commons.logging.Log;
023
024import org.springframework.http.HttpLogging;
025import org.springframework.http.HttpMethod;
026import org.springframework.lang.Nullable;
027import org.springframework.util.Assert;
028
029/**
030 * Base class for {@link org.springframework.web.client.AsyncRestTemplate}
031 * and other HTTP accessing gateway helpers, defining common properties
032 * such as the {@link org.springframework.http.client.AsyncClientHttpRequestFactory}
033 * to operate on.
034 *
035 * <p>Not intended to be used directly. See
036 * {@link org.springframework.web.client.AsyncRestTemplate}.
037 *
038 * @author Arjen Poutsma
039 * @since 4.0
040 * @see org.springframework.web.client.AsyncRestTemplate
041 * @deprecated as of Spring 5.0, with no direct replacement
042 */
043@Deprecated
044public class AsyncHttpAccessor {
045
046        /** Logger available to subclasses. */
047        protected final Log logger = HttpLogging.forLogName(getClass());
048
049        @Nullable
050        private org.springframework.http.client.AsyncClientHttpRequestFactory asyncRequestFactory;
051
052
053        /**
054         * Set the request factory that this accessor uses for obtaining {@link
055         * org.springframework.http.client.ClientHttpRequest HttpRequests}.
056         */
057        public void setAsyncRequestFactory(
058                        org.springframework.http.client.AsyncClientHttpRequestFactory asyncRequestFactory) {
059
060                Assert.notNull(asyncRequestFactory, "AsyncClientHttpRequestFactory must not be null");
061                this.asyncRequestFactory = asyncRequestFactory;
062        }
063
064        /**
065         * Return the request factory that this accessor uses for obtaining {@link
066         * org.springframework.http.client.ClientHttpRequest HttpRequests}.
067         */
068        public org.springframework.http.client.AsyncClientHttpRequestFactory getAsyncRequestFactory() {
069                Assert.state(this.asyncRequestFactory != null, "No AsyncClientHttpRequestFactory set");
070                return this.asyncRequestFactory;
071        }
072
073        /**
074         * Create a new {@link org.springframework.http.client.AsyncClientHttpRequest} via this template's
075         * {@link org.springframework.http.client.AsyncClientHttpRequestFactory}.
076         * @param url the URL to connect to
077         * @param method the HTTP method to execute (GET, POST, etc.)
078         * @return the created request
079         * @throws IOException in case of I/O errors
080         */
081        protected org.springframework.http.client.AsyncClientHttpRequest createAsyncRequest(URI url, HttpMethod method)
082                        throws IOException {
083
084                org.springframework.http.client.AsyncClientHttpRequest request =
085                                getAsyncRequestFactory().createAsyncRequest(url, method);
086                if (logger.isDebugEnabled()) {
087                        logger.debug("Created asynchronous " + method.name() + " request for \"" + url + "\"");
088                }
089                return request;
090        }
091
092}