- 浏览: 187283 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (83)
- J2EE/Core Java (24)
- J2EE/Portal (2)
- J2EE/UI (4)
- J2EE/ATG (1)
- J2EE/Report (1)
- J2EE/Web Service/Rest API (2)
- Design Pattern (2)
- Arithmetic (4)
- Linux (12)
- Ruby&Rails (17)
- Database (5)
- J2EE/Payment (1)
- J2EE/JVM (1)
- Encryption/Decryption (3)
- J2EE/Multi Threading (4)
- SQL (1)
- https://community.teamviewer.com/t5/Knowledge-Base/Where-can-I-download-older-TeamViewer-versions-nbsp/ta-p/7729 (0)
最新评论
1. HttpClient4.1.2 & HtmlUnit2.9 NTLM 验证
2. Httpclient4.1.2信任所有https/SSL证书
private static final String URL = "*******"; @Test public void testHttpClient4_1_2Auth() throws ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, new NTCredentials("wc24465", "*****!", null, "apac")); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); HttpGet httpget = new HttpGet(URL); } @Test public void testHtmlUnit2_9Auth() throws FailingHttpStatusCodeException, MalformedURLException, IOException { final WebClient webClient = new WebClient(); webClient.setWebConnection(new HttpWebConnection(webClient) { protected synchronized AbstractHttpClient getHttpClient() { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory()); httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new NTCredentials("wc24465", "*****", "APACCNSHZJW2336.apac.nsroot.net", "apac")); List<String> authpref = new ArrayList<String>(); authpref.add(AuthPolicy.NTLM); httpClient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref); return httpClient; } }); final HtmlPage page = webClient.getPage(URL); }
public class NTLMSchemeFactory implements AuthSchemeFactory { public AuthScheme newInstance(final HttpParams params) { return new NTLMScheme(new JCIFSEngine()); } }
import jcifs.ntlmssp.NtlmFlags; import jcifs.ntlmssp.Type1Message; import jcifs.ntlmssp.Type2Message; import jcifs.ntlmssp.Type3Message; import jcifs.util.Base64; import org.apache.http.impl.auth.NTLMEngine; import org.apache.http.impl.auth.NTLMEngineException; import java.io.IOException; public final class JCIFSEngine implements NTLMEngine { private static final int TYPE_1_FLAGS = NtlmFlags.NTLMSSP_NEGOTIATE_56 | NtlmFlags.NTLMSSP_NEGOTIATE_128 | NtlmFlags.NTLMSSP_NEGOTIATE_NTLM2 | NtlmFlags.NTLMSSP_NEGOTIATE_ALWAYS_SIGN | NtlmFlags.NTLMSSP_REQUEST_TARGET; public String generateType1Msg(final String domain, final String workstation) throws NTLMEngineException { final Type1Message type1Message = new Type1Message(TYPE_1_FLAGS, domain, workstation); return Base64.encode(type1Message.toByteArray()); } public String generateType3Msg(final String username, final String password, final String domain, final String workstation, final String challenge) throws NTLMEngineException { Type2Message type2Message; try { type2Message = new Type2Message(Base64.decode(challenge)); } catch (final IOException exception) { throw new NTLMEngineException("Invalid NTLM type 2 message", exception); } final int type2Flags = type2Message.getFlags(); final int type3Flags = type2Flags & (0xffffffff ^ (NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN | NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER)); final Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, type3Flags); return Base64.encode(type3Message.toByteArray()); } }
2. Httpclient4.1.2信任所有https/SSL证书
@Test public void testHttpsLogin() throws IOException { SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); HttpParams params = new BasicHttpParams(); params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ClientConnectionManager cm = new SingleClientConnManager(params, schemeRegistry); HttpClient httpClient = new DefaultHttpClient(cm, params); }
package com.citi.ocean.errorProduct.util.test; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.TrustManager; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.conn.scheme.LayeredSocketFactory; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams; /** * This socket factory will create ssl socket that accepts self signed * certificate * * @author olamy * @version $Id: EasySSLSocketFactory.java 765355 2009-04-15 20:59:07Z evenisse * $ * @since 1.2.3 */ public class EasySSLSocketFactory implements LayeredSocketFactory { private SSLContext sslcontext = null; private static SSLContext createEasySSLContext() throws IOException { try { SSLContext context = SSLContext.getInstance("TLS"); context.init(null, new TrustManager[] { new EasyX509TrustManager( null) }, null); return context; } catch (Exception e) { throw new IOException(e.getMessage()); } } private SSLContext getSSLContext() throws IOException { if (this.sslcontext == null) { this.sslcontext = createEasySSLContext(); } return this.sslcontext; } /** * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket, * java.lang.String, int, java.net.InetAddress, int, * org.apache.http.params.HttpParams) */ public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException { int connTimeout = HttpConnectionParams.getConnectionTimeout(params); int soTimeout = HttpConnectionParams.getSoTimeout(params); InetSocketAddress remoteAddress = new InetSocketAddress(host, port); SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket()); if ((localAddress != null) || (localPort > 0)) { // we need to bind explicitly if (localPort < 0) { localPort = 0; // indicates "any" } InetSocketAddress isa = new InetSocketAddress(localAddress, localPort); sslsock.bind(isa); } sslsock.connect(remoteAddress, connTimeout); sslsock.setSoTimeout(soTimeout); return sslsock; } /** * @see org.apache.http.conn.scheme.SocketFactory#createSocket() */ public Socket createSocket() throws IOException { return getSSLContext().getSocketFactory().createSocket(); } /** * @see org.apache.http.conn.scheme.SocketFactory#isSecure(java.net.Socket) */ public boolean isSecure(Socket socket) throws IllegalArgumentException { return true; } /** * @see org.apache.http.conn.scheme.LayeredSocketFactory#createSocket(java.net.Socket, * java.lang.String, int, boolean) */ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { //return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose); return getSSLContext().getSocketFactory().createSocket(socket, host, port, autoClose); } // ------------------------------------------------------------------- // javadoc in org.apache.http.conn.scheme.SocketFactory says : // Both Object.equals() and Object.hashCode() must be overridden // for the correct operation of some connection managers // ------------------------------------------------------------------- public boolean equals(Object obj) { return ((obj != null) && obj.getClass().equals( EasySSLSocketFactory.class)); } public int hashCode() { return EasySSLSocketFactory.class.hashCode(); } }
package com.citi.ocean.errorProduct.util.test; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you 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. */ import java.security.KeyStore; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; /** * @author olamy * @version $Id: EasyX509TrustManager.java 765355 2009-04-15 20:59:07Z evenisse $ * @since 1.2.3 */ public class EasyX509TrustManager implements X509TrustManager { private X509TrustManager standardTrustManager = null; /** * Constructor for EasyX509TrustManager. */ public EasyX509TrustManager( KeyStore keystore ) throws NoSuchAlgorithmException, KeyStoreException { super(); TrustManagerFactory factory = TrustManagerFactory.getInstance( TrustManagerFactory.getDefaultAlgorithm() ); factory.init( keystore ); TrustManager[] trustmanagers = factory.getTrustManagers(); if ( trustmanagers.length == 0 ) { throw new NoSuchAlgorithmException( "no trust manager found" ); } this.standardTrustManager = (X509TrustManager) trustmanagers[0]; } /** * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType) */ public void checkClientTrusted( X509Certificate[] certificates, String authType ) throws CertificateException { standardTrustManager.checkClientTrusted( certificates, authType ); } /** * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType) */ public void checkServerTrusted( X509Certificate[] certificates, String authType ) throws CertificateException { if ( ( certificates != null ) && ( certificates.length == 1 ) ) { certificates[0].checkValidity(); } else { standardTrustManager.checkServerTrusted( certificates, authType ); } } /** * @see javax.net.ssl.X509TrustManager#getAcceptedIssuers() */ public X509Certificate[] getAcceptedIssuers() { return this.standardTrustManager.getAcceptedIssuers(); } }
发表评论
-
Start tomcat with port 80 without Linux root user-Use iptables mapping
2016-05-25 17:39 830引用In linux system. only root us ... -
Format XML in JAVA
2016-01-11 12:23 601public static String format ... -
HttpURLConnection下载文件
2015-08-07 11:25 793public class HttpDownloadUtilit ... -
Ehcache RMI Replicated Cluster(RMI集群)
2013-04-25 23:39 1067引用本文是ehcache RMI集群的例子,导入附件中的jav ... -
Integrete unitils for database(dao) testing
2013-02-01 18:39 1691引用Database testing Unit tests f ... -
JAXB入门
2012-10-16 11:59 785引用jaxb是一个读写xml的工具,还可以提供验证,不需要额外 ... -
Freemarker使用入门
2012-10-16 11:54 1017引用freemarker是一种模板标记工具,可以做页面静态化, ... -
perforce java api使用
2012-10-16 11:43 1253引用perforce是种版本管理软件,提供啦完整的java a ... -
XPath 入门
2012-10-16 11:29 879引用xpath可以快速定位获取XML文件中指定属性和值,jdk ... -
Java File Diff-diffutils
2012-09-27 17:35 74441. Maven Dependency <depende ... -
XSD 入门使用
2012-09-18 23:20 775<?xml version="1.0" ... -
nexus-2.1.1安装及使用入门
2012-08-13 22:52 14451. 安装 地址http://www.sonatype.org ... -
File Demo
2012-06-25 22:55 1308package org.springside.examples ... -
Java 访问sharepoint webservice(NTLM & SSL)
2012-06-12 09:47 3771引用遇到需要使用java访问微软的sharepoint的web ... -
Selenium Web Driver入门
2012-05-27 23:17 58351 What is Selenium? 引用Selenium ... -
HttpClient4.1.2 & HtmlUnit2.9 处理文件下载
2012-01-09 18:18 1025TestCode import java.io.Fi ... -
HttpClient4登陆ITeye
2012-01-08 23:33 1895import java.io.IOException; im ... -
Spring2集成测试
2011-08-25 22:21 761Spring2测试类继承层次 集成测试例子 public ... -
Learning EasyMock3.0 By Official Example
2011-08-24 16:48 1375Maven Installation+ add followi ... -
Maven+jetty+jrebel+m2eclipse+eclipse搭建struts2开发环境
2011-08-11 11:18 4119引用Maven:项目构建工具,通过pom.xml可以自动维护j ...
相关推荐
NULL 博文链接:https://caerun.iteye.com/blog/1338956
httpclient4.1.2 jar包
httpclient4.1.2.zip
HttpClient4.1.2的中英文文档
httpclient jersey所需要的全部jar包,版本是4.1.2,有需要就下载吧
HttpClient&&HtmlParser(Crawler)网络爬虫 HttpClient&&HtmlParser(Crawler)网络爬虫
httpClient 4.1.2 API chm格式
以上自己测试是可行的,直接拿过去导入即可,直接用main
使用HttpClient4.5实现https请求忽略SSL证书验证工具类
Commons HTTPClient4.X组件应用示例
activation.jar、commons-beanutils-1.8.3.jar、httpclient-4.1.2.jar、httpclient-cache-4.1.2.jar、httpcore-4.1.2.jar、httpmime-4.1.2.jar、json-lib-2.4-jdk15.jar、log4j.jar、mail.jar等
里面包含httpclient4相关的技术文档与实例
方法和原有低版本的API不太兼容,package路径变为:org.apache.http.相关包,细节使用方式请参考我的博客: http://blog.csdn.net/xieyuooo/article/details/7210846 如还有更加细致的问题,请在博客中留言,谢谢...
httpclient-4.1.2
thrift 生成的java包httpclient-4.1.2.jar
http远程接口调用-httpClient+跳过SSL证书校验. 里面分别有3个httpClient的工具类代码。 还有一个专门为了跳过SSL证书校验的工具类。
HttpClient配置SSL绕过https证书实例,附件中包含所需httpclient组件jar库。博客地址:http://blog.csdn.net/irokay/article/details/78801307。