use of org.apache.commons.httpclient.protocol.Protocol in project tdi-studio-se by Talend.
the class HttpMethodBase method generateRequestLine.
// ------------------------------------------------- Static Utility Methods
/**
* Generates HTTP request line according to the specified attributes.
*
* @param connection the {@link HttpConnection connection} used to execute
* this HTTP method
* @param name the method name generate a request for
* @param requestPath the path string for the request
* @param query the query string for the request
* @param version the protocol version to use (e.g. HTTP/1.0)
*
* @return HTTP request line
*/
protected static String generateRequestLine(HttpConnection connection, String name, String requestPath, String query, String version) {
LOG.trace("enter HttpMethodBase.generateRequestLine(HttpConnection, " + "String, String, String, String)");
StringBuffer buf = new StringBuffer();
// Append method name
buf.append(name);
buf.append(" ");
// Absolute or relative URL?
if (!connection.isTransparent()) {
Protocol protocol = connection.getProtocol();
buf.append(protocol.getScheme().toLowerCase());
buf.append("://");
buf.append(connection.getHost());
if ((connection.getPort() != -1) && (connection.getPort() != protocol.getDefaultPort())) {
buf.append(":");
buf.append(connection.getPort());
}
}
// Append path, if any
if (requestPath == null) {
buf.append("/");
} else {
if (!connection.isTransparent() && !requestPath.startsWith("/")) {
buf.append("/");
}
buf.append(requestPath);
}
// Append query, if any
if (query != null) {
if (query.indexOf("?") != 0) {
buf.append("?");
}
buf.append(query);
}
// Append protocol
buf.append(" ");
buf.append(version);
buf.append("\r\n");
return buf.toString();
}
use of org.apache.commons.httpclient.protocol.Protocol in project zm-mailbox by Zimbra.
the class SocketFactories method register.
private static synchronized void register(X509TrustManager tm) {
if (registered)
return;
// Set default TrustManager
TrustManagers.setDefaultTrustManager(tm);
// Register Apache Commons HTTP/HTTPS protocol socket factories
ProtocolSocketFactory psf = defaultProtocolSocketFactory();
Protocol.registerProtocol(HTTP, new Protocol(HTTP, psf, 80));
ProtocolSocketFactory spsf = defaultSecureProtocolSocketFactory();
Protocol.registerProtocol(HTTPS, new Protocol(HTTPS, spsf, 443));
// HttpURLConnection already uses system ProxySelector by default
// Set HttpsURLConnection SSL socket factory and optional hostname verifier
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory(false));
if (tm instanceof CustomTrustManager) {
HttpsURLConnection.setDefaultHostnameVerifier(new CustomHostnameVerifier());
}
// Set the system-wide default ProxySelector
ProxySelector.setDefault(ProxySelectors.defaultProxySelector());
registered = true;
}
use of org.apache.commons.httpclient.protocol.Protocol in project translationstudio8 by heartsome.
the class ServiceUtilTest method getService.
public static IService getService() throws MalformedURLException {
// Service srvcModel = new
// ObjectServiceFactory().create(IService.class);
// XFireProxyFactory factory = new XFireProxyFactory(XFireFactory
// .newInstance().getXFire());
//
// IService srvc = (IService) factory.create(srvcModel,
// Constants.CONNECT_URL);
// return srvc;
ProtocolSocketFactory easy = new EasySSLProtocolSocketFactory();
Protocol protocol = new Protocol(HTTP_TYPE, easy, PORT);
Protocol.registerProtocol(HTTP_TYPE, protocol);
Service serviceModel = new ObjectServiceFactory().create(IService.class, SERVICE_NAME, SERVICE_NAMESPACE, null);
IService service = (IService) new XFireProxyFactory().create(serviceModel, SERVICE_URL);
Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
client.addOutHandler(new DOMOutHandler());
client.setProperty(CommonsHttpMessageSender.GZIP_ENABLED, Boolean.FALSE);
client.setProperty(CommonsHttpMessageSender.DISABLE_EXPECT_CONTINUE, "1");
client.setProperty(CommonsHttpMessageSender.HTTP_TIMEOUT, "0");
return service;
}
use of org.apache.commons.httpclient.protocol.Protocol in project camel by apache.
the class HttpsSslContextParametersGetTest method createRouteBuilder.
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
public void configure() {
SSLContextParameters params = new SSLContextParameters();
ProtocolSocketFactory factory = new SSLContextParametersSecureProtocolSocketFactory(params, context);
Protocol.registerProtocol("https", new Protocol("https", factory, 443));
from("direct:start").to("https://mail.google.com/mail/").to("mock:results");
}
};
}
use of org.apache.commons.httpclient.protocol.Protocol in project pinpoint by naver.
the class HttpMethodBaseExecuteMethodInterceptor method recordDestination.
private void recordDestination(final Trace trace, final HttpMethod httpMethod, final Object[] args) {
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
try {
final URI uri = httpMethod.getURI();
final HttpConnection httpConnection = getHttpConnection(args);
// if uri have schema or not found HttpConnection argument.
if (uri.isAbsoluteURI() || httpConnection == null) {
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(uri.getURI(), param));
recorder.recordDestinationId(getEndpoint(uri.getHost(), uri.getPort()));
return;
}
if (isDebug) {
logger.debug("URI is not absolute. {}", uri.getURI());
}
// use HttpConnection argument.
final String host = httpConnection.getHost();
int port = httpConnection.getPort();
final StringBuilder httpUrl = new StringBuilder();
final Protocol protocol = httpConnection.getProtocol();
if (protocol != null) {
httpUrl.append(protocol.getScheme()).append("://");
httpUrl.append(httpConnection.getHost());
// if port is default port number.
if (httpConnection.getPort() == protocol.getDefaultPort()) {
port = -1;
} else {
httpUrl.append(":").append(port);
}
}
httpUrl.append(uri.getURI());
recorder.recordAttribute(AnnotationKey.HTTP_URL, InterceptorUtils.getHttpUrl(httpUrl.toString(), param));
recorder.recordDestinationId(getEndpoint(host, port));
} catch (URIException e) {
logger.error("Fail get URI", e);
recorder.recordDestinationId("unknown");
}
}
Aggregations