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

com.iteaj.iot.client.http.HttpRequestMessage Maven / Gradle / Ivy

package com.iteaj.iot.client.http;

import com.iteaj.iot.client.ClientMessage;

import java.util.HashMap;
import java.util.Map;

public class HttpRequestMessage extends ClientMessage {

    private String url;

    private long timeout;

    /**
     * http使用的方法, 只支持两种
     * @see HttpMethod#Get
     * @see HttpMethod#Post
     */
    private HttpMethod method;

    /**
     * http请求的请求头
     */
    private Map heads;
    /**
     * 请求参数
* 1. 如果是get请求, 将作为查询参数的一部分, 连接到url后面 * 2. 如果是post请求, 将作为body */ private Map param; public HttpRequestMessage(String url, HttpMethod method) { this(url, method, null); } public HttpRequestMessage(String url, HttpMethod method, Map param) { super(new byte[]{0}); this.url = url; this.param = param; this.method = method; } public static HttpRequestMessage get(String url) { return get(url, new HashMap<>()); } public static HttpRequestMessage get(String url, Map param) { return new HttpRequestMessage(url, HttpMethod.Get, param); } public static HttpRequestMessage post(String url) { return new HttpRequestMessage(url, HttpMethod.Post, new HashMap<>()); } public static HttpRequestMessage post(String url, Map param) { return new HttpRequestMessage(url, HttpMethod.Post, param); } @Override public int length() { throw new UnsupportedOperationException("不支持的操作"); } @Override public byte[] getMessage() { throw new UnsupportedOperationException("不支持的操作"); } @Override public MessageHead getHead() { throw new UnsupportedOperationException("不支持的操作"); } @Override public MessageBody getBody() { throw new UnsupportedOperationException("不支持的操作"); } public HttpMethod getMethod() { return method; } public Map getParam() { return param; } public HttpRequestMessage addParam(String key, String value) { if(this.param == null) { this.param = new HashMap<>(); } this.param.put(key, value); return this; } public Map getHeads() { return heads; } public HttpRequestMessage addHeader(String key, String val) { if(this.heads == null) { this.heads = new HashMap<>(); } this.heads.put(key, val); return this; } public HttpRequestMessage setHeads(Map heads) { this.heads = heads; return this; } public String getUrl() { return url; } public HttpRequestMessage setUrl(String url) { this.url = url; return this; } public long getTimeout() { return timeout; } public HttpRequestMessage setTimeout(long timeout) { this.timeout = timeout; return this; } @Override protected MessageHead doBuild(byte[] message) { throw new UnsupportedOperationException("不支持此操作"); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy