List of usage examples for org.apache.commons.httpclient.protocol Protocol getScheme
public String getScheme()
From source file:com.navercorp.pinpoint.plugin.httpclient3.HttpClient3RequestTrace.java
private static String getHttpUrl(final String host, final int port, final URI uri, final HttpConnection httpConnection) throws URIException { final Protocol protocol = httpConnection.getProtocol(); if (protocol == null) { return uri.getURI(); }//from w w w .jav a 2 s. com final StringBuilder sb = new StringBuilder(); final String scheme = protocol.getScheme(); sb.append(scheme).append("://"); sb.append(host); // if port is default port number. if (port != SKIP_DEFAULT_PORT) { sb.append(':').append(port); } sb.append(uri.getURI()); return sb.toString(); }
From source file:edu.utah.further.core.ws.HttpResponseTo.java
/** * Generates HTTP request line according to the specified attributes. * // w w w . j a v a 2 s. c o m * @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(final HttpConnection connection, final String name, final String requestPath, final String query, final String version) { final StringBuffer buf = new StringBuffer(); // Append method name buf.append(name).append(Strings.SPACE_STRING); // Absolute or relative URL? if (!connection.isTransparent()) { final 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(Strings.SPACE_STRING).append(version).append(Strings.UNIX_NEW_LINE_STRING); return buf.toString(); }
From source file:au.edu.monash.merc.capture.util.httpclient.ssl.HostConfigurationWithStickyProtocol.java
/** * 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>// w ww.j a v a 2s. com * 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); }
From source file:au.edu.monash.merc.capture.util.httpclient.ssl.HttpHostFactory.java
/** * 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.//from w w w .j ava 2 s . c om */ 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; }
From source file:ch.cyberduck.core.http.StickyHostConfiguration.java
/** * 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/>// w w w . j a va 2s .c o m * This implementation returns the current Protocol if it has the given * scheme; otherwise it returns the Protocol registered for that scheme. * * @param scheme * @return */ protected org.apache.commons.httpclient.protocol.Protocol getCachedProtocol(String scheme) { final org.apache.commons.httpclient.protocol.Protocol oldProtocol = getProtocol(); if (oldProtocol != null) { if (oldProtocol.getScheme().equalsIgnoreCase(scheme)) { // The old {rotocol has the desired scheme. return oldProtocol; // Retain it. } } log.warn("No cached protocol for:" + scheme); return org.apache.commons.httpclient.protocol.Protocol.getProtocol(scheme); }
From source file:com.axelor.apps.crm.service.CalendarService.java
public boolean testConnect(Calendar cal) throws MalformedURLException, ObjectStoreException { boolean connected = false; PathResolver RESOLVER = getPathResolver(cal.getTypeSelect()); Protocol protocol = getProtocol(cal.getIsSslConnection()); URL url = new URL(protocol.getScheme(), cal.getUrl(), cal.getPort(), ""); ICalendarStore store = new ICalendarStore(url, RESOLVER); try {//from w ww.ja v a 2 s.com connected = store.connect(cal.getLogin(), cal.getPassword()); } finally { store.disconnect(); } return connected; }
From source file:com.axelor.apps.crm.service.CalendarService.java
@Transactional public void sync(Calendar calendar) throws ICalendarException, MalformedURLException { PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect()); Protocol protocol = getProtocol(calendar.getIsSslConnection()); URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), ""); ICalendarStore store = new ICalendarStore(url, RESOLVER); try {//from ww w . j a va 2 s . c o m if (calendar.getLogin() != null && calendar.getPassword() != null && store.connect(calendar.getLogin(), calendar.getPassword())) { List<CalDavCalendarCollection> colList = store.getCollections(); if (!colList.isEmpty()) { calendar = doSync(calendar, colList.get(0)); calendarRepo.save(calendar); } } else { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)), IException.CONFIGURATION_ERROR); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } }
From source file:com.axelor.apps.crm.service.CalendarService.java
public net.fortuna.ical4j.model.Calendar getCalendar(String uid, Calendar calendar) throws ICalendarException, MalformedURLException { net.fortuna.ical4j.model.Calendar cal = null; PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect()); Protocol protocol = getProtocol(calendar.getIsSslConnection()); URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), ""); ICalendarStore store = new ICalendarStore(url, RESOLVER); try {/*from www.j a va 2 s . c om*/ if (store.connect(calendar.getLogin(), calendar.getPassword())) { List<CalDavCalendarCollection> colList = store.getCollections(); if (!colList.isEmpty()) { CalDavCalendarCollection collection = colList.get(0); cal = collection.getCalendar(uid); } } else { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)), IException.CONFIGURATION_ERROR); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } return cal; }
From source file:com.axelor.apps.crm.service.CalendarService.java
public void removeEventFromIcal(Event event) throws MalformedURLException, ICalendarException { if (event.getCalendarCrm() != null && !Strings.isNullOrEmpty(event.getUid())) { Calendar calendar = event.getCalendarCrm(); PathResolver RESOLVER = getPathResolver(calendar.getTypeSelect()); Protocol protocol = getProtocol(calendar.getIsSslConnection()); URL url = new URL(protocol.getScheme(), calendar.getUrl(), calendar.getPort(), ""); ICalendarStore store = new ICalendarStore(url, RESOLVER); try {//from ww w. ja v a2s . c o m if (store.connect(calendar.getLogin(), calendar.getPassword())) { List<CalDavCalendarCollection> colList = store.getCollections(); if (!colList.isEmpty()) { CalDavCalendarCollection collection = colList.get(0); final Map<String, VEvent> remoteEvents = new HashMap<>(); for (VEvent item : ICalendarStore.getEvents(collection)) { remoteEvents.put(item.getUid().getValue(), item); } VEvent target = remoteEvents.get(event.getUid()); removeCalendar(collection, target.getUid().getValue()); } } else { throw new AxelorException(String.format(I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)), IException.CONFIGURATION_ERROR); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } } }
From source file:com.twinsoft.convertigo.beans.connectors.SiteClipperConnector.java
private synchronized HostConfiguration getHostConfiguration(Shuttle shuttle) throws EngineException, MalformedURLException { if (hostConfiguration != null) { String host = hostConfiguration.getHost(); if (isCompatibleConfiguration(host != null && host.equals(shuttle.getRequest(QueryPart.host)))) { if (isCompatibleConfiguration(hostConfiguration.getPort() == shuttle.getRequestPort())) { Protocol protocol = hostConfiguration.getProtocol(); String scheme = (protocol == null) ? "" : protocol.getScheme(); if (isCompatibleConfiguration( scheme != null && scheme.equals(shuttle.getRequest(QueryPart.scheme)))) { if (Engine.theApp.proxyManager.isEnabled()) { String proxyHost = hostConfiguration.getProxyHost(); if (proxyHost == null) { proxyHost = ""; }//from w ww . j a v a 2 s . c o m if (isCompatibleConfiguration( proxyHost.equals(Engine.theApp.proxyManager.getProxyServer()))) { //don't test the proxy port if the proxy host is null if (isCompatibleConfiguration(hostConfiguration .getProxyPort() == Engine.theApp.proxyManager.getProxyPort())) { isCompatibleConfiguration( hostConfiguration.getParams().getParameter("hostConfId") .equals(Engine.theApp.proxyManager.getHostConfId())); } } } } } } } if (hostConfiguration == null) { Engine.logSiteClipper.debug("(SiteClipperConnector) create a new HostConfiguration"); hostConfiguration = new HostConfiguration(); String host = shuttle.getRequest(QueryPart.host); if (shuttle.getRequestScheme() == Scheme.https) { Engine.logSiteClipper.debug("(SiteClipperConnector) Setting up SSL properties"); certificateManager.collectStoreInformation(context); Engine.logSiteClipper.debug( "(SiteClipperConnector) CertificateManager has changed: " + certificateManager.hasChanged); Engine.logSiteClipper .debug("(SiteClipperConnector) Using MySSLSocketFactory for creating the SSL socket"); Protocol myhttps = new Protocol("https", MySSLSocketFactory.getSSLSocketFactory(certificateManager.keyStore, certificateManager.keyStorePassword, certificateManager.trustStore, certificateManager.trustStorePassword, trustAllServerCertificates), shuttle.getRequestPort()); hostConfiguration.setHost(host, shuttle.getRequestPort(), myhttps); } else { hostConfiguration.setHost(host, shuttle.getRequestPort()); } URL requestUrl = new URL(shuttle.getRequestUrl()); Engine.theApp.proxyManager.setProxy(hostConfiguration, context.httpState, requestUrl); } return hostConfiguration; }