List of usage examples for org.apache.commons.httpclient.contrib.ssl EasySSLProtocolSocketFactory EasySSLProtocolSocketFactory
public EasySSLProtocolSocketFactory()
From source file:br.org.acessobrasil.nucleuSilva.util.PegarPaginaWEB.java
public PegarPaginaWEB() { // me parece que o construtor aqui apenas inicializa alguns parametros e // registra o protocolo httpClient = new HttpClient(); ps = new PainelSenha(); httpClient.getParams().setParameter(CredentialsProvider.PROVIDER, ps); // coloca // no//from ww w . ja v a 2s .co m // objeto // httpclient // o // parametro // provider // associado // a ps EasySSLProtocolSocketFactory sssl = new EasySSLProtocolSocketFactory(); // StrictSSLProtocolSocketFactory sssl = new // StrictSSLProtocolSocketFactory(); // sssl.setHostnameVerification(false); Protocol easyhttps = new Protocol("https", sssl, 443); Protocol.registerProtocol("https", easyhttps); }
From source file:com.twinsoft.convertigo.engine.util.RemoteAdmin.java
public void login(String username, String password) throws RemoteAdminException, EngineException { PostMethod loginMethod = null;// w ww . ja v a2s .c o m try { String loginServiceURL = (bHttps ? "https" : "http") + "://" + serverBaseUrl + "/admin/services/engine.Authenticate"; Protocol myhttps = null; hostConfiguration = httpClient.getHostConfiguration(); if (bHttps) { if (bTrustAllCertificates) { ProtocolSocketFactory socketFactory = new EasySSLProtocolSocketFactory(); myhttps = new Protocol("https", socketFactory, serverPort); Protocol.registerProtocol("https", myhttps); hostConfiguration.setHost(host, serverPort, myhttps); } } if (("").equals(username) || username == null) { throw new RemoteAdminException( "Unable to connect to the Convertigo server: \"Server administrator\" field is empty."); } if (("").equals(password) || password == null) { throw new RemoteAdminException( "Unable to connect to the Convertigo server: \"Password\" field is empty."); } URL url = new URL(loginServiceURL); HttpState httpState = new HttpState(); httpClient.setState(httpState); // Proxy configuration Engine.theApp.proxyManager.setProxy(hostConfiguration, httpState, url); loginMethod = new PostMethod(loginServiceURL); loginMethod.addParameter("authType", "login"); loginMethod.addParameter("authUserName", username); loginMethod.addParameter("authPassword", password); int returnCode = httpClient.executeMethod(loginMethod); String httpResponse = loginMethod.getResponseBodyAsString(); if (returnCode == HttpStatus.SC_OK) { Document domResponse; try { DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder(); domResponse = parser.parse(new InputSource(new StringReader(httpResponse))); domResponse.normalize(); NodeList nodeList = domResponse.getElementsByTagName("error"); if (nodeList.getLength() != 0) { throw new RemoteAdminException( "Unable to connect to the Convertigo server: wrong username or password."); } } catch (ParserConfigurationException e) { throw new RemoteAdminException("Unable to parse the Convertigo server response: \n" + e.getMessage() + ".\n" + "Received response: " + httpResponse); } catch (IOException e) { throw new RemoteAdminException( "An unexpected error has occured during the Convertigo server login.\n" + "(IOException) " + e.getMessage() + "\n" + "Received response: " + httpResponse, e); } catch (SAXException e) { throw new RemoteAdminException("Unable to parse the Convertigo server response: " + e.getMessage() + ".\n" + "Received response: " + httpResponse); } } else { decodeResponseError(httpResponse); } } catch (HttpException e) { throw new RemoteAdminException("An unexpected error has occured during the Convertigo server login.\n" + "Cause: " + e.getMessage(), e); } catch (UnknownHostException e) { throw new RemoteAdminException( "Unable to find the Convertigo server (unknown host): " + e.getMessage()); } catch (IOException e) { String message = e.getMessage(); if (message.indexOf("unable to find valid certification path") != -1) { throw new RemoteAdminException( "The SSL certificate of the Convertigo server is not trusted.\nPlease check the 'Trust all certificates' checkbox."); } else throw new RemoteAdminException( "Unable to reach the Convertigo server: \n" + "(IOException) " + e.getMessage(), e); } catch (GeneralSecurityException e) { throw new RemoteAdminException( "Unable to reach the Convertigo server: \n" + "(GeneralSecurityException) " + e.getMessage(), e); } finally { Protocol.unregisterProtocol("https"); if (loginMethod != null) loginMethod.releaseConnection(); } }
From source file:com.google.jstestdriver.requesthandlers.RequestHandlersModule.java
@Provides @Singleton//w w w . ja v a 2 s. co m HttpClient provideHttpClient() { Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443)); MultiThreadedHttpConnectionManager manager = new MultiThreadedHttpConnectionManager(); manager.getParams().setDefaultMaxConnectionsPerHost(20); manager.getParams().setMaxTotalConnections(200); HttpClient client = new HttpClient(manager); client.getParams().setCookiePolicy(CookiePolicy.IGNORE_COOKIES); return client; }
From source file:edu.indiana.d2i.htrc.portal.HTRCExperimentalAnalysisServiceClient.java
public List<VMImageDetails> listVMImages(Http.Session session) throws IOException, GeneralSecurityException { String listVMImageUrl = PlayConfWrapper.sloanWsEndpoint() + PlayConfWrapper.listVMImagesUrl(); List<VMImageDetails> vmDetailsList = new ArrayList<VMImageDetails>(); Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); GetMethod getMethod = new GetMethod(listVMImageUrl); getMethod.addRequestHeader("Authorization", "Bearer " + session.get(PortalConstants.SESSION_TOKEN)); getMethod.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); getMethod.addRequestHeader("htrc-remote-user", session.get(PortalConstants.SESSION_USERNAME)); getMethod.addRequestHeader("htrc-remote-user-email", session.get(PortalConstants.SESSION_EMAIL)); int response = client.executeMethod(getMethod); this.responseCode = response; if (response == 200) { String jsonStr = getMethod.getResponseBodyAsString(); log.info(Arrays.toString(getMethod.getRequestHeaders())); JSONParser parser = new JSONParser(); try {/*from w ww . j av a 2 s . c o m*/ Object obj = parser.parse(jsonStr); JSONObject jsonObject = (JSONObject) obj; JSONArray jsonArray = (JSONArray) jsonObject.get("imageInfo"); for (Object aJsonArray : jsonArray) { JSONObject infoObject = (JSONObject) aJsonArray; String name = (String) infoObject.get("imageName"); String description = (String) infoObject.get("imageDescription"); VMImageDetails vmDetails = new VMImageDetails(name, description); if (!vmDetailsList.contains(vmDetails)) { vmDetailsList.add(vmDetails); } } } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } return vmDetailsList; } else { this.responseCode = response; throw new IOException("Response code " + response + " for " + listVMImageUrl + " message: \n " + getMethod.getResponseBodyAsString()); } }
From source file:com.kagilum.intellij.icescrum.IceScrumRepository.java
private boolean extractSettings(String url) { Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); this.setUseHttpAuthentication(true); if (url.indexOf("/p/") > 0) { this.serverUrl = url.substring(0, url.indexOf("/p/")); } else {/*from w w w . ja va 2 s . co m*/ this.serverUrl = null; this.pkey = null; return false; } Pattern p = Pattern.compile("\\d*[A-Z][A-Z0-9]*"); Matcher m = p.matcher(url); if (m.find()) { this.pkey = m.group(0); return true; } else { this.pkey = null; return false; } }
From source file:com.spike.tg4w.htmlunit.HtmlUnitInterpreter.java
public void runTest(File testFile) throws InterpreterException { // Initialize the context InterpreterContext context = new InterpreterContext(this.config); try {//w w w . j ava2s. c o m context.setDebugDir(this.config.debugDir); context.setLogger(this.logger); context.clear(); context.currentFile = testFile.getAbsolutePath(); if (this.config.easyHttps) { logger.info("Enabling EasySSL"); Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); } Action[] actions = null; try { actions = context.loadFile(testFile.getAbsolutePath()); } catch (Exception e) { throw new InterpreterException("Error parsing file: " + testFile.getAbsolutePath(), e, context); } int newac = -1; for (int ac = 0; ac < actions.length; ac++) { Action action = fixAction(context, actions[ac]); logger.stepStart(action, ac); logger.info("isContainer:" + action.isContainer()); try { // set action in context context.currentAction = action; context.currentActionCount = ac; if (action.type.equals("goto")) { handleAction_goto_url(context, action); } else if ("click".equals(action.type)) { if (this.config.thinkTime != -1) { logger.info("Thinking for " + this.config.thinkTime + " ms"); try { Thread.sleep(this.config.thinkTime); } catch (Exception e) { } } handleAction_click(context, action); } else if ("verify-title".equals(action.type)) { handleAction_verify_title(context, action); } else if ("assert-text-exists".equals(action.type)) { handleAction_assert_text_exists(context, action); } else if ("assert-text-does-not-exist".equals(action.type)) { handleAction_assert_text_not_exists(context, action); } else if ("fill".equals(action.type)) { handleAction_fill(context, action); } else if ("select".equals(action.type)) { handleAction_select(context, action); } else if ("check".equals(action.type)) { handleAction_check(context, action); } else if ("alert".equals(action.type)) { logger.warning("TODO: Expecting alert around here: '" + action.value + "'"); } else if ("confirm".equals(action.type)) { logger.info("TODO: Expecting confirm around here: '" + action.xpath + "'. Should click ok? : " + action.value); } else if ("wait-for-ms".equals(action.type)) { int wait4ms = Integer.parseInt(action.value); logger.debug("wait start: " + new java.util.Date() + ", will wait for: " + wait4ms + " ms"); try { Thread.sleep(wait4ms); } catch (InterruptedException e) { } logger.debug("wait end: " + new java.util.Date()); } else if (action.isGotoAction()) { newac = handleAction_goto(context, action); } else if (action.isVariableAction()) { handleAction_setvar(context, action); } else if (action.isContainer()) { boolean evaluationResult = evaluateContainer(context, action); System.out.println("evaluationResult:" + evaluationResult); if (!evaluationResult) { // if not true, jump end + 1 newac = context.findEnd4Container(action).actionIndex + 1; } else { // push container, evaluate next context.pushContainer(action); } } else if (action.isEndContainer()) { Action container = context.popContainer(); if (container.isCondition() != null) { // nothing to do, just a "if", move on } else { Action.DatasetLoop dsl = container.isDatasetLoop(); // loop - increment if it is a dataset loop if (dsl != null) { RuntimeDataset ds = context.getDataset(dsl.dsname); ds.incrementLoop(); } // and jump to container, which will evaluate newac = container.actionIndex; } } else { String errMsg = "action not supported: " + action.type; throw new InterpreterException(errMsg, context); } } finally { try { logger.info("Final browser url: " + getCurrentUrl(context)); } catch (Exception e) { // i don't want to handle any null pointers or such, just ignore it! logger.info("Final browser url: unknown. reason: " + e.getMessage()); } logger.stepEnd(ac); if (newac != -1) { logger.info("Jumping to action: " + newac); ac = newac - 1; newac = -1; } } } logger.info("all actions done!"); } finally { context.destroy(); } }
From source file:edu.indiana.d2i.htrc.portal.HTRCExperimentalAnalysisServiceClient.java
public List<VMStatus> listVMs(Http.Session session) throws GeneralSecurityException, IOException { String listVMUrl = PlayConfWrapper.sloanWsEndpoint() + PlayConfWrapper.showVMUrl(); Protocol easyhttps = new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("https", easyhttps); List<VMStatus> vmList = new ArrayList<VMStatus>(); PostMethod post = new PostMethod(listVMUrl); post.addRequestHeader("Authorization", "Bearer " + session.get(PortalConstants.SESSION_TOKEN)); post.addRequestHeader("Content-Type", "application/x-www-form-urlencoded"); post.addRequestHeader("htrc-remote-user", session.get(PortalConstants.SESSION_USERNAME)); post.addRequestHeader("htrc-remote-user-email", session.get(PortalConstants.SESSION_EMAIL)); int response = client.executeMethod(post); this.responseCode = response; if (response == 200) { String jsonStr = post.getResponseBodyAsString(); JSONParser parser = new JSONParser(); log.info(Arrays.toString(post.getRequestHeaders())); try {//from ww w .j a v a2s . c om Object obj = parser.parse(jsonStr); JSONObject jsonObject = (JSONObject) obj; JSONArray jsonArray = (JSONArray) jsonObject.get("status"); for (Object aJsonArray : jsonArray) { VMStatus vmStatus = new VMStatus(); JSONObject infoObject = (JSONObject) aJsonArray; vmStatus.setVmId((String) infoObject.get("vmid")); vmStatus.setMode((String) infoObject.get("mode")); vmStatus.setState((String) infoObject.get("state")); vmStatus.setVncPort((Long) infoObject.get("vncport")); vmStatus.setSshPort((Long) infoObject.get("sshport")); vmStatus.setPublicIp((String) infoObject.get("publicip")); vmStatus.setVcpu((Long) infoObject.get("vcpus")); vmStatus.setMemory((Long) infoObject.get("memSize")); vmStatus.setVolumeSize((Long) infoObject.get("volumeSize")); vmStatus.setImageName((String) infoObject.get("imageName")); vmStatus.setVmIntialLogingId((String) infoObject.get("vmInitialLoginId")); vmStatus.setVmInitialLogingPassword((String) infoObject.get("vmInitialLoginPassword")); vmList.add(vmStatus); } } catch (ParseException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } else { this.responseCode = response; log.error("Response code " + response + " for " + listVMUrl + " message: \n " + post.getResponseBodyAsString()); vmList = null; // throw new IOException("Response code " + response + " for " + listVMUrl + " message: \n " + post.getResponseBodyAsString()); } return vmList; }
From source file:com.sonicle.webtop.core.app.WebTopApp.java
WebTopApp(ServletContext servletContext) { WebTopApp.webappName = ContextUtils.getWebappFullName(servletContext, false); this.servletContext = servletContext; this.osInfo = OSInfo.build(); this.systemCharset = Charset.forName("UTF-8"); this.systemTimeZone = DateTimeZone.getDefault(); // Ignore SSL checks for old commons-http components. // This is required in order to avoid error when accessing WebDAV // secured servers throught vfs2. Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443)); System.setProperty("net.fortuna.ical4j.timezone.update.enabled", "false"); //System.setProperty("mail.mime.address.strict", "false"); // If necessary set using -D System.setProperty("mail.mime.decodetext.strict", "false"); System.setProperty("mail.mime.decodefilename", "true"); ICalendarUtils.setUnfoldingRelaxed(true); ICalendarUtils.setParsingRelaxed(true); ICalendarUtils.setValidationRelaxed(true); ICalendarUtils.setCompatibilityOutlook(true); ICalendarUtils.setCompatibilityNotes(true); Properties systemProps = System.getProperties(); WebTopProps.checkOldPropsUsage(systemProps); WebTopProps.print(systemProps);/*from w w w . ja v a 2 s . co m*/ //logger.info("getContextPath: {}", context.getContextPath()); //logger.info("getServletContextName: {}", context.getServletContextName()); //logger.info("getVirtualServerName: {}", context.getVirtualServerName()); String configDir = WebTopProps.getWebappsConfigDir(systemProps); if (StringUtils.isBlank(configDir)) { this.webappConfigPath = null; } else { this.webappConfigPath = PathUtils.concatPaths(configDir, ContextUtils.getWebappFullName(servletContext, true)); } this.shiroSecurityManager = buildSecurityManager(); this.adminSubject = buildSysAdminSubject(shiroSecurityManager); }
From source file:edu.umd.cs.buildServer.BuildServerDaemon.java
public static void main(String[] args) throws Exception { CommandLineParser parser = new PosixParser(); Options options = getOptions();//from w ww. j av a2 s . com CommandLine line; try { line = parser.parse(options, args); } catch (Exception e) { printHelp(options); return; } if (line.hasOption("help")) { printHelp(options); return; } String[] remainingArgs = line.getArgs(); Protocol easyhttps = new Protocol("https", new EasySSLProtocolSocketFactory(), 443); Protocol.registerProtocol("easyhttps", easyhttps); BuildServerDaemon buildServer = new BuildServerDaemon(); if (line.hasOption("config")) { String c = line.getOptionValue("config"); buildServer.setConfigFile(c); } else if (remainingArgs.length == 1) buildServer.setConfigFile(remainingArgs[0]); boolean once = line.hasOption("once"); if (line.hasOption("submission")) { once = true; buildServer.getConfig().setProperty(DEBUG_SPECIFIC_SUBMISSION, line.getOptionValue("submission")); if (line.hasOption("testSetup")) buildServer.getConfig().setProperty(DEBUG_SPECIFIC_TESTSETUP, line.getOptionValue("testSetup")); if (line.hasOption("skipDownload")) buildServer.getConfig().setProperty(DEBUG_SKIP_DOWNLOAD, "true"); } else if (line.hasOption("testSetup")) { throw new IllegalArgumentException( "You can only specify a specific test setup if you also specify a specific submission"); } if (line.hasOption("projectNum")) { buildServer.getConfig().setProperty(DEBUG_SPECIFIC_PROJECT, line.getOptionValue("projectNum")); } if (line.hasOption("quiet")) buildServer.setQuiet(true); if (line.hasOption("verify")) buildServer.setVerifyOnly(); if (line.hasOption("course")) { buildServer.getConfig().setProperty(DEBUG_SPECIFIC_COURSE, line.getOptionValue("course")); } if (line.hasOption("logLevel")) buildServer.getConfig().setProperty(LOG4J_THRESHOLD, line.getOptionValue("logLevel")); if (line.hasOption("downloadOnly")) { System.out.println("Setting download only"); buildServer.setDownloadOnly(true); once = true; } if (once) { buildServer.getConfig().setProperty(LOG_DIRECTORY, "console"); buildServer.setDoNotLoop(true); buildServer.getConfig().setProperty(DEBUG_PRESERVE_SUBMISSION_ZIPFILES, "true"); } buildServer.initConfig(); Logger log = buildServer.getLog(); /** Redirect standard out and err to dev null, since clover * writes to standard out and error */ PrintStream systemOut = System.out; PrintStream systemErr = System.err; if (buildServer.isQuiet()) { System.setOut(new PrintStream(new DevNullOutputStream())); System.setErr(new PrintStream(new DevNullOutputStream())); } try { buildServer.executeServerLoop(); if (log != null) log.info("Shutting down"); System.out.println("Shutting down"); timedSystemExit0(); } catch (Throwable e) { buildServer.clearMyPidFile(); if (log != null) log.fatal("BuildServerDaemon got fatal exception; waiting for cron to restart me: ", e); e.printStackTrace(systemErr); System.exit(1); } if (buildServer.isQuiet()) { System.setOut(systemOut); System.setErr(systemErr); } }
From source file:com.sos.VirtualFileSystem.WebDAV.SOSVfsWebDAV.java
/** * * \brief setRootHttpURL/*w ww . jav a2 s .c o m*/ * * \details * * \return void * * @param puser * @param ppassword * @param phost * @param pport * @return HttpURL * @throws Exception */ private HttpURL setRootHttpURL(final String puser, final String ppassword, final String phost, final int pport) throws Exception { rootUrl = null; HttpURL httpUrl = null; String path = "/"; String normalizedHost = normalizeRootHttpURL(phost, pport); if (connection2OptionsAlternate.auth_method.isURL()) { if (phost.toLowerCase().startsWith("https://")) { httpUrl = new HttpsURL(normalizedHost); } else { httpUrl = new HttpURL(normalizedHost); } String phostRootUrl = httpUrl.getScheme() + "://" + httpUrl.getAuthority() + "/"; if (httpUrl.getScheme().equalsIgnoreCase("https")) { rootUrl = new HttpsURL(phostRootUrl); if (pport > 0) { Protocol.registerProtocol("https", new Protocol("https", (ProtocolSocketFactory) new EasySSLProtocolSocketFactory(), pport)); } } else { rootUrl = new HttpURL(phostRootUrl); } } else { httpUrl = new HttpURL(phost, pport, path); rootUrl = new HttpURL(phost, pport, path); } httpUrl.setUserinfo(puser, ppassword); return httpUrl; }