http请求忽略证书、单向认证、双向认证、连接池范例(httpclient 4.3.x以上版本)

2023-11-09

目录:
  • 加载证书单向认证
  • 忽略证书
  • 双向认证
  • 连接池
加载证书单向认证

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class Httpclient43x {
    /********************* 4.3.x *****************************/
    public void sendMessage() throws Exception {
        CloseableHttpClient httpclient = null;
        HttpGet httpget = null;
        CloseableHttpResponse response = null;
        try {
            KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
            FileInputStream instream = new FileInputStream(new File("d:\\tomcat.keystore"));
            try {
                // 加载keyStore d:\\tomcat.keystore
                trustStore.load(instream, "123456".toCharArray());
            } catch (CertificateException e) {
                e.printStackTrace();
            } finally {
                try {
                    instream.close();
                } catch (Exception ignore) {
                }
            }
            // 相信自己的CA和所有自签名的证书.SSLContexts 4.3.x之后提供
            SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustStore, new TrustSelfSignedStrategy()).build();
            // 可选("SSLv3", "TLSv1", "TLSv1.2")
            SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"}, null,
                    SSLConnectionSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
            httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build();
            // 创建http请求(get方式)
            httpget = new HttpGet("https://localhost:8080/test");
            response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
                System.out.println(EntityUtils.toString(entity));
                EntityUtils.consume(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (response != null) {
                response.close();
            }
            if (httpget != null) {
                httpget.releaseConnection();
            }
            if (httpclient != null) {
                httpclient.close();//等价shutdown
            }
        }
    }
忽略证书
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class Httpclient43x {
    /********************* 4.3.x *****************************/
    public void sendMessage() throws Exception {
        CloseableHttpClient httpclient = null;
        HttpGet httpget = null;
        CloseableHttpResponse response = null;
        try {
            SSLConnectionSocketFactory sslsf2 = new SSLConnectionSocketFactory(ignoreSSL(),
                    SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            httpclient = HttpClients.custom().setSSLSocketFactory(sslsf2).build();
            // 创建http请求(get方式)
            httpget = new HttpGet("https://localhost:8080/test");
            response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
                System.out.println(EntityUtils.toString(entity));
                EntityUtils.consume(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (response != null) {
                response.close();
            }
            if (httpget != null) {
                httpget.releaseConnection();
            }
            if (httpclient != null) {
                httpclient.close();//等价shutdown
            }
        }
    }
    TLS 和ssl区别https://blog.csdn.net/adrian169/article/details/9164385
    private static SSLContext ignoreSSL() {
        try {
            SSLContext sslContext = SSLContext.getInstance("SSLv3");
            sslContext.init(null, new TrustManager[]{truseAllManager}, null);
            return sslContext;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static TrustManager truseAllManager = new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
        public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }
        public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }
    };
}
双向认证
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
/**
 * 4.3版本双向认证
 */
public class HttpTwoWay2 {
    public static void main(String[] args) throws Exception {
        KeyStore keyStore = KeyStore.getInstance("PKCS12");
        keyStore.load(new FileInputStream(new File("C:\\Users\\Administrator\\Desktop\\jiaoyiping.p12")), "123456".toCharArray());
        SSLContext sslcontext = SSLContexts.custom()
                //加载服务端提供的truststore(如果服务器提供truststore的话就不用忽略对服务器端证书的校验了)
                .loadTrustMaterial(new File("D:\\truststore.jks"), "123456".toCharArray(), new TrustSelfSignedStrategy())
                .loadKeyMaterial(keyStore, "cmcc".toCharArray())//loadKeyMaterial()重载方法是加载客户端证书用的
                .build();
        SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(
                sslcontext,
                new String[]{"TLSv1"},//new String[]{"SSLv2Hello", "SSLv3", "TLSv1", "TLSv1.2"}
                null,
                SSLConnectionSocketFactory.getDefaultHostnameVerifier());
        CloseableHttpClient httpclient = null;
        HttpGet httpget = null;
        CloseableHttpResponse response = null;
        try {
            httpclient = HttpClients.custom().setSSLSocketFactory(sslConnectionSocketFactory).build();
            httpget = new HttpGet("https://10.2.5.116/PnsReceiver/ReceiveMessage");
            System.out.println("Executing request " + httpget.getRequestLine());
            response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            System.out.println(response.getStatusLine());
            System.out.println(entity.getContent());
            EntityUtils.consume(entity);
        } finally {
            if (response != null) {
                response.close();
            }
            if (httpget != null) {
                httpget.releaseConnection();
            }
            if (httpclient != null) {
                httpclient.close();
            }
        }
    }
}
连接池

写法一:


import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContexts;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.util.EntityUtils;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
public class Httpclient43x {
    /********************* 4.3.x *****************************/
    static CloseableHttpClient httpclient;
    private static CloseableHttpClient getHttpclient(){
        if(httpclient != null) {
            return httpclient;
        } else {
            synchronized (Httpclient43x.class){
                if(httpclient !=null) {
                    return httpclient;
                } else {
                    //忽略证书校验
                    SSLConnectionSocketFactory sslsf2 = new SSLConnectionSocketFactory(ignoreSSL(),
                            SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
                    //连接池写法
                    Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create()
                            .register("http", new PlainConnectionSocketFactory())
                            .register("https", sslsf2)
                            .build();
                    PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
                    cm.setMaxTotal(1000);
                    cm.setDefaultMaxPerRoute(200);
                    httpclient = HttpClients.custom().setConnectionManager(cm).build();
                    return httpclient;
                }
            }
        }
    }
    public static void sendMessage() throws Exception {
        HttpGet httpget = null;
        CloseableHttpResponse response = null;
        try {
            // 创建http请求(get方式)
            httpget = new HttpGet("https://localhost:8443/myDemo/Ajax/serivceJ.action");
            response = getHttpclient().execute(httpget);
            HttpEntity entity = response.getEntity();
            System.out.println("----------------------------------------");
            System.out.println(response.getStatusLine());
            if (entity != null) {
                System.out.println("Response content length: " + entity.getContentLength());
                System.out.println(EntityUtils.toString(entity));
                EntityUtils.consume(entity);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (response != null) {
                response.close();
            }
            if (httpget != null) {
                httpget.releaseConnection();
            }
            // 若采用连接池写法不要关闭httpclient
        }
    }
    TLS 和ssl区别https://blog.csdn.net/adrian169/article/details/9164385
    private static SSLContext ignoreSSL() {
        try {
            SSLContext sslContext = SSLContext.getInstance("SSLv3");
            sslContext.init(null, new TrustManager[]{truseAllManager}, null);
            return sslContext;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
    public static TrustManager truseAllManager = new X509TrustManager() {
        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
        public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }
        public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                throws CertificateException {
        }
    };
}

连接池写法二:


import com.google.common.base.Optional;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.LayeredConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.apache.http.message.BasicHeaderElementIterator;
import org.apache.http.protocol.HTTP;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class HttpClient4Util {
    private final static Logger logger = LoggerFactory
            .getLogger(HttpClient4Util.class);
    private CloseableHttpClient httpclient;
    private RequestConfig requestConfig;
    private PoolingHttpClientConnectionManager connManager;
    private static HttpClient4Util httpClient4UtilNew;
    private volatile boolean shutdown;
    public synchronized static HttpClient4Util getInstance() throws Exception {
        if (httpClient4UtilNew == null) {
            httpClient4UtilNew = new HttpClient4Util();
            httpClient4UtilNew.init();
        }
        return httpClient4UtilNew;
    }
    private HttpClient4Util() {
    }
    /**
     * 构造函数
     */
    public void init() throws NoSuchAlgorithmException, KeyManagementException {
        SSLContext sslCtx = SSLContext.getInstance("TLS");
        X509TrustManager trustManager = new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                return null;
            }
            public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                    throws CertificateException {
            }
            public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                    throws CertificateException {
            }
        };
        sslCtx.init(null, new TrustManager[]{trustManager}, null);
        LayeredConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
                sslCtx, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
        RegistryBuilder<ConnectionSocketFactory> registryBuilder = RegistryBuilder
                .<ConnectionSocketFactory>create();
        ConnectionSocketFactory plainSocketFactory = new PlainConnectionSocketFactory();
        registryBuilder.register("http", plainSocketFactory);
        registryBuilder.register("https", sslSocketFactory);
        Registry<ConnectionSocketFactory> registry = registryBuilder.build();
        // 设置连接管理器
        connManager = new PoolingHttpClientConnectionManager(registry);
        // 设置最大连接数
        connManager.setMaxTotal(200);
        // 设置每个路由基础的连接
        connManager.setDefaultMaxPerRoute(20);
        // 连接保持活跃策略
        ConnectionKeepAliveStrategy myStrategy = new ConnectionKeepAliveStrategy() {
            @Override
            public long getKeepAliveDuration(HttpResponse response,
                                             HttpContext context) {
                // 获取'keep-alive'HTTP报文头
                HeaderElementIterator it = new BasicHeaderElementIterator(
                        response.headerIterator(HTTP.CONN_KEEP_ALIVE));
                while (it.hasNext()) {
                    HeaderElement he = it.nextElement();
                    String param = he.getName();
                    String value = he.getValue();
                    if (null != value && "timeout".equalsIgnoreCase(param)) {
                        try {
                            return Long.parseLong(value) * 1000;
                        } catch (NumberFormatException ignore) {
                        }
                    }
                }
                // 保持20秒活跃
                return 20 * 1000;
            }
        };
        httpclient = HttpClientBuilder.create().setConnectionManager(
                connManager).setKeepAliveStrategy(myStrategy).build();
        shutdown = false;
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (!shutdown) {
                    try {
                        synchronized (this) {
                            wait(500);
                            // 关闭过期的连接
                            connManager.closeExpiredConnections();
                            // 关闭超过40秒的空闲连接
                            connManager.closeIdleConnections(40, TimeUnit.SECONDS);
                        }
                    } catch (Exception e) {
                        logger.error(e.getLocalizedMessage(), e);
                    }
                }
            }
        }).start();
    }
    /**
     * 基本的Get请求
     *
     * @param url            请求URL
     * @param nameValuePairs 请求List<NameValuePair>查询参数
     */
    public byte[] doGet(String url, List<NameValuePair> nameValuePairs) {
        CloseableHttpResponse response = null;
        HttpGet httpget = new HttpGet();
        try {
            URIBuilder builder = new URIBuilder(url);
            // 填入查询参数
            if (nameValuePairs != null && !nameValuePairs.isEmpty()) {
                builder.setParameters(nameValuePairs);
            }
            httpget.setURI(builder.build());
            httpget.setConfig(requestConfig);
            response = httpclient.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                return EntityUtils.toByteArray(entity);
            }
        } catch (Exception e) {
            logger.error("http 请求异常", e);
        } finally {
            if (response != null) {
                try {
                    response.close();
                } catch (IOException e) {
                    logger.error("释放连接异常", e);
                }
            }
        }
        return null;
    }
    /**
     *
     * @param url
     * @param queryParams
     * @param formParams
     * @return
     */
    public byte[] doPost(String url, Map<String, String> heard, List<NameValuePair> queryParams, List<NameValuePair> formParams, String content,String  charset, int timeout) {
        if (StringUtils.isBlank(url)) {
            return null;
        }
        CloseableHttpResponse response = null;
        HttpPost httppost = new HttpPost();
        try {
            URIBuilder builder = new URIBuilder(url);
            // 填入查询参数
            if (CollectionUtils.isNotEmpty(queryParams)) {
                builder.setParameters(queryParams);
            }
            httppost.setURI(builder.build());
            timeout = Optional.fromNullable(timeout).or(60000);
            requestConfig = RequestConfig.custom()
                    .setConnectTimeout(timeout).setSocketTimeout(
                            timeout).build();
            httppost.setConfig(requestConfig);
            if (null != heard) {
                for (String key : heard.keySet()) {
                    httppost.setHeader(key, heard.get(key));
                }
            }
            if (CollectionUtils.isNotEmpty(formParams)) {
                httppost.setEntity(new UrlEncodedFormEntity(formParams, charset));
            }
            if (StringUtils.isNotBlank(content)) {
                httppost.setEntity(new StringEntity(content, charset));
            }
            response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            int stateCode = response.getStatusLine().getStatusCode();
            if (HttpStatus.SC_OK != stateCode) {
                logger.error("非正常响应[" + stateCode + "]", new String(EntityUtils.toByteArray(entity), charset));
                return null;
            }
            if (entity != null) {
                return EntityUtils.toByteArray(entity);
            }
        } catch (Exception e) {
            logger.error("http请求异常", e);
        } finally {
            httppost.releaseConnection();
            if (response != null) {
                try {
                    response.close();
                } catch (IOException e) {
                    logger.error("释放连接异常", e);
                }
            }
        }
        return null;
    }
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

http请求忽略证书、单向认证、双向认证、连接池范例(httpclient 4.3.x以上版本) 的相关文章

  • 如何在 Openfire 中使用 smack

    你好 我计划开发一个可以连接到 gtalk facebook 等的聊天客户端 我决定将 smack API 与 openfire 一起使用 但我需要很少的指导来了解如何将它与 openfire 服务器一起使用 openfire 是否提供了基
  • 如何使用 JAVA 代码以编程方式捕获线程转储?

    我想通过 java 代码生成线程转储 我尝试使用 ThreadMXBean 为此 但我没有以正确的格式获得线程转储 因为我们正在使用jstack命令 请任何人提供一些帮助 他们是否有其他方式获取线程转储 使用任何其他 API 我想要的线程转
  • 将SQL数据引入jquery availabletag

    我正在尝试制作自动完成文本框 但如何将 SQL 数据包含到 jquery 可用标记并循环它 我无法根据以下代码执行该功能 任何帮助 将不胜感激 谢谢 这是我的预期输出 预期结果演示 http jsfiddle net VvETA 71 jq
  • Reactive Spring 不支持 HttpServletRequest 作为 REST 端点中的参数?

    我创建了一个 RestController 如下所示 RestController public class GreetingController RequestMapping value greetings method RequestM
  • 在 Struts 2 中传递 URL 参数而不使用查询字符串

    我想使用类似的 URL host ActionName 123 abc 而不是像这样传递查询字符串 host ActionName parm1 123 parm2 abc 我怎样才能在 Struts 2 中做到这一点 我按照下面的方法做了
  • tomcat 7.0.50 java websocket 实现给出 404 错误

    我正在尝试使用 Java Websocket API 1 0 JSR 356 中指定的带注释端点在 tomcat 7 0 50 上实现 websocket 以下是我如何对其进行编码的简要步骤 1 使用 ServerEndpoint注解编写w
  • 如何检测图像是否像素化

    之前有人在 SO 上提出过这样的问题 在Python中检测像素化图像 https stackoverflow com questions 12942365 detecting a pixelated image in python还有关于q
  • http和https在编程中有什么区别[关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我只知道 s 代表 安全 用户永远不
  • 从直方图计算平均值和百分位数?

    我编写了一个计时器 可以测量任何多线程应用程序中特定代码的性能 在下面的计时器中 它还会在地图中填充花费了 x 毫秒的调用次数 我将使用这张图作为我的直方图的一部分来进行进一步的分析 例如调用花费了这么多毫秒的百分比等等 public st
  • 使用 JSON 的 Pentaho HTTP Post

    我是 Pentaho 的新手 我正在尝试执行以下工作流程 从数据库中读取一堆行 做一些转换 将它们以 JSON 格式发布到 REST Web 服务 我已经使用输入步骤和 Json 输出步骤解决了前两个问题 但是 我在执行最后一步时遇到两个问
  • Eclipse - 安装新的 JRE (Java SE 8 1.8.0)

    我正在尝试安装 Java 8 到目前为止我所做的 安装最新版本的 Eclipse 下载并安装 Java SE 运行时环境 8http www oracle com technetwork java javase downloads jre8
  • 我们如何测试包私有类?

    我正在看书Effective Java in Item 13 Minimize the accessibility of classes and members 它提到 为了方便测试 您可能想让类 接口或成员更易于访问 这在某种程度上是好的
  • JAVA中遍历JSON数据

    我是 JSON 新手 我使用 HTTPUrlConnections 并在 JAVA 程序中获得一些响应 响应数据将类似于 data id 1 userId 1 name ABC modified 2014 12 04 created 201
  • 避免 Java 中的重复导入:继承导入?

    有没有办法 继承 导入 Example 常见枚举 public enum Constant ONE TWO THREE 使用此枚举的基类 public class Base protected void register Constant
  • Lombok @Builder 不创建不可变对象?

    在很多网站上 我看到 lombok Builder 可以用来创建不可变的对象 https www baeldung com lombok builder singular https www baeldung com lombok buil
  • 无需登录即可直接从 Alfresco 访问文件/内容

    我的场景是这样的 我有一个使用 ALFRESCO CMS 来显示文件或图像的 Web 应用程序 我正在做的是在 Java servlet 中使用用户名和密码登录 alfresco 并且我可以获得该登录的票证 但我无法使用该票证直接从浏览器访
  • HttpClient请求设置属性问题

    我使用这个 HttpClient 库玩了一段时间 几周 我想以某种方式将属性设置为请求 不是参数而是属性 在我的 servlet 中 我想使用 Integer inte Integer request getAttribute obj 我不
  • 以 REST 方式更新整个资源集合

    我有一个资源列表的 REST URI 例如 http foo com group users 这些用户中的每一个都有一个序列号 我想公开一种方法来为集合中的所有用户重新编号这些值 并使访问该列表的每个人都可以使用此更改 由于这是对整个集合的
  • 使用 JFreeChart 为两个系列设置不同的 y 轴

    我正在使用 JFreeChart 使用折线图绘制两个数据系列 XYSeries 复杂的因素是 其中一个数据系列的 y 值通常远高于第二个数据系列的 y 值 假设第一个系列的 y 值约为数百万数量级 而第二个数据系列的 y 值约为数百万数量级
  • try-with-resources 中出现死代码警告,但翻译后的 try-catch-finally 中没有出现死代码警告

    以下代码使用try 有资源 https docs oracle com javase specs jls se7 html jls 14 html jls 14 20 3Java 8 中引入的构造 偶尔抛出 方法被声明为抛出一个偶尔的异常

随机推荐

  • Kioptrix_Level_1-writeup

    Kioptrix Level 1 writeup 0x00 信息收集 目标机器IP 16 16 16 176 kali攻击机 16 16 16 177 nmap扫描端口服务 nmap A Pn 16 16 16 176 Starting N
  • 如何安装JDK

    Orade 公司提供了多种操作系统的 JDK 不同操作系统的 JIDK 在使用上基本类似 初学者可以根据自已使用的操作系统 从Cnacle 官方网站下载相应的JDK 安装文件 下面以64位的 Windows 10系统为的来演示 JDK 8
  • 对象的实例化

    对象的实例化 创建对象的方式 new Class的newInstance 只能调用空参的构造器 权限必须是public Constructor的newInstance Xxx 可以调用空参 带参的构造器 权限没有要求 使用clone 需要实
  • python进阶知识点汇总

    一 函数 1 函数的传参 1 值传递 将实际的参数复制一份传递给形参 函数中修改形参时 不会影响到实际参数 def a b c 2 return b c print a 10 print a 123 2 print a 2 2 引用传递 将
  • 一张图看懂区块链

    要逐步了解区块链 我们需要一步步了解如下东西 去中心化 先来考虑一个中心化集中式处理的过程 你要在某宝上买一部手机 交易流程是 你将钱打给支付宝 支付宝收款后通知卖家发货 卖家发货 你确认收货 支付宝把钱打给卖家 在这个过程中 虽然你是在和
  • Vert.x的TCP服务端和客户端配置

    Vert x系列 Vert x介绍 https blog csdn net haoranhaoshi article details 89279096 Vert x实战一 Vert x通过Http发布数据 https blog csdn n
  • 蓝桥杯2020省赛单词分析

    题目描述 小蓝正在学习一门神奇的语言 这门语言中的单词都是由小写英文字母组 成 有些单词很长 远远超过正常英文单词的长度 小蓝学了很长时间也记不住一些单词 他准备不再完全记忆这些单词 而是根据单词中哪个字母出现得最多来分辨单词 现在 请你帮
  • RHEL/CentOS 7中的网络暨network.service与NetworkManager.service详解

    在RHEL CentOS 6及以前的版本中 网络功能是通过一系列网络相关的脚本文件实现 如 etc init d network文件 及如下 sbin if 文件等 root myserver ll sbin if rwxr xr x 1
  • ESP32s3 MSC/U盘 虚拟串口

    ESP32s3 MSC U盘 虚拟串口 开发环境是 IDF4 4 芯片 esp32s3 在项目中想要用到把内部的FLASH做成U盘 但是在idf4 4中没有找到MSC相关例程 如图 1 我在网上只找到esp32s2的例程 https git
  • 英国第七批36颗互联网卫星升空

    导读 英国卫星通信公司OneWeb 36颗卫星从俄东方航天发射场点火升空 累计在轨卫星218颗 据外媒 英国卫星通信公司OneWeb 36颗卫星从俄东方航天发射场点火升空 累计在轨卫星218颗 根据OneWeb的说法 只需要再发射一批36颗
  • 解决“unable to access ‘https://github.com...”

    前提 我在操作的时候做了https授权 但是密码输入错误了 再找想改也找不到了 搞半天都会报这个错 甚至我想用秘钥的方式都不行 万恶的git 解决方法 git config global http sslVerify false 然后正常操
  • STM32F103ZET6【HAL函开发】STM32CUBEMX------USART串口实验(DMA)

    printf重定义 需要将下面的代码插入到usart c里面 USER CODE BEGIN 1 if 1 include
  • hive集群安装,连接mysql

    1 linux安装mysql 并且生成hive用户 密码为Abc 123D 权限为所有权限 请看 这点很重要 http blog csdn net qq 21383435 article details 76573955 2 我的hadoo
  • JAVA中的目录指什么_默认情况下,Java listFiles()读取目录中的文件的顺序是什么? - java...

    我编写了以下程序 该程序读取目录中的所有文件 所有文件名均由数字组成 例如10023134 txt File dir new File directoryPath File files dir listFiles for File file
  • 内存管理实战案例分析3:为何分配不出一个页面?

    微信公众号 奔跑吧linux社区本文节选自 奔跑吧Linux内核 第二版卷1第6 3 3章 1 问题描述 下面是有问题的OOM Killer内核日志 其中空闲页面为86048KB 最低警戒水位为22528KB 低水位为28160KB 读者可
  • 如何使用iMazing监督、配置器功能

    监督功能是一种移动设备管理技术 使得Apple设备所有人具有最高管理权 设备受到监督之后 仅仅可以在监督人设定的模式下运行Apple设备 如单应用运行模式 权限限制模式 禁用配对模式等 最近很火的网剧 你安全了吗 就是宣传网络安全的 利用i
  • 【mySQL】MySQL JOIN原理

    MySQL JOIN原理 先看一下实验的两张表 表comments 总行数28856 表comments for 总行数57 comments id是有索引的 ID列为主键 以上两张表是我们测试的基础 然后看一下索引 comments fo
  • Nginx+Keepalived双机热备(主主模式)

    Keepalived介绍 Keepalived是一个基于VRRP协议来实现的服务高可用方案 可以利用其来避免IP单点故障 类似的工具还有heartbeat corosync pacemaker 但是它一般不会单独出现 而是与其它负载均衡技术
  • Mybatis 返回对象中包含 List集合

    遇到这种情况的实体类 需要在mapper xml文件里使用 resultMap标签以及其他子标签 先贴代码 实体类 UserEntity类 private Long id 用户id private String username 用户名 p
  • http请求忽略证书、单向认证、双向认证、连接池范例(httpclient 4.3.x以上版本)

    目录 加载证书单向认证 忽略证书 双向认证 连接池 加载证书单向认证 import org apache http HttpEntity import org apache http client methods CloseableHttp