All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mycomm.YesHttp.core.Request Maven / Gradle / Ivy

There is a newer version: 1.0.53
Show newest version
/*
 * Copyright 2018 jw362j.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.mycomm.YesHttp.core;

import java.net.URLConnection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author jw362j
 */
public abstract class Request {

    public static final String DEFAULT_PARAMS_ENCODING = "UTF-8";
    protected Map params = new HashMap();
    protected Map headers = new HashMap();

    /**
     * Supported request methods.
     */
    public interface MethodA {

        short DEPRECATED_GET_OR_POST = -1;
        short GET = 0;
        short POST = 1;
        short PUT = 2;
        short DELETE = 3;
        short HEAD = 4;
        short OPTIONS = 5;
        short TRACE = 6;
        short PATCH = 7;
    }

    public interface YesLog {

        public void w(String text);

        public void e(String text);

        public void d(String text);

        public void i(String text);

        public void v(String text);
    }

    public interface HttpObserver {

        public void Observe(URLConnection connection);
    }

    public interface Protocol {

        short HTTP = 0;
        short HTTPS = 1;
        short HTTPS_IGNORE_CERT = 2;
    }

    private final HttpMethod mMethod;
    /**
     * URL of this request.
     */
    private final String mUrl;
    private final Response.Listener response;
    private final Response.ErrorListener errorListener;
    private final HttpObserver httpObserver;
    private final YesLog log;
    private final short protocol;

    public Request(String mUrl, Response.Listener response) {
        this(HttpMethod.GET, mUrl, response, null, null, (short) 0);
    }

    public Request(String mUrl, Response.Listener response, Response.ErrorListener errorListener) {
        this(HttpMethod.GET, mUrl, response, errorListener, null, (short) 0);
    }

    public Request(HttpMethod mMethod, String mUrl, Response.Listener response, Response.ErrorListener errorListener, YesLog log, short protocol) {
        this(mMethod, mUrl, response, null, errorListener, log, protocol);
    }

    public Request(HttpMethod method, String mUrl, Response.Listener response, HttpObserver observer, Response.ErrorListener errorListener, YesLog log, short protocol) {
        this.mMethod = method;
        this.mUrl = mUrl;
        this.response = response;
        this.errorListener = errorListener;
        this.log = log;
        this.protocol = protocol;
        this.httpObserver = observer;
    }

    public YesLog getLog() {
        return log;
    }

    public abstract void getParams(Map requestData);

    public abstract void getHeaders(Map headers);
    
    public abstract void processResponseHeaders(Map> headers);

    public abstract int getReadTimeout();

    public abstract int getVersion();

    public abstract int getConnectTimeout();

    public abstract ResponseCodeHandler getCodeHandler();

    public abstract MyTrustManager getTrustManager();

    public abstract boolean useGzip();

    public String getmUrl() {
        return mUrl;
    }

    public HttpMethod getmMethod() {
        return mMethod;
    }

    public short getProtocol() {
        return protocol;
    }

    public Response.Listener getResponse() {
        return response;
    }

    public Response.ErrorListener getErrorListener() {
        return errorListener;
    }

    public HttpObserver getHttpObserver() {
        return httpObserver;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy