Java Code Examples for org.apache.commons.httpclient.protocol.Protocol#getScheme()
The following examples show how to use
org.apache.commons.httpclient.protocol.Protocol#getScheme() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpHostFactory.java From http4e with Apache License 2.0 | 6 votes |
/** * 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; }
Example 2
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
public net.fortuna.ical4j.model.Calendar getCalendar(String uid, ICalendar 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 { 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( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } return cal; }
Example 3
Source File: HttpClient3RequestWrapper.java From pinpoint with Apache License 2.0 | 6 votes |
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(); } 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(); }
Example 4
Source File: HostConfigurationWithStickyProtocol.java From http4e with Apache License 2.0 | 5 votes |
/** * 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); }
Example 5
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
public void testConnect(ICalendar cal) throws MalformedURLException, ObjectStoreException { 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 { store.connect(cal.getLogin(), getCalendarDecryptPassword(cal.getPassword())); } finally { store.disconnect(); } }
Example 6
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
@Transactional(rollbackOn = {Exception.class}) protected void sync(ICalendar calendar, LocalDateTime startDate, LocalDateTime endDate) 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 { String password = getCalendarDecryptPassword(calendar.getPassword()); if (calendar.getLogin() != null && calendar.getPassword() != null && store.connect(calendar.getLogin(), password)) { List<CalDavCalendarCollection> colList = store.getCollections(); if (!colList.isEmpty()) { calendar = doSync(calendar, colList.get(0), startDate, endDate); calendar.setLastSynchronizationDateT( Beans.get(AppBaseService.class).getTodayDateTime().toLocalDateTime()); Beans.get(ICalendarRepository.class).save(calendar); } } else { throw new AxelorException( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } }
Example 7
Source File: ICalendarService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 5 votes |
public void removeEventFromIcal(ICalendarEvent event) throws MalformedURLException, ICalendarException { if (event.getCalendar() != null && !Strings.isNullOrEmpty(event.getUid())) { ICalendar calendar = event.getCalendar(); 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 { if (store.connect( calendar.getLogin(), getCalendarDecryptPassword(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()); if (target != null) removeCalendar(collection, target.getUid().getValue()); } } else { throw new AxelorException( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.CALENDAR_NOT_VALID)); } } catch (Exception e) { throw new ICalendarException(e); } finally { store.disconnect(); } } }
Example 8
Source File: ProtocolAwareHostConfiguration.java From elasticsearch-hadoop with Apache License 2.0 | 5 votes |
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); }