// Goes online to get user authentication from Flickr. public void getAuthentication() { AuthInterface authInterface = flickr.getAuthInterface(); try { frob = authInterface.getFrob(); } catch (Exception e) { e.printStackTrace(); } try { URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob); // open the authentication URL in a browser open(authURL.toExternalForm()); } catch (Exception e) { e.printStackTrace(); } println("You have 15 seconds to approve the app!"); int startedWaiting = millis(); int waitDuration = 15 * 1000; // wait 10 seconds while ((millis() - startedWaiting) < waitDuration) { // just wait } println("Done waiting"); try { auth = authInterface.getToken(frob); println("Authentication success"); // This token can be used until the user revokes it. token = auth.getToken(); // save it for future use saveToken(token); } catch (Exception e) { e.printStackTrace(); } // complete authentication authenticateWithToken(token); }
/** * (Re)Compiles the given source. This method starts the compilation of a given source, if the * source has changed since the class was created. For this isSourceNewer is called. * * @param source the source pointer for the compilation * @param className the name of the class to be generated * @param oldClass a possible former class * @return the old class if the source wasn't new enough, the new class else * @throws CompilationFailedException if the compilation failed * @throws IOException if the source is not readable * @see #isSourceNewer(URL, Class) */ protected Class recompile(URL source, String className, Class oldClass) throws CompilationFailedException, IOException { if (source != null) { // found a source, compile it if newer if ((oldClass != null && isSourceNewer(source, oldClass)) || (oldClass == null)) { synchronized (sourceCache) { String name = source.toExternalForm(); sourceCache.remove(name); if (isFile(source)) { try { return parseClass( new GroovyCodeSource(new File(source.toURI()), config.getSourceEncoding())); } catch (URISyntaxException e) { // do nothing and fall back to the other version } } return parseClass(source.openStream(), name); } } } return oldClass; }
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputSource inputSource = null; if (options.entityResolver != null) { inputSource = options.entityResolver.resolveEntity(null, systemId); } if (inputSource == null) { inputSource = new InputSource(systemId); InputStream is = null; int redirects = 0; boolean redirect; URL url = JAXWSUtils.getFileOrURL(inputSource.getSystemId()); URLConnection conn = url.openConnection(); do { if (conn instanceof HttpsURLConnection) { if (options.disableSSLHostnameVerification) { ((HttpsURLConnection) conn).setHostnameVerifier(new HttpClientVerifier()); } } redirect = false; if (conn instanceof HttpURLConnection) { ((HttpURLConnection) conn).setInstanceFollowRedirects(false); } if (conn instanceof JarURLConnection) { if (conn.getUseCaches()) { doReset = true; conn.setDefaultUseCaches(false); c = conn; } } try { is = conn.getInputStream(); // is = sun.net.www.protocol.http.HttpURLConnection.openConnectionCheckRedirects(conn); } catch (IOException e) { if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = ((HttpURLConnection) conn); int code = httpConn.getResponseCode(); if (code == 401) { errorReceiver.error( new SAXParseException( WscompileMessages.WSIMPORT_AUTH_INFO_NEEDED( e.getMessage(), systemId, WsimportOptions.defaultAuthfile), null, e)); throw new AbortException(); } // FOR other code we will retry with MEX } throw e; } // handle 302 or 303, JDK does not seem to handle 302 very well. // Need to redesign this a bit as we need to throw better error message for IOException in // this case if (conn instanceof HttpURLConnection) { HttpURLConnection httpConn = ((HttpURLConnection) conn); int code = httpConn.getResponseCode(); if (code == 302 || code == 303) { // retry with the value in Location header List<String> seeOther = httpConn.getHeaderFields().get("Location"); if (seeOther != null && seeOther.size() > 0) { URL newurl = new URL(url, seeOther.get(0)); if (!newurl.equals(url)) { errorReceiver.info( new SAXParseException( WscompileMessages.WSIMPORT_HTTP_REDIRECT(code, seeOther.get(0)), null)); url = newurl; httpConn.disconnect(); if (redirects >= 5) { errorReceiver.error( new SAXParseException( WscompileMessages.WSIMPORT_MAX_REDIRECT_ATTEMPT(), null)); throw new AbortException(); } conn = url.openConnection(); inputSource.setSystemId(url.toExternalForm()); redirects++; redirect = true; } } } } } while (redirect); inputSource.setByteStream(is); } return inputSource; }