本文整理汇总了Java中org.apache.commons.httpclient.protocol.Protocol.getProtocol方法的典型用法代码示例。如果您正苦于以下问题:Java Protocol.getProtocol方法的具体用法?Java Protocol.getProtocol怎么用?Java Protocol.getProtocol使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.protocol.Protocol
的用法示例。
在下文中一共展示了Protocol.getProtocol方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: 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;
}
示例3: replaceProtocol
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
private void replaceProtocol(HostConfiguration hostConfig, ProtocolSocketFactory socketFactory, String schema, int defaultPort) {
//
// switch protocol
// due to how HttpCommons work internally this dance is best to be kept as is
//
// NB: not really needed (see below that the protocol is reseted) but in place just in case
hostConfig = new ProtocolAwareHostConfiguration(hostConfig);
Protocol directHttp = Protocol.getProtocol(schema);
Protocol proxiedHttp = new DelegatedProtocol(socketFactory, directHttp, schema, defaultPort);
// NB: register the new protocol since when using absolute URIs, HttpClient#executeMethod will override the configuration (#387)
// NB: hence why the original/direct http protocol is saved - as otherwise the connection is not closed since it is considered different
// NB: (as the protocol identities don't match)
// this is not really needed since it's being replaced later on
// hostConfig.setHost(proxyHost, proxyPort, proxiedHttp);
Protocol.registerProtocol(schema, proxiedHttp);
// end dance
}
示例4: registerAdvancedSslContext
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
/**
* Registers or unregisters the proper components for advanced SSL handling.
* @throws IOException
*/
@SuppressWarnings("deprecation")
public static void registerAdvancedSslContext(boolean register, Context context)
throws GeneralSecurityException, IOException {
Protocol pr = null;
try {
pr = Protocol.getProtocol("https");
if (pr != null && mDefaultHttpsProtocol == null) {
mDefaultHttpsProtocol = pr;
}
} catch (IllegalStateException e) {
// nothing to do here; really
}
boolean isRegistered = (pr != null && pr.getSocketFactory() instanceof AdvancedSslSocketFactory);
if (register && !isRegistered) {
Protocol.registerProtocol("https", new Protocol("https", getAdvancedSslSocketFactory(context), 443));
} else if (!register && isRegistered) {
if (mDefaultHttpsProtocol != null) {
Protocol.registerProtocol("https", mDefaultHttpsProtocol);
}
}
}
示例5: MoveFileTest
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public MoveFileTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
示例6: SingleSessionManagerTest
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public SingleSessionManagerTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
示例7: SimpleFactoryManagerTest
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public SimpleFactoryManagerTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
示例8: OwnCloudClientTest
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public OwnCloudClientTest() {
super();
Protocol pr = Protocol.getProtocol("https");
if (pr == null || !(pr.getSocketFactory() instanceof SelfSignedConfidentSslSocketFactory)) {
try {
ProtocolSocketFactory psf = new SelfSignedConfidentSslSocketFactory();
Protocol.registerProtocol(
"https",
new Protocol("https", psf, 443));
} catch (GeneralSecurityException e) {
throw new AssertionFailedError(
"Self-signed confident SSL context could not be loaded");
}
}
}
示例9: getRequest
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
private String getRequest()
{
if (!Server.serving) return "";
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpHost host = new HttpHost("localhost", Server.frontPort, Protocol.getProtocol("http"));
HttpGet request = new HttpGet(host.toURI().concat("/" + Server.RESPONSES));
ResponseHandler<String> responseHandler = new ResponseHandler<String>() {
public String handleResponse(final HttpResponse response) throws IOException {
int status = response.getStatusLine().getStatusCode();
if (status >= 200 && status < 300) {
HttpEntity entity = response.getEntity();
return entity != null ? EntityUtils.toString(entity) : null;
} else throw new ClientProtocolException("Unexpected response status: " + status);
}
};
String responseBody = null;
try {
responseBody = httpclient.execute(request, responseHandler);
} catch (IOException e) { Runner.LOGGER.warn(e); }
return responseBody;
}
示例10: testProtocolReplacement
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
@Test
public void testProtocolReplacement() throws Exception {
final ProtocolSocketFactory socketFactory = getSocketFactory();
CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443);
Protocol protocol = Protocol.getProtocol("https");
assertThat(protocol, instanceOf(DelegatedProtocol.class));
DelegatedProtocol delegatedProtocol = (DelegatedProtocol) protocol;
assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory));
assertThat(delegatedProtocol.getOriginal(), sameInstance(original));
// ensure we do not re-wrap a delegated protocol
CommonsHttpTransport.replaceProtocol(socketFactory, "https", 443);
protocol = Protocol.getProtocol("https");
assertThat(protocol, instanceOf(DelegatedProtocol.class));
delegatedProtocol = (DelegatedProtocol) protocol;
assertThat(delegatedProtocol.getSocketFactory(), sameInstance(socketFactory));
assertThat(delegatedProtocol.getOriginal(), sameInstance(original));
}
示例11: getNewProtocol
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
/**
* Select a Protocol to be used for the given host, port and scheme. The
* current Protocol may be selected, if appropriate. This method need not be
* thread-safe; the caller must synchronize if necessary.
* <p/>
* This implementation returns the current Protocol if it has the given
* scheme; otherwise it returns the Protocol registered for that scheme.
*/
protected Protocol getNewProtocol(String host, int port, String scheme) {
final Protocol oldProtocol = getProtocol();
if (oldProtocol != null) {
final String oldScheme = oldProtocol.getScheme();
if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
// The old {rotocol has the desired scheme.
return oldProtocol; // Retain it.
}
}
return Protocol.getProtocol(scheme);
}
示例12: testHostHeaderPortHTTPS443
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public void testHostHeaderPortHTTPS443() throws Exception {
HttpConnection conn = new HttpConnection("some.host.name", 443,
Protocol.getProtocol("https"));
HttpState state = new HttpState();
FakeHttpMethod method = new FakeHttpMethod();
method.addRequestHeaders(state, conn);
assertEquals("Host: some.host.name", method.getRequestHeader("Host").toString().trim());
}
示例13: testHostHeaderPortHTTPS444
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
public void testHostHeaderPortHTTPS444() throws Exception {
HttpConnection conn = new HttpConnection("some.host.name", 444,
Protocol.getProtocol("https"));
HttpState state = new HttpState();
FakeHttpMethod method = new FakeHttpMethod();
method.addRequestHeaders(state, conn);
assertEquals("Host: some.host.name:444", method.getRequestHeader("Host").toString().trim());
}
示例14: getNewProtocol
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
/**
* Select a Protocol to be used for the given host, port and scheme. The
* current Protocol may be selected, if appropriate. This method need not be
* thread-safe; the caller must synchronize if necessary.
* <p>
* This implementation returns the current Protocol if it has the given
* scheme; otherwise it returns the Protocol registered for that scheme.
*/
protected Protocol getNewProtocol(String host, int port, String scheme)
{
final Protocol oldProtocol = getProtocol();
if (oldProtocol != null) {
final String oldScheme = oldProtocol.getScheme();
if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
// The old {rotocol has the desired scheme.
return oldProtocol; // Retain it.
}
}
return Protocol.getProtocol(scheme);
}
示例15: keepProtocol
import org.apache.commons.httpclient.protocol.Protocol; //导入方法依赖的package包/类
protected Protocol keepProtocol(String host, int port, String scheme) {
final Protocol oldProtocol = getProtocol();
if (oldProtocol != null) {
final String oldScheme = oldProtocol.getScheme();
if (oldScheme == scheme || (oldScheme != null && oldScheme.equalsIgnoreCase(scheme))) {
return oldProtocol;
}
}
return Protocol.getProtocol(scheme);
}