List of usage examples for org.apache.commons.httpclient.contrib.ssl EasySSLProtocolSocketFactory EasySSLProtocolSocketFactory
public EasySSLProtocolSocketFactory()
From source file:edu.internet2.middleware.shibboleth.idp.profile.saml2.SLOProfileHandler.java
/** * Creates Http connection.//from ww w .j a v a 2 s . co m * * @param serviceLogoutInfo * @param endpoint * @return * @throws URIException * @throws GeneralSecurityException * @throws IOException */ private HttpConnection createHttpConnection(LogoutInformation serviceLogoutInfo, Endpoint endpoint) throws URIException, GeneralSecurityException, IOException { HttpClientBuilder httpClientBuilder = new HttpClientBuilder(); httpClientBuilder.setContentCharSet("UTF-8"); SecureProtocolSocketFactory sf = new EasySSLProtocolSocketFactory(); httpClientBuilder.setHttpsProtocolSocketFactory(sf); //build http connection HttpClient httpClient = httpClientBuilder.buildClient(); HostConfiguration hostConfig = new HostConfiguration(); URI location = new URI(endpoint.getLocation()); hostConfig.setHost(location); LogoutRequestConfiguration config = (LogoutRequestConfiguration) getProfileConfiguration( serviceLogoutInfo.getEntityID(), getProfileId()); if (log.isDebugEnabled()) { log.debug("Creating new HTTP connection with the following timeouts:"); log.debug("Maximum waiting time for the connection pool is {}", config.getBackChannelConnectionPoolTimeout()); log.debug("Timeout for connection establishment is {}", config.getBackChannelConnectionTimeout()); log.debug("Timeout for soap response is {}", config.getBackChannelResponseTimeout()); } HttpConnection httpConn = null; try { httpConn = httpClient.getHttpConnectionManager().getConnectionWithTimeout(hostConfig, config.getBackChannelConnectionPoolTimeout()); } catch (ConnectionPoolTimeoutException e) { return null; } HttpConnectionParams params = new HttpConnectionParams(); params.setConnectionTimeout(config.getBackChannelConnectionTimeout()); params.setSoTimeout(config.getBackChannelResponseTimeout()); httpConn.setParams(params); return httpConn; }
From source file:com.cloud.network.cisco.CiscoVnmcConnectionImpl.java
private String sendRequest(String service, String xmlRequest) throws ExecutionException { HttpClient client = new HttpClient(); String response = null;//w w w .j a v a2s.co m PostMethod method = new PostMethod("/xmlIM/" + service); method.setRequestBody(xmlRequest); try { org.apache.commons.httpclient.protocol.Protocol myhttps = new org.apache.commons.httpclient.protocol.Protocol( "https", new EasySSLProtocolSocketFactory(), 443); client.getHostConfiguration().setHost(_ip, 443, myhttps); int statusCode = client.executeMethod(method); if (statusCode != HttpStatus.SC_OK) { throw new Exception("Error code : " + statusCode); } response = method.getResponseBodyAsString(); } catch (Exception e) { System.out.println(e.getMessage()); throw new ExecutionException(e.getMessage()); } System.out.println(response); return response; }
From source file:oauth.OAuthTokenValidaterStubFactory.java
/** * This is required to create a trusted connection with the external entity. * Have to manually configure it since we use CommonHTTPTransport(axis2 transport) in axis2. * * @return an EasySSLProtocolSocketFactory for SSL communication. */// ww w. ja v a 2s. co m private EasySSLProtocolSocketFactory createProtocolSocketFactory() throws OAuthTokenValidationException { try { EasySSLProtocolSocketFactory easySSLPSFactory = new EasySSLProtocolSocketFactory(); return easySSLPSFactory; } catch (IOException e) { String errorMsg = "Failed to initiate EasySSLProtocolSocketFactory."; throw new OAuthTokenValidationException(errorMsg, e); } catch (GeneralSecurityException e) { String errorMsg = "Failed to set the key material in easy ssl factory."; throw new OAuthTokenValidationException(errorMsg, e); } }
From source file:org.apache.webdav.cmd.Slide.java
public static void main(String[] args) { Client client = new Client(System.in, System.out); String remoteHost = null;/*from w w w. ja va 2s . co m*/ //////////// BEGIN Command line arguments ////////////// String argOptions = null; // parse arguments for (int i = 0; i < args.length; i++) { if (args[i].startsWith("-")) { if (argOptions != null) argOptions += args[i].substring(1); else argOptions = args[i]; } else { remoteHost = args[i]; } } // print options if (argOptions != null) { char option; for (int i = 0; i < argOptions.length(); i++) { option = argOptions.charAt(i); switch (option) { case '-': break; case 'h': printCmdLineUsage(); break; case 'v': System.out.println(version); break; case 'd': client.setDebug(Client.DEBUG_ON); break; case 's': Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); break; default: System.exit(-1); } } } //////////// END Command line arguments ////////////// if (remoteHost != null) { client.connect(remoteHost); } client.run(); }
From source file:org.cloudfoundry.identity.uaa.provider.saml.idp.SamlServiceProviderConfigurator.java
protected ExtendedMetadataDelegate configureURLMetadata(SamlServiceProvider provider) throws MetadataProviderException { ProtocolSocketFactory socketFactory = null; SamlServiceProviderDefinition def = provider.getConfig().clone(); if (def.getMetaDataLocation().startsWith("https")) { try {//from ww w. j av a2 s . c o m socketFactory = new EasySSLProtocolSocketFactory(); } catch (GeneralSecurityException | IOException e) { throw new MetadataProviderException("Error instantiating SSL/TLS socket factory.", e); } } else { socketFactory = new DefaultProtocolSocketFactory(); } ExtendedMetadata extendedMetadata = new ExtendedMetadata(); extendedMetadata.setAlias(provider.getEntityId()); FixedHttpMetaDataProvider fixedHttpMetaDataProvider; try { fixedHttpMetaDataProvider = FixedHttpMetaDataProvider.buildProvider(dummyTimer, getClientParams(), adjustURIForPort(def.getMetaDataLocation()), new RestTemplate(UaaHttpRequestUtils.createRequestFactory(def.isSkipSslValidation())), this.contentCache ); } catch (URISyntaxException e) { throw new MetadataProviderException("Invalid metadata URI: " + def.getMetaDataLocation(), e); } fixedHttpMetaDataProvider.setSocketFactory(socketFactory); byte[] metadata = fixedHttpMetaDataProvider.fetchMetadata(); def.setMetaDataLocation(new String(metadata, StandardCharsets.UTF_8)); return configureXMLMetadata(provider); }
From source file:org.deegree.portal.wac.WAClient.java
/** * performs a GetCapabilities request against the WSS that is assigned to a client * /*w w w.j av a 2 s . co m*/ * @return Capabilities document if request was successful otherwise an exception document will * be returned * @throws WACException */ public Document performGetCapabilities() throws WACException { Document doc; try { StringBuffer sb = new StringBuffer(200); sb.append(path).append("?service=WSS&request=GetCapabilities&version=1.0.0"); HttpClient httpclient = new HttpClient(); httpclient = WebUtils.enableProxyUsage(httpclient, new URL(path)); EasySSLProtocolSocketFactory fac = new EasySSLProtocolSocketFactory(); Protocol myhttps = new Protocol("https", (ProtocolSocketFactory) fac, port); httpclient.getHostConfiguration().setHost(host, port, myhttps); GetMethod httpget = new GetMethod(sb.toString()); httpclient.executeMethod(httpget); extractContentType(httpget.getResponseHeader("")); XMLFragment xml = new XMLFragment(); InputStream is = httpget.getResponseBodyAsStream(); xml.load(is, path); is.close(); doc = xml.getRootElement().getOwnerDocument(); } catch (IOException e) { throw new WACException("can not access WSS", e); } catch (SAXException e) { throw new WACException("could not parse result from WSS GetCapabilities request", e); } return doc; }
From source file:org.deegree.portal.wac.WAClient.java
/** * performs a GetSession request against the WSS that is assigned to a client. The method * assumed that user/password (urn:x-gdi-nrw:authnMethod:1.0:password) is used for * authentication/*from ww w . ja va 2s .com*/ * * @param user * name of the user who like to get a session * @param password * password of the user * @return GetSession result string if request was successful, otherwise ? * @throws WACException */ public String performGetSession(String user, String password) throws WACException { String s = null; try { StringBuffer sb = new StringBuffer(200); sb.append(path).append("?service=WSS&request=GetSession&version=1.0.0&"); sb.append("AUTHMETHOD=urn:x-gdi-nrw:authnMethod:1.0:password&"); sb.append("CREDENTIALS=").append(user).append(',').append(password); HttpClient httpclient = new HttpClient(); httpclient = WebUtils.enableProxyUsage(httpclient, new URL(path)); EasySSLProtocolSocketFactory fac = new EasySSLProtocolSocketFactory(); Protocol myhttps = new Protocol("https", (ProtocolSocketFactory) fac, port); httpclient.getHostConfiguration().setHost(host, port, myhttps); GetMethod httpget = new GetMethod(sb.toString()); httpclient.executeMethod(httpget); extractContentType(httpget.getResponseHeader("")); InputStream is = httpget.getResponseBodyAsStream(); InputStreamReader ireader = new InputStreamReader(is); BufferedReader br = new BufferedReader(ireader); StringBuffer sb2 = new StringBuffer(5000); while ((s = br.readLine()) != null) { sb2.append(s); } s = sb2.toString(); br.close(); } catch (UnknownHostException e) { throw new WACException("Host: " + host + " is not known. Host must be set without protocol", e); } catch (IOException e) { throw new WACException("can not access WSS", e); } return s; }
From source file:org.deegree.portal.wac.WAClient.java
/** * closes a Session by sending a CloseSession request against the WSS that is assigned to a * client. If the passed sessionID is not valid an WSS exception document will be returned * instead of the success message/answer. * //from w w w. ja v a 2 s .com * @param sessionID * @return document that indicates that session has been closed otherwise an exception document * will be returned * @throws WACException */ public Document performCloseSession(String sessionID) throws WACException { Document doc; try { StringBuffer sb = new StringBuffer(200); sb.append(path).append("?service=WSS&request=CloseSession&version=1.0.0&"); sb.append("SESSIONID=").append(sessionID); HttpClient httpclient = new HttpClient(); httpclient = WebUtils.enableProxyUsage(httpclient, new URL(path)); EasySSLProtocolSocketFactory fac = new EasySSLProtocolSocketFactory(); Protocol myhttps = new Protocol("https", (ProtocolSocketFactory) fac, port); httpclient.getHostConfiguration().setHost(host, port, myhttps); GetMethod httpget = new GetMethod(sb.toString()); httpclient.executeMethod(httpget); extractContentType(httpget.getResponseHeader("")); XMLFragment xml = new XMLFragment(); InputStream is = httpget.getResponseBodyAsStream(); xml.load(is, path); is.close(); doc = xml.getRootElement().getOwnerDocument(); } catch (IOException e) { throw new WACException("can not access WSS", e); } catch (SAXException e) { throw new WACException("could not parse result from WSS GetCapabilities request", e); } return doc; }
From source file:org.deegree.portal.wac.WAClient.java
/** * performs a DoService request against the WSS that is assigned to a client. According to the * WSS specification the request will be send using HTTP POST.<BR> * The method uses a user/password authentification * /* w w w . j a v a 2 s .c o m*/ * @see #performDoService(String, String) * * @param request * request to perform * @param user * name of the user who like to get a session * @param password * password of the user * @return result of the passed request. the type depends on target service and request * @throws WACException */ public InputStream performDoService(String request, String user, String password) throws WACException { InputStream is = null; try { StringBuffer sb = new StringBuffer(2000); sb.append(path).append("?service=WSS&request=DoService&version=1.0.0&"); sb.append("AUTHMETHOD=USERPASSWORD&"); sb.append("CREDENTIALS=").append(user).append(';').append(password); sb.append("&SERVICEREQUEST=").append(URLEncoder.encode(request, CharsetUtils.getSystemCharset())); HttpClient httpclient = new HttpClient(); httpclient = WebUtils.enableProxyUsage(httpclient, new URL(path)); EasySSLProtocolSocketFactory fac = new EasySSLProtocolSocketFactory(); Protocol myhttps = new Protocol("https", (ProtocolSocketFactory) fac, port); httpclient.getHostConfiguration().setHost(host, port, myhttps); GetMethod httpget = new GetMethod(sb.toString()); httpclient.executeMethod(httpget); extractContentType(httpget.getResponseHeader("")); is = httpget.getResponseBodyAsStream(); } catch (IOException e) { throw new WACException("can not access WSS", e); } return is; }
From source file:org.deegree.portal.wac.WAClient.java
/** * performs a DoService request against the WSS that is assigned to a client. According to the * WSS specification the request will be send using HTTP POST.<BR> * The method uses an authentification through a sessionID * /* w ww .jav a2 s .c o m*/ * @see #performDoService(String, String, String) * * @param request * request to perform * @param sessionID * id to authentificate a user * @return result of the passed request. the type depends on target service and request * @throws WACException */ public InputStream performDoService(String request, String sessionID) throws WACException { InputStream is = null; try { StringBuffer sb = new StringBuffer(2000); sb.append(path).append("?service=WSS&request=DoService&version=1.0.0&"); sb.append("AUTHMETHOD=urn:x-gdi-nrw:authnMethod:1.0:session&"); sb.append("DCP=http_get&"); sb.append("CREDENTIALS=").append(sessionID).append("&"); sb.append("SERVICEREQUEST=").append(URLEncoder.encode(request, CharsetUtils.getSystemCharset())); HttpClient httpclient = new HttpClient(); httpclient = WebUtils.enableProxyUsage(httpclient, new URL(path)); EasySSLProtocolSocketFactory fac = new EasySSLProtocolSocketFactory(); Protocol myhttps = new Protocol("https", (ProtocolSocketFactory) fac, port); httpclient.getHostConfiguration().setHost(host, port, myhttps); GetMethod httpget = new GetMethod(sb.toString()); httpclient.executeMethod(httpget); extractContentType(httpget.getResponseHeader("")); is = httpget.getResponseBodyAsStream(); } catch (IOException e) { throw new WACException("can not access WSS", e); } return is; }