org.apache.commons.httpclient.protocol.Protocol Java Examples

The following examples show how to use org.apache.commons.httpclient.protocol.Protocol. 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: CommonsHttpTransportTests.java    From elasticsearch-hadoop with Apache License 2.0 6 votes vote down vote up
@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));
}
 
Example #2
Source File: ServiceUtil.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
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;
	}
 
Example #3
Source File: HttpClient3RequestWrapper.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
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: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 6 votes vote down vote up
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 #5
Source File: HttpClientTransmitterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #6
Source File: ServiceUtil.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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;
	}
 
Example #7
Source File: CertificadoService.java    From Java_Certificado with MIT License 6 votes vote down vote up
public static void inicializaCertificado(Certificado certificado, InputStream cacert) throws CertificadoException {

        Optional.ofNullable(certificado).orElseThrow(() -> new IllegalArgumentException("Certificado não pode ser nulo."));
        Optional.ofNullable(cacert).orElseThrow(() -> new IllegalArgumentException("Cacert não pode ser nulo."));

        try {

            KeyStore keyStore = getKeyStore(certificado);
            if (certificado.isAtivarProperties()) {
                CertificadoProperties.inicia(certificado, cacert);
            } else {
                SocketFactoryDinamico socketFactory = new SocketFactoryDinamico(keyStore,certificado.getNome(),certificado.getSenha(), cacert,
                        certificado.getSslProtocol());
                Protocol protocol = new Protocol("https", socketFactory, 443);
                Protocol.registerProtocol("https", protocol);
            }

        } catch (KeyStoreException | NoSuchAlgorithmException | KeyManagementException | CertificateException | IOException e) {
            throw new CertificadoException(e.getMessage());
        }

    }
 
Example #8
Source File: GetSSLCert.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
public static javax.security.cert.X509Certificate getCert(String host, int port) {
	GetCertSSLProtocolSocketFactory certFactory = new GetCertSSLProtocolSocketFactory();
	Protocol myhttps = new Protocol("https", certFactory, port);
	HttpClient httpclient = new HttpClient();
	httpclient.getHostConfiguration().setHost(host, port, myhttps);
	GetMethod httpget = new GetMethod("/");
	try {
	  httpclient.executeMethod(httpget);
	  //System.out.println(httpget.getStatusLine());
	} catch (Throwable t) {
		//do nothing
	}
	
	finally {
	  httpget.releaseConnection();
	}
	
	return certFactory.getCertificate();
}
 
Example #9
Source File: Manager.java    From zap-extensions with Apache License 2.0 6 votes vote down vote up
private void createHttpClient() {
    Protocol protocol = Protocol.getProtocol("https");
    if (protocol == null) {
        // ZAP: Dont override an existing protocol - it causes problems with ZAP
        Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443);
        Protocol.registerProtocol("https", easyhttps);
    }
    initialState = new HttpState();

    MultiThreadedHttpConnectionManager connectionManager =
            new MultiThreadedHttpConnectionManager();
    connectionManager.getParams().setDefaultMaxConnectionsPerHost(1000);
    connectionManager.getParams().setMaxTotalConnections(1000);

    // connectionManager.set

    httpclient = new HttpClient(connectionManager);
    // httpclient.

}
 
Example #10
Source File: ServiceUtil.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
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;
	}
 
Example #11
Source File: HttpHostFactory.java    From http4e with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #12
Source File: HttpConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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;
}
 
Example #13
Source File: HttpConnection.java    From http4e with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #14
Source File: HttpHost.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #15
Source File: HttpPerformer.java    From http4e with Apache License 2.0 6 votes vote down vote up
private void doSSL( HttpClient client, HostConfiguration hostConf, String host, int port){
   if (hostConf.getProtocol().isSecure()) {

      // System.setProperty("javax.net.ssl.trustStore", sslKeystore);
      // Protocol sslPprotocol = new Protocol("https", new
      // org.apache.commons.httpclient.contrib.ssl.EasySSLProtocolSocketFactory(),
      // 443);
      // client.getHostConfiguration().setHost(host, 443, sslPprotocol);

      try {
         ProtocolSocketFactory factory = new InsecureSSLProtocolSocketFactory();
         Protocol https = new Protocol("https", factory, port);
         Protocol.registerProtocol("https", https);
         client.getHostConfiguration().setHost(host, port, https);

      } catch (GeneralSecurityException e) {
         throw new CoreException(CoreException.SSL, e);
      }
   }
}
 
Example #16
Source File: NeutronRestApi.java    From cloudstack with Apache License 2.0 5 votes vote down vote up
protected NeutronRestApi(final Class<? extends HttpMethodBase> httpClazz, final String protocol, final int port) {
    client = createHttpClient();
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
    this.httpClazz = httpClazz;

    try {
        // Cast to ProtocolSocketFactory to avoid the deprecated constructor
        // with the SecureProtocolSocketFactory parameter
        Protocol.registerProtocol(protocol, new Protocol(protocol, (ProtocolSocketFactory) new TrustingProtocolSocketFactory(), HTTPS_PORT));
    } catch (IOException e) {
        s_logger.warn("Failed to register the TrustingProtocolSocketFactory, falling back to default SSLSocketFactory", e);
    }
}
 
Example #17
Source File: HttpConnection.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the protocol used to establish the connection
 * 
 * @param protocol The protocol to use.
 * 
 * @throws IllegalStateException if the connection is already open
 */
public void setProtocol(Protocol protocol) {
    assertNotOpen();

    if (protocol == null) {
        throw new IllegalArgumentException("protocol is null");
    }

    protocolInUse = protocol;

}
 
Example #18
Source File: HostConfiguration.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Sets the given host, port and protocol.
 *   
 * @param host the host(IP or DNS name)
 * @param port The port
 * @param protocol the protocol
 */
public synchronized void setHost(final String host, int port, final Protocol protocol) {
    if (host == null) {
        throw new IllegalArgumentException("host must not be null");   
    }
    if (protocol == null) {
        throw new IllegalArgumentException("protocol must not be null");   
    }
    this.host = new HttpHost(host, port, protocol);
}
 
Example #19
Source File: HostConfiguration.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the protocol.
 * @return The protocol.
 */
public synchronized Protocol getProtocol() {
    if (this.host != null) {
        return this.host.getProtocol();
    } else {
        return null;
    }
}
 
Example #20
Source File: MultiThreadedHttpConnectionManager.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public Protocol getProtocol() {
    if (hasConnection()) {
        return wrappedConnection.getProtocol();
    } else {
        return null;
    }
}
 
Example #21
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
public Protocol getProtocol(boolean isSslConnection) {

    if (isSslConnection) {
      return Protocol.getProtocol("https");
    } else {
      return Protocol.getProtocol("http");
    }
  }
 
Example #22
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #23
Source File: ServiceUtilTest.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: HttpsCallerProcess.java    From zap-extensions with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("URL not set! Please give an URL as argument.");
        System.exit(-1);
    }

    try {
        String urlStrg = args[0];
        URL url = new URL(urlStrg);
        if (!HTTPS.equals(url.getProtocol())) {
            throw new IllegalArgumentException("Please choose https protocol! " + url);
        }

        Protocol.registerProtocol(
                HTTPS, new Protocol(HTTPS, (ProtocolSocketFactory) new SSLConnector(), 443));

        HttpMessage msg = accessURL(url);
        if (msg != null) {
            System.out.println(msg.getResponseHeader());
        }
        System.out.println("--- END of call -------------------------------------------------");
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    System.out.close();
    System.err.close();
}
 
Example #25
Source File: Soap.java    From openxds with Apache License 2.0 5 votes vote down vote up
public void soapSend(OMElement body, Protocol protocol, String endpoint, boolean mtom, 
		boolean addressing, boolean soap12, String action) 
throws  XdsException, AxisFault {
	
	this.expectedReturnAction = null;
	this.mtom = mtom;
	this.addressing = addressing;
	this.soap12 = soap12;
	
	soapSend(body, protocol, endpoint, action);
}
 
Example #26
Source File: ICalendarService.java    From axelor-open-suite with GNU Affero General Public License v3.0 5 votes vote down vote up
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 #27
Source File: Shibboleth3ConfService.java    From oxTrust with MIT License 5 votes vote down vote up
public String saveSpMetadataFile(String spMetaDataURL, String spMetadataFileName) {
	if (StringHelper.isEmpty(spMetaDataURL)) {
		return null;
	}

	if (appConfiguration.getShibboleth3IdpRootDir() == null) {
		throw new InvalidConfigurationException("Failed to save SP meta-data file due to undefined IDP root folder");
	}

	HTTPFileDownloader.setEasyhttps(new Protocol("https", new EasyCASSLProtocolSocketFactory(), 443));
	String spMetadataFileContent = HTTPFileDownloader.getResource(spMetaDataURL, "application/xml, text/xml", null, null);

	if (StringHelper.isEmpty(spMetadataFileContent)) {
		return null;
	}

	String idpMetadataTempFolder = getIdpMetadataTempDir();
	String tempFileName = getTempMetadataFilename(idpMetadataTempFolder, spMetadataFileName);
	String spMetadataFile = idpMetadataTempFolder + tempFileName;
	try {
		boolean result = documentStoreService.saveDocument(spMetadataFile, spMetadataFileContent, UTF_8);
		if (result) {
			return tempFileName;
		}
	} catch (Exception ex) {
		log.error("Failed to write SP meta-data file '{}'", spMetadataFile, ex);
	}

	return null;
}
 
Example #28
Source File: MultiThreadedHttpConnectionManager.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void setProtocol(Protocol protocol) {
    if (hasConnection()) {
        wrappedConnection.setProtocol(protocol);
    } else {
        // do nothing
    }
}
 
Example #29
Source File: MonitorServlet.java    From freeacs with MIT License 5 votes vote down vote up
public MonitorServlet(Properties properties, ExecutorWrapper executorWrapper) {
  this.properties = properties;
  this.executorWrapper = executorWrapper;
  ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory();
  Protocol https = new Protocol("https", socketFactory, 443);
  Protocol.registerProtocol("https", https);
}
 
Example #30
Source File: SoapCall.java    From openxds with Apache License 2.0 5 votes vote down vote up
public void run() {
	try {
		Protocol protocol = ConnectionUtil.getProtocol(connection);
		String epr = ConnectionUtil.getTransactionEndpoint(connection);
		Soap soap = new Soap();
		soap.soapCall(request, protocol, epr, mtom, true, true, action, null);
		ag.store(homeId, soap.getResult());
	}catch(Exception e){
		String msg = "Fail to get a response from the community " + homeId + " - " + e.getMessage();
		OMElement response = service.start_up_error(request, e, AppendixV.REGISTRY_ACTOR, msg);
		service.generateLogMessage(response);
		ag.store(homeId, response);
	}
}