List of usage examples for org.apache.commons.httpclient URIException printStackTrace
public void printStackTrace()
From source file:org.archive.wayback.util.htmllex.ParseContext.java
/** * @param baseURL an base URL for relative URLs *///from w w w . j a v a2 s. com public void setBaseUrl(String baseURL) { try { baseUrl = UsableURIFactory.getInstance(baseURL); } catch (URIException ex) { // XXX ex.printStackTrace(); } }
From source file:org.archive.wayback.util.url.AggressiveUrlCanonicalizerTest.java
License:asdf
private void checkCanonicalization(String orig, String want) { String got;/*from ww w .ja v a 2 s. co m*/ try { got = canonicalizer.urlStringToKey(orig); assertEquals( "Failed canonicalization (" + orig + ") => (" + got + ") and not (" + want + ") as expected", want, got); String got2 = canonicalizer.urlStringToKey(got); assertEquals("Failed 2nd canonicalization (" + got + ") => (" + got2 + ") and not (" + want + ") as expected", want, got2); } catch (URIException e) { e.printStackTrace(); assertTrue("Exception converting(" + orig + ")", false); } }
From source file:org.eclipsetrader.yahoo.internal.core.Util.java
/** * Builds the http method for historycal prices download. * * @return the method./*from w w w.j a v a2 s . co m*/ */ public static HttpMethod getHistoryFeedMethod(IFeedIdentifier identifier, Date from, Date to) throws URIException { String symbol = getSymbol(identifier); Calendar fromDate = Calendar.getInstance(); fromDate.setTime(from); Calendar toDate = Calendar.getInstance(); toDate.setTime(to); String prefix = "/instrument/1.0/"; String suffix = "/chartdata;type=quote"; URI uri = new URI("http", "chartapi.finance.yahoo.com", prefix + symbol.toLowerCase() + suffix, ""); GetMethod method = new GetMethod(); method.setURI(uri); method.setQueryString(new NameValuePair[] { new NameValuePair("s", symbol), new NameValuePair("d", String.valueOf(toDate.get(Calendar.MONTH))), new NameValuePair("e", String.valueOf(toDate.get(Calendar.DAY_OF_MONTH))), new NameValuePair("f", String.valueOf(toDate.get(Calendar.YEAR))), new NameValuePair("g", "d"), new NameValuePair("a", String.valueOf(fromDate.get(Calendar.MONTH))), new NameValuePair("b", String.valueOf(fromDate.get(Calendar.DAY_OF_MONTH))), new NameValuePair("c", String.valueOf(fromDate.get(Calendar.YEAR))), new NameValuePair("ignore", ".csv"), }); method.setFollowRedirects(true); try { System.out.println(method.getURI().toString()); } catch (URIException e) { e.printStackTrace(); } return method; }
From source file:org.eclipsetrader.yahoojapan.internal.core.Util.java
/** * Builds the http method for historycal prices download. * * @return the method.// w ww. j av a 2 s .c om */ public static HttpMethod getHistoryFeedMethod(IFeedIdentifier identifier, Date from, Date to) throws URIException { String symbol = getSymbol(identifier); Calendar fromDate = Calendar.getInstance(); fromDate.setTime(from); Calendar toDate = Calendar.getInstance(); toDate.setTime(to); String prefix = "/history/"; String suffix = ""; URI uri = new URI("http", "info.finance.yahoo.co.jp", prefix + suffix, ""); GetMethod method = new GetMethod(); method.setURI(uri); method.setQueryString(new NameValuePair[] { new NameValuePair("code", symbol), new NameValuePair("sy", String.valueOf(fromDate.get(Calendar.YEAR))), new NameValuePair("sm", String.valueOf(fromDate.get(Calendar.MONTH) + 1)), new NameValuePair("sd", String.valueOf(fromDate.get(Calendar.DAY_OF_MONTH))), new NameValuePair("ey", String.valueOf(toDate.get(Calendar.YEAR))), new NameValuePair("em", String.valueOf(toDate.get(Calendar.MONTH) + 1)), new NameValuePair("ed", String.valueOf(toDate.get(Calendar.DAY_OF_MONTH))), new NameValuePair("tm", "d"), // new NameValuePair("p", "1"), }); method.setFollowRedirects(true); try { System.out.println(method.getURI().toString()); } catch (URIException e) { e.printStackTrace(); } return method; }
From source file:org.glite.slcs.shibclient.ShibbolethClient.java
/** * Authenticates the user on his IdP for the given SP. * /*from w w w.j av a2s .c o m*/ * @param spEntryURL * The Service Provider entry point URL * @return <code>true</code> iff the user have been authenticated by his * Identity Provider. * @throws AuthException * @throws RemoteException * @throws ServiceException * @throws UnknownResourceException */ public boolean authenticate(String spEntryURL) throws AuthException, RemoteException, ServiceException, UnknownResourceException { String idpProviderID = credentials_.getIdentityProviderID(); IdentityProvider idp = metadata_.getIdentityProvider(idpProviderID); if (idp == null) { throw new UnknownResourceException("IdP " + idpProviderID + " not found in Metadata"); } LOG.info(spEntryURL + " IdP=" + idp.getUrl() + " AuthType=" + idp.getAuthTypeName()); try { URI idpSSOResponseURI = null; // 1. get the first redirection, or the SAML2 DS response, or the // same // (already authN) URI spLoginResponseURI = processSPEntry(spEntryURL, idp); // either wayf or idp or same (already authenticated) String spLoginResponseURL = spLoginResponseURI.getEscapedURI(); LOG.debug("spLoginResponseURL=" + spLoginResponseURL); // check if already authenticated (multiple call to authenticate) if (spLoginResponseURL.startsWith(spEntryURL)) { LOG.info("Already authenticated? " + isAuthenticated_ + ": " + spLoginResponseURL); return this.isAuthenticated_; } // 2. process the IdP SSO login idpSSOResponseURI = processIdPSSO(idp, spLoginResponseURI); // 3. process the IdP SSO response -> Artifact or Browser/POST // profile URI idpResponseURI = processIdPSSOResponse(idp, idpSSOResponseURI); String url = idpResponseURI.getURI(); if (url.equals(spEntryURL)) { this.isAuthenticated_ = true; LOG.info("Sucessful authentication"); } } catch (URIException e) { LOG.error("URIException: " + e); e.printStackTrace(); } catch (HttpException e) { LOG.error("HttpException: " + e); e.printStackTrace(); } catch (IOException e) { LOG.error("IOException: " + e); e.printStackTrace(); throw new RemoteException(e); } return this.isAuthenticated_; }
From source file:org.glite.slcs.shibclient.ShibbolethClient.java
/** * Processes the IdP response as a Browser/POST * /*from w w w .j a v a 2s. c om*/ * @param idp * The {@link IdentityProvider}. * @param idpSSOResponseURI * The IdP SSO reponse {@link URI}. * @return the SP URI to go to * @throws RemoteException */ private URI processIdPBrowserPOST(IdentityProvider idp, URI idpSSOResponseURI, InputStream htmlStream) throws RemoteException { // return value URI browserPostResponseURI = null; RemoteException remoteException = null; try { Source source = new Source(htmlStream); List<Element> forms = source.findAllElements(Tag.FORM); if (!forms.isEmpty()) { // check if form contains a valid SAML Browser/POST for (Element form : forms) { String spSAMLURL = form.getAttributeValue("ACTION"); LOG.debug("SAML Browser/POST URL=" + spSAMLURL); if (spSAMLURL == null) { // no SAML post URL found String htmlBody = inputStreamToString(htmlStream); LOG.error("No SAML Browser/POST FORM ACTION found: " + idpSSOResponseURI + ": " + htmlBody); remoteException = new RemoteException("No SAML Browser/POST FORM ACTION found: " + idpSSOResponseURI + ". Please see the log file."); break; // exit loop } // create POST method PostMethod postSPSAMLMethod = new PostMethod(spSAMLURL); // add all HIDDEN fields to POST List<FormControl> formControls = form.findFormControls(); for (FormControl control : formControls) { FormControlType type = control.getFormControlType(); if (type.equals(FormControlType.HIDDEN)) { String name = control.getName(); Collection<CharSequence> values = control.getValues(); for (CharSequence value : values) { LOG.debug("HIDDEN " + name + "=" + value); // add all hidden fields postSPSAMLMethod.addParameter(name, (String) value); } } } // execute the SAML post LOG.info("POST SPSAMLMethod: " + postSPSAMLMethod.getURI()); int spSAMLResponseStatus = executeMethod(postSPSAMLMethod); LOG.debug(postSPSAMLMethod.getStatusLine()); // status must be 302 and redirect Location Header location = postSPSAMLMethod.getResponseHeader("Location"); if (spSAMLResponseStatus == 302 && location != null) { String url = location.getValue(); browserPostResponseURI = new URI(url, false); LOG.debug("Redirect: " + browserPostResponseURI); } else { LOG.error( "Unexpected SP response: Status=" + spSAMLResponseStatus + " Location=" + location); remoteException = new RemoteException( "Unexpected SP response: Status=" + spSAMLResponseStatus + " Location=" + location); } LOG.trace("postSPSAMLMethod.releaseConnection()"); postSPSAMLMethod.releaseConnection(); } // forms loop } else { // no SAML post found String htmlBody = inputStreamToString(htmlStream); LOG.error("No SAML Browser/POST profile found: " + idpSSOResponseURI + ": " + htmlBody); remoteException = new RemoteException( "No SAML Browser/POST profile found: " + idpSSOResponseURI + ". Please see the log file."); } } catch (URIException e) { e.printStackTrace(); remoteException = new RemoteException(e.getMessage(), e); } catch (IOException e) { e.printStackTrace(); remoteException = new RemoteException(e.getMessage(), e); } if (browserPostResponseURI == null) { if (remoteException != null) { throw remoteException; } } return browserPostResponseURI; }
From source file:org.kalypso.ui.addlayer.internal.util.AddLayerUtils.java
public static String makeRelativeOrProjectRelative(final IPath mapPath, final IPath path) { if (path == null) return null; if (mapPath == null) return path.toPortableString(); final IPath mapFolderPath = mapPath.removeLastSegments(1); final IPath relativeStylePath = path.makeRelativeTo(mapFolderPath); /* No '..': path is nicely relative to map */ if (!"..".equals(relativeStylePath.segment(0))) //$NON-NLS-1$ return relativeStylePath.toPortableString(); /* map and path are in same project, use project: style notation */ final IPath projectPath = mapPath.uptoSegment(1); if (projectPath.isPrefixOf(path)) return UrlResolver.createProjectPath(path); try {/*from w ww . ja va 2s.com*/ /* No in same project: make platform path */ return ResourceUtilities.createURLSpec(path); } catch (final URIException e) { e.printStackTrace(); return null; } }
From source file:org.kalypso.ui.wizards.results.editor.EditStyleDialog.java
private Symbolizer[] parseStyle() { InputStream inputStream = null; try {//www . j av a 2 s . c om inputStream = m_sldFile.getContents(); final IUrlResolver2 resolver = new IUrlResolver2() { @Override @SuppressWarnings("synthetic-access") public URL resolveURL(final String relativeOrAbsolute) throws MalformedURLException { try { final URL sldURL = ResourceUtilities.createURL(m_sldFile); return new URL(sldURL, relativeOrAbsolute); } catch (final URIException e) { e.printStackTrace(); throw new MalformedURLException(e.getLocalizedMessage()); } } }; m_sld = SLDFactory.createSLD(resolver, inputStream); final NamedLayer[] namedLayers = m_sld.getNamedLayers(); // get always just the first layer final NamedLayer namedLayer = namedLayers[0]; // get always the first style (we assume there is only one) final Style[] styles = namedLayer.getStyles(); final Style style = styles[0]; if (style instanceof UserStyle) { final UserStyle userStyle = (UserStyle) style; final FeatureTypeStyle[] featureTypeStyles = userStyle.getFeatureTypeStyles(); // we assume, that there is only one feature type style and take the first we can get. final FeatureTypeStyle featureTypeStyle = featureTypeStyles[0]; // we assume, that there is only one rule and take the first we can get. m_rules = featureTypeStyle.getRules(); final List<Symbolizer> symbList = new ArrayList<>(); for (final Rule rule : m_rules) { final Symbolizer[] symbolizers = rule.getSymbolizers(); // and the first and only symbolizer is taken final Symbolizer symb = symbolizers[0]; symbList.add(symb); } return symbList.toArray(new Symbolizer[symbList.size()]); } } catch (final CoreException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final XMLParsingException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { IOUtils.closeQuietly(inputStream); } return null; }
From source file:org.lobid.lodmill.PipeLobidOrganisationEnrichment.java
private void startOsmLookupEnrichment() { // activate the geo position bnode enterBnode(this.bnodeIDGeoPos); for (int i = 0; i < 2; i++) { osmUrl[i] = null;//ww w. ja va2 s .com urlOsmLookupSearchParameters[1] = null; } final String firstLiteralOfProperty = getFirstLiteralOfProperty(VcardNs.LOCALITY.uri); if (firstLiteralOfProperty != null) { // OSM Api doesn't like e.g /Marburg%2FLahn/ but accepts /Marburg/. // Having also the postcode we will not encounter ambigous cities try { this.locality = URIUtil.encodeQuery( (URIUtil.decode(firstLiteralOfProperty, "UTF-8").replaceAll("(.*)\\p{Punct}.*", "$1")), "UTF-8"); } catch (URIException e1) { this.locality = firstLiteralOfProperty; e1.printStackTrace(); } } this.postalcode = getFirstLiteralOfProperty(VcardNs.POSTAL_CODE.uri); this.street = getFirstLiteralOfProperty(VcardNs.STREET_ADDRESS.uri); if (!doubles()) { this.countryName = getFirstLiteralOfProperty(VcardNs.COUNTRY_NAME.uri); if (makeOsmApiSearchParameters()) { lookupLocation(); // TODO check whats happening if geo data already in // source file } } if (this.lat != null && this.lon != null) { super.literal(GEO_WGS84_POS_LAT, String.valueOf(this.lat)); super.literal(GEO_WGS84_POS_LONG, String.valueOf(this.lon)); super.literal(RDF_SYNTAX_NS_TYPE, WGS84_POS_SPATIALTHING); } }
From source file:org.lobid.lodmill.PipeLobidOrganisationEnrichment.java
private void sanitizeStreetnameAndRetrieveOsmApiResultAndStoreLatLon(String regex) throws Exception { String tmp = ""; try {//from www . j a v a2 s . c o m tmp = URIUtil.encodeQuery((URIUtil.decode(this.street, "UTF-8").replaceAll(regex, "$1")), "UTF-8"); } catch (URIException e2) { e2.printStackTrace(); } // make new request only if strings differ if (!tmp.equals(this.street)) { this.street = tmp; try { if (makeOsmApiSearchParameters()) { if (!makeUrlAndLookupIfCached()) { this.osmApiLookupResult = getUrlContent(this.osmUrl[1]); parseJsonAndStoreLatLon(); } } } catch (IOException e1) { LOG.error(super.subject + " " + e1.getLocalizedMessage()); } } }