/** * Return the input stream to artifact. * * @return prepared input stream * * @throws IOException re-thrown * @see org.ops4j.net.URLUtils#prepareInputStream(java.net.URL,boolean) */ InputStream getInputStream() throws IOException { return URLUtils.prepareInputStream( m_artifactURL, !m_checkCertificate ); }
/** * Prepare url for authentication and ssl if necessary and returns the input stream from the url. * * @param url url to prepare * @param acceptAnyCertificate true if the certicate check should be skipped * * @return input stream from url * * @throws IOException re-thrown */ public static InputStream prepareInputStream( final URL url, final boolean acceptAnyCertificate ) throws IOException { final URLConnection conn = url.openConnection(); prepareForAuthentication( conn ); prepareHttpHeaders( conn ); if( acceptAnyCertificate ) { prepareForSSL( conn ); } return conn.getInputStream(); }
/** * @return Function that returns {@code true} when there's a response from the URL; otherwise {@code false} */ public static Callable<Boolean> responseFrom(final URL url) { return () -> { HttpURLConnection conn = null; try { conn = (HttpURLConnection) url.openConnection(); if (conn instanceof HttpsURLConnection) { // relax host and certificate checks as we just want to see if it's up ((HttpsURLConnection) conn).setHostnameVerifier((hostname, session) -> true); URLUtils.prepareForSSL(conn); } conn.setRequestMethod("HEAD"); conn.connect(); return true; } finally { if (conn != null) { conn.disconnect(); } } }; }
/** * Prepares an url connection for authentication if necessary. * * @param connection the connection to be prepared * * @return the prepared conection */ public static URLConnection prepareForAuthentication( final URLConnection connection ) { NullArgumentException.validateNotNull( connection, "url connection cannot be null" ); if( connection.getURL().getUserInfo() != null ) { // Need to decode username/password because it may contain encoded characters (http://www.w3schools.com/tags/ref_urlencode.asp) // A common encoding is to provide a username as an email address like user%40domain.org String decodedUserInfo = decode( connection.getURL().getUserInfo() ); String base64Encoded = Base64Encoder.encode( decodedUserInfo ); // sun bug 6459815: Long passwords cause Basic Auth to fail with a java.net.Authenticator base64Encoded = base64Encoded.replaceAll( "\n", "" ); connection.setRequestProperty( "Authorization", "Basic " + base64Encoded ); } return connection; }
/** * {@inheritDoc} */ @Override public InputStream getDefinition( final Configuration configuration ) throws IOException { return URLUtils.prepareInputStream( new URL( configuration.getProperty( "felix.snapshot.definition.url" ) ), true ); }
/** * {@inheritDoc} */ @Override public InputStream getDefinition( final Configuration configuration ) throws IOException { return URLUtils.prepareInputStream( new URL( configuration.getProperty( "equinox.snapshot.definition.url" ) ), true ); }
/** * {@inheritDoc} */ @Override public InputStream getDefinition( final Configuration configuration ) throws IOException { return URLUtils.prepareInputStream( new URL( configuration.getProperty( "knopflerfish.snapshot.definition.url" ) ), true ); }
/** * {@inheritDoc} */ @Override public InputStream getDefinition( final Configuration configuration ) throws IOException { return URLUtils.prepareInputStream( new URL( configuration.getProperty( "concierge.snapshot.definition.url" ) ), true ); }
try is = URLUtils.prepareInputStream( bndFileURL, true ); m_wrappingProperties.load( is );
/** * @param repositoryURL url to reporsitory * @param path a path to the artifact jar file * * @return prepared input stream * * @throws IOException re-thrown * @see org.ops4j.net.URLUtils#prepareInputStream(java.net.URL,boolean) */ private InputStream prepareInputStream( URL repositoryURL, final String path ) throws IOException { String repository = repositoryURL.toExternalForm(); if( !repository.endsWith( Parser.FILE_SEPARATOR ) ) { repository = repository + Parser.FILE_SEPARATOR; } m_configuration.enableProxy( repositoryURL ); final URL url = new URL( repository + path ); LOG.trace( "Reading " + url.toExternalForm() ); return URLUtils.prepareInputStream( url, !m_configuration.getCertificateCheck() ); }
/** * Url must be a reference to an instructions file. * * @see AbstractConnection#getInstructions() */ protected Properties getInstructions() throws IOException { final Properties instructions = new Properties(); final URL instructionsFleUrl = getInstructionsFileURL(); instructions.load( URLUtils.prepareInputStream( instructionsFleUrl, !getConfiguration().getCertificateCheck() ) ); //the following line is for debugging purposes //instructions.store( System.out, null ); return instructions; }
/** * Returns the {@link Jar} if exists and is valid or creates on from scratch. * @return the {@link Jar} that corresponds to the object properties. * @throws Exception */ private Jar getOrCreateJar() throws Exception { if (this.jar != null && jar.getResources() != null) { return jar; } else { return BndUtils.createJar( URLUtils.prepareInputStream(new URL(fabUri), configuration.getCertificateCheck()), instructions, fabUri, OverwriteMode.MERGE, embeddedResources, classPathResolver.getExtraImportPackages(), actualImports, this); } }
/** * Returns the {@link Jar} if exists and is valid or creates on from scratch. * @return the {@link Jar} that corresponds to the object properties. * @throws Exception */ private Jar getOrCreateJar() throws Exception { if (this.jar != null && jar.getResources() != null) { return jar; } else { return BndUtils.createJar( URLUtils.prepareInputStream(new URL(fabUri), configuration.getCertificateCheck()), instructions, fabUri, OverwriteMode.MERGE, embeddedResources, classPathResolver.getExtraImportPackages(), actualImports, this); } }
URLUtils.prepareInputStream(new URL(warUri), !m_configuration.getCertificateCheck()), instructions, warUri );
/** * Returns an input stream for the bundle created from the jar. * * @return the input stream for the bundle created from the jar * * @throws IOException re-thrown from BndLib.createBundle * @see BndUtils#createBundle(InputStream, Properties, String) */ @Override public InputStream getInputStream() throws IOException { connect(); return BndUtils.createBundle( URLUtils.prepareInputStream( m_parser.getWrappedJarURL(), !m_configuration.getCertificateCheck() ), m_parser.getWrappingProperties(), url.toExternalForm(), m_parser.getOverwriteMode() ); }