Giter Club home page Giter Club logo

matrix-http's Introduction

matrix-http

License Maven Central

这个项目干嘛的?

httpclient创建和管理的工具类。

怎么用

添加依赖:


<dependency>
  <groupId>io.github.forezp</groupId>
  <artifactId>matrix-http-starter</artifactId>
  <version>${version}</version>
</dependency>

使用

在配置文件中添加:

http.sync.enable=true
http.async.enable=true

httpclient的配置如下,如果不填,即为默认值:

   public static final String HTTPCLIENT_CONNCT_TIMEOUT = "httpclient.connect.timeout";
    public static final String HTTPCLIENT_CONNCT_TIMEOUT_DEFAULT = "5000";
    public static final String HTTPCLIENT_CONNCT_REQUEST_TIMEOUT = "httpclient.connect.request.timeout";
    public static final String HTTPCLIENT_CONNCT_REQUEST_TIMEOUT_DEFAULT = "5000";
    public static final String HTTPCLIENT_SOCKET_TIMEOUT = "httpclient.socket.timeout";
    public static final String HTTPCLIENT_SOCKET_TIMEOUT_DEFAULT = "5000";
    public static final String HTTPCLIENT_SEDBUFSIZE = "httpclient.send.bufsize";
    public static final String HTTPCLIENT_SEDBUFSIZE_DEFAULT = "65536";
    public static final String HTTPCLIENT_RCV_BUFSIZE = "httpclient.rcv.bufsize";
    public static final String HTTPCLIENT_RCV_BUFSIZE_DEFAULT = "65536";
    public static final String HTTPCLIENT_BACK_LOG_SIZE = "httpclient.back.logszie";
    public static final String HTTPCLIENT_BACK_LOG_SIZE_DEFAULT = "128";
    public static final String HTTPCLIENT_MAX_TOTAL = "httpclient.max.total";
    public static final String HTTPCLIENT_MAX_TOTAL_DEFAULT = "64";

使用:


   package io.github.forezp;
   
   import com.alibaba.fastjson.JSON;
   import com.fasterxml.jackson.annotation.JsonAlias;
   import org.springframework.beans.factory.annotation.Autowired;
   import org.springframework.boot.SpringApplication;
   import org.springframework.boot.autoconfigure.SpringBootApplication;
   import org.springframework.web.bind.annotation.GetMapping;
   import org.springframework.web.bind.annotation.RestController;
   
   import java.util.HashMap;
   import java.util.Map;
   
   @SpringBootApplication
   @RestController
   public class MatrixHttpExampleApplication {
   
       public static void main(String[] args) {
           SpringApplication.run(MatrixHttpExampleApplication.class, args);
       }
   
       @Autowired
       ApacheAsyncClientExecutor httpAsyncClientExecutor;
       @Autowired
       ApacheSyncClientExecutor httpClientExecutor;
   
       @GetMapping("/test")
       public String test() {
   
           httpClientExecutor.get("https://www.baidu.com", new ResonseCallBack() {
               @Override
               public void completed(int httpCode, String result) {
                   System.out.println(result);
               }
   
               @Override
               public void failed(Exception e) {
   
               }
           });
           return "ok";
       }
   
       @GetMapping("/test2")
       public Keyswords testJieba() {
           String url = "http://fangzhipeng.com/test";
           Map<String, Object> paras = new HashMap<>();
           paras.put("title", "詹姆斯带队湖人登第一");
           paras.put("content", "詹姆斯给力,浓眉给力");
           ResonseCallBack.DEAULT deault = new ResonseCallBack.DEAULT();
           httpClientExecutor.postForm(url, paras, deault);
           Keyswords keyswords = JSON.parseObject(deault.getData(), Keyswords.class);
           System.out.println(JSON.toJSONString(keyswords));
           return keyswords;
       }
   
   
   }


matrix-http's People

Contributors

forezp avatar

Stargazers

June avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.