本文整理汇总了Java中org.apache.commons.httpclient.protocol.Protocol类的典型用法代码示例。如果您正苦于以下问题:Java Protocol类的具体用法?Java Protocol怎么用?Java Protocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Protocol类属于org.apache.commons.httpclient.protocol包,在下文中一共展示了Protocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initStub
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
private void initStub(Stub stub) throws AxisFault
{
if( stub != null )
{
final ServiceClient client = stub._getServiceClient();
final Options options = client.getOptions();
options.setProperty(WSHandlerConstants.PW_CALLBACK_REF, this);
options.setProperty(WSSHandlerConstants.OUTFLOW_SECURITY, ofc.getProperty());
options.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, "true");
options.setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_11);
URI uri = URI.create(bbUrl);
if( uri.getScheme().toLowerCase().startsWith("https") )
{
Protocol myhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
options.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, myhttps);
}
client.engageModule("rampart-1.5.1");
}
}
示例2: create
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
@Create
public void create() {
Protocol.registerProtocol("https", new Protocol("https",
new EasySSLProtocolSocketFactory(), 8443));
this.httpClient = new HttpClient();
this.httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin",
this.entityManager.find(CommandParameter.class,
CommandParameter.HERITRIX_ADMINPW_KEY)
.getCommandValue());
this.httpClient.getState().setCredentials(
new AuthScope(AuthScope.ANY_SCHEME, AuthScope.ANY_PORT,
AuthScope.ANY_REALM), defaultcreds);
this.engineUri = this.entityManager.find(Parameter.class,
Parameter.ENGINE_URI.getKey()).getValue();
Logger httpClientlogger = Logger.getLogger(this.httpClient.getClass());
httpClientlogger.setLevel(Level.ERROR);
Logger authChallengeProcessorLogger = Logger
.getLogger(AuthChallengeProcessor.class);
authChallengeProcessorLogger.setLevel(Level.ERROR);
Logger httpMethodBaseLogger = Logger.getLogger(HttpMethodBase.class);
httpMethodBaseLogger.setLevel(Level.ERROR);
this.jobsDir = this.entityManager.find(Parameter.class,
Parameter.JOBS_DIR.getKey()).getValue();
}
示例3: create
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
private void create() {
Protocol.registerProtocol("https", new Protocol("https",
new EasySSLProtocolSocketFactory(), 8443));
this.httpClient = new HttpClient();
this.httpClient.getParams().setAuthenticationPreemptive(true);
Credentials defaultcreds = new UsernamePasswordCredentials("admin",
this.entityManager.find(CommandParameter.class,
CommandParameter.HERITRIX_ADMINPW_KEY)
.getCommandValue());
this.httpClient.getState().setCredentials(
new AuthScope(AuthScope.ANY_SCHEME, AuthScope.ANY_PORT,
AuthScope.ANY_REALM), defaultcreds);
this.engineUri = this.entityManager.find(Parameter.class,
Parameter.ENGINE_URI.getKey()).getValue();
Logger httpClientlogger = Logger.getLogger(this.httpClient.getClass());
httpClientlogger.setLevel(Level.ERROR);
Logger authChallengeProcessorLogger = Logger
.getLogger(AuthChallengeProcessor.class);
authChallengeProcessorLogger.setLevel(Level.ERROR);
Logger httpMethodBaseLogger = Logger.getLogger(HttpMethodBase.class);
httpMethodBaseLogger.setLevel(Level.ERROR);
this.jobsDir = this.entityManager.find(Parameter.class,
Parameter.JOBS_DIR.getKey()).getValue();
}
示例4: HttpClientTransmitterImpl
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public HttpClientTransmitterImpl()
{
protocolMap = new TreeMap<String,Protocol>();
protocolMap.put(HTTP_SCHEME_NAME, httpProtocol);
protocolMap.put(HTTPS_SCHEME_NAME, httpsProtocol);
httpClient = new HttpClient();
httpClient.setHttpConnectionManager(new MultiThreadedHttpConnectionManager());
httpMethodFactory = new StandardHttpMethodFactoryImpl();
jsonErrorSerializer = new ExceptionJsonSerializer();
// Create an HTTP Proxy Host if appropriate system properties are set
httpProxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT);
httpProxyCredentials = HttpClientHelper.createProxyCredentials("http.proxyUser", "http.proxyPassword");
httpAuthScope = createProxyAuthScope(httpProxyHost);
// Create an HTTPS Proxy Host if appropriate system properties are set
httpsProxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT);
httpsProxyCredentials = HttpClientHelper.createProxyCredentials("https.proxyUser", "https.proxyPassword");
httpsAuthScope = createProxyAuthScope(httpsProxyHost);
}
示例5: getHost
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
/** Get a host for the given parameters. This method need not be thread-safe. */
public HttpHost getHost(String host, int port, String scheme)
{
if(scheme == null)
{
scheme = "http";
}
Protocol protocol = protocols.get(scheme);
if(protocol == null)
{
protocol = Protocol.getProtocol("http");
if(protocol == null)
{
throw new IllegalArgumentException("Unrecognised scheme parameter");
}
}
return new HttpHost(host, port, protocol);
}
示例6: HttpConnection
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
/**
* Creates a new HTTP connection for the given host with the virtual
* alias and port via the given proxy host and port using the given
* protocol.
*
* @param proxyHost the host to proxy via
* @param proxyPort the port to proxy via
* @param host the host to connect to. Parameter value must be non-null.
* @param port the port to connect to
* @param protocol The protocol to use. Parameter value must be non-null.
*/
public HttpConnection(
String proxyHost,
int proxyPort,
String host,
int port,
Protocol protocol) {
if (host == null) {
throw new IllegalArgumentException("host parameter is null");
}
if (protocol == null) {
throw new IllegalArgumentException("protocol is null");
}
proxyHostName = proxyHost;
proxyPortNumber = proxyPort;
hostName = host;
portNumber = protocol.resolvePort(port);
protocolInUse = protocol;
}
示例7: HttpHost
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
/**
* Constructor for HttpHost.
*
* @param hostname the hostname (IP or DNS name). Can be <code>null</code>.
* @param port the port. Value <code>-1</code> can be used to set default protocol port
* @param protocol the protocol. Value <code>null</code> can be used to set default protocol
*/
public HttpHost(final String hostname, int port, final Protocol protocol) {
super();
if (hostname == null) {
throw new IllegalArgumentException("Host name may not be null");
}
if (protocol == null) {
throw new IllegalArgumentException("Protocol may not be null");
}
this.hostname = hostname;
this.protocol = protocol;
if (port >= 0) {
this.port = port;
} else {
this.port = this.protocol.getDefaultPort();
}
}
示例8: testDefaults
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public void testDefaults() throws IOException {
this.server.setHttpService(new SimpleService());
this.client.getParams().setParameter(HttpMethodParams.USER_AGENT, "test");
HostConfiguration hostconfig = new HostConfiguration();
hostconfig.setHost(
this.server.getLocalAddress(),
this.server.getLocalPort(),
Protocol.getProtocol("http"));
GetMethod httpget = new GetMethod("/miss/");
try {
this.client.executeMethod(hostconfig, httpget);
} finally {
httpget.releaseConnection();
}
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("test", httpget.getRequestHeader("User-Agent").getValue());
assertEquals("test", httpget.getParams().
getParameter(HttpMethodParams.USER_AGENT));
assertEquals("test", hostconfig.getParams().
getParameter(HttpMethodParams.USER_AGENT));
assertEquals("test", client.getParams().
getParameter(HttpMethodParams.USER_AGENT));
}
示例9: testRedirectWithVirtualHost
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public void testRedirectWithVirtualHost() throws IOException {
String host = this.server.getLocalAddress();
int port = this.server.getLocalPort();
Protocol testhttp = new Protocol("http", new VirtualSocketFactory(host, port), port);
Protocol.registerProtocol("testhttp", testhttp);
try {
this.server.setHttpService(new VirtualHostService());
this.client.getHostConfiguration().setHost(host, port, "testhttp");
this.client.getHostConfiguration().getParams().setVirtualHost("whatever.com");
GetMethod httpget = new GetMethod("/");
httpget.setFollowRedirects(true);
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
assertEquals("http://www.whatever.co.nz/", httpget.getURI().toString());
} finally {
httpget.releaseConnection();
}
} finally {
Protocol.unregisterProtocol("testhttp");
}
}
示例10: testConnTimeout
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public void testConnTimeout() {
// create a custom protocol that will delay for 500 milliseconds
Protocol testProtocol = new Protocol(
"timeout",
new DelayedProtocolSocketFactory(
500,
Protocol.getProtocol("http").getSocketFactory()
),
this.server.getLocalPort()
);
HttpConnection conn = new HttpConnection(
this.server.getLocalAddress(), this.server.getLocalPort(), testProtocol);
// 1 ms is short enough to make this fail
conn.getParams().setConnectionTimeout(1);
try {
conn.open();
fail("Should have timed out");
} catch(IOException e) {
assertTrue(e instanceof ConnectTimeoutException);
/* should fail */
}
}
示例11: testNTLMAuthenticationRetry
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public void testNTLMAuthenticationRetry() throws Exception {
this.server.setHttpService(new NTLMAuthService());
// configure the client
this.client.getHostConfiguration().setHost(
server.getLocalAddress(), server.getLocalPort(),
Protocol.getProtocol("http"));
this.client.getState().setCredentials(AuthScope.ANY,
new NTCredentials("username", "password", "host", "domain"));
FakeHttpMethod httpget = new FakeHttpMethod("/");
try {
client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNull(httpget.getResponseHeader("WWW-Authenticate"));
assertEquals(200, httpget.getStatusCode());
}
示例12: testRelativeURLHitWithDefaultHost
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public void testRelativeURLHitWithDefaultHost() throws IOException {
this.server.setHttpService(new EchoService());
// Set default host
this.client.getHostConfiguration().setHost(
this.server.getLocalAddress(),
this.server.getLocalPort(),
Protocol.getProtocol("http"));
GetMethod httpget = new GetMethod("/test/");
try {
this.client.executeMethod(httpget);
assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
} finally {
httpget.releaseConnection();
}
}
示例13: getProtocol
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
/**
* Get a Protocol for the given parameters. The default implementation
* selects a protocol based only on the scheme. Subclasses can do fancier
* things, such as select SSL parameters based on the host or port. This
* method must not return null.
*/
protected Protocol getProtocol(HostConfiguration old, String scheme, String host, int port)
{
final Protocol oldProtocol = old.getProtocol();
if (oldProtocol != null) {
final String oldScheme = oldProtocol.getScheme();
if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
// The old protocol has the desired scheme.
return oldProtocol; // Retain it.
}
}
Protocol newProtocol = (scheme != null && scheme.toLowerCase().endsWith("s")) ? httpsProtocol
: httpProtocol;
if (newProtocol == null) {
newProtocol = Protocol.getProtocol(scheme);
}
return newProtocol;
}
示例14: inicializaCertificado
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
/**
* Metodo Que Inicializa as Informações de Certificado Digital
*
* @param certificado
* @param cacert
* @throws CertificadoException
*/
public static void inicializaCertificado(Certificado certificado, InputStream cacert) throws CertificadoException {
try {
KeyStore keyStore = getKeyStore(certificado);
X509Certificate certificate = getCertificate(certificado, keyStore);
PrivateKey privateKey = (PrivateKey) keyStore.getKey(certificado.getNome(), certificado.getSenha().toCharArray());
if (certificado.isAtivarProperties()) {
CertificadoProperties.inicia(certificado, cacert);
} else {
SocketFactoryDinamico socketFactory = new SocketFactoryDinamico(certificate, privateKey, cacert, certificado.getSslProtocol());
Protocol protocol = new Protocol("https", socketFactory, 443);
Protocol.registerProtocol("https", protocol);
}
} catch (UnrecoverableKeyException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException | CertificateException | IOException e) {
throw new CertificadoException(e.getMessage());
}
}
示例15: load
import org.apache.commons.httpclient.protocol.Protocol; //导入依赖的package包/类
public static void load(KeyStore ks, String alias, char[] pin, String patOfCacerts)
throws KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException {
if (!isLoaded) {
if ((alias == null) || ("".equals(alias))) {
Enumeration<String> aliasesEnum = ks.aliases();
while (aliasesEnum.hasMoreElements()) {
alias = (String) aliasesEnum.nextElement();
if (ks.isKeyEntry(alias)) {
break;
}
}
}
X509Certificate certificate = (X509Certificate) ks.getCertificate(alias);
PrivateKey privateKey = (PrivateKey) ks.getKey(alias, pin);
SocketFactoryDinamico socketFactoryDinamico = new SocketFactoryDinamico(certificate, privateKey);
socketFactoryDinamico.setFileCacerts(patOfCacerts);
Protocol protocol = new Protocol("https", socketFactoryDinamico, 443);
Protocol.registerProtocol("https", protocol);
isLoaded = true;
}
}