Search in sources :

Example 61 with URL

use of java.net.URL in project cas by apereo.

the class KryoTranscoderTests method internalProxyTest.

private void internalProxyTest(final String proxyUrl) throws MalformedURLException {
    final Credential proxyCredential = new HttpBasedServiceCredential(new URL(proxyUrl), RegisteredServiceTestUtils.getRegisteredService("https://.+"));
    final TicketGrantingTicket expectedTGT = new MockTicketGrantingTicket(USERNAME);
    expectedTGT.grantServiceTicket(ST_ID, null, null, false, true);
    assertEquals(expectedTGT, transcoder.decode(transcoder.encode(expectedTGT)));
}
Also used : MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) Credential(org.apereo.cas.authentication.Credential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) HttpBasedServiceCredential(org.apereo.cas.authentication.HttpBasedServiceCredential) TicketGrantingTicket(org.apereo.cas.ticket.TicketGrantingTicket) MockTicketGrantingTicket(org.apereo.cas.mock.MockTicketGrantingTicket) URL(java.net.URL)

Example 62 with URL

use of java.net.URL in project jvm-tools by aragozin.

the class JarBuilderTool method addFiles.

//    private static byte[] jarFiles(String path) throws IOException {
//        ByteArrayOutputStream bos = new ByteArrayOutputStream();
//        JarOutputStream jarOut = new JarOutputStream(bos);
//        int size = addFiles(jarOut, "", new File(path));
//        if (size == 0) {
//            // no files in folder
//            return null;
//        }
//        jarOut.close();
//        return bos.toByteArray();
//    }
//
//    private static int addFiles(JarOutputStream jarOut, String base, File path) throws IOException {
//        int count = 0;
//        for(File file : path.listFiles()) {
//            if (file.isDirectory()) {
//                final String dirName = base + file.getName() + "/";
//
//                JarEntry entry = new JarEntry(dirName);
//                entry.setTime(0l);// this to ensure equal hash for equal content
//                jarOut.putNextEntry(entry);
//                jarOut.closeEntry();
//                count += addFiles(jarOut, dirName, file);
//            }
//            else {
//                JarEntry entry = new JarEntry(base + file.getName());
//                entry.setTime(file.lastModified());
//                jarOut.putNextEntry(entry);
//                copyStream(new FileInputStream(file), jarOut);
//                jarOut.closeEntry();
//                ++count; 
//            }
//        }
//        return count;
//    }
private void addFiles(ZipOutputStream jarOut, String basePackage, String baseUrl) throws IOException, MalformedURLException {
    if (baseUrl.startsWith("jar:")) {
        int n = baseUrl.lastIndexOf("!");
        if (n < 0) {
            throw new IllegalArgumentException("Unexpected classpath URL: " + baseUrl);
        }
        String fileUrl = baseUrl.substring(4, n);
        InputStream is = new URL(fileUrl).openStream();
        ZipInputStream zis = new ZipInputStream(is);
        while (true) {
            ZipEntry ze = zis.getNextEntry();
            if (ze != null) {
                if (matchPath(ze.getName(), basePackage)) {
                    ZipEntry entry = new ZipEntry(ze.getName());
                    // this is to facilitate content cache
                    entry.setTime(0);
                    if (!pathEntries.contains(entry.getName())) {
                        pathEntries.add(entry.getName());
                        jarOut.putNextEntry(entry);
                        copyStreamNoClose(zis, jarOut);
                        jarOut.closeEntry();
                    }
                }
                zis.closeEntry();
            } else {
                break;
            }
        }
    } else {
        InputStream is = new URL(baseUrl).openStream();
        for (String line : toLines(is)) {
            String fpath = baseUrl + "/" + line;
            String jpath = basePackage + "/" + line;
            ZipEntry entry = new ZipEntry(jpath);
            // this is to facilitate content cache            
            entry.setTime(0);
            if (!pathEntries.contains(entry.getName())) {
                jarOut.closeEntry();
                jarOut.putNextEntry(entry);
                copyStream(new URL(fpath).openStream(), jarOut);
                jarOut.closeEntry();
            }
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) URL(java.net.URL)

Example 63 with URL

use of java.net.URL in project bazel by bazelbuild.

the class DefaultModelResolver method getModelSource.

// TODO(kchodorow): make this work with local repositories.
private UrlModelSource getModelSource(String url, String groupId, String artifactId, String version) throws UnresolvableModelException {
    try {
        if (!url.endsWith("/")) {
            url += "/";
        }
        URL urlUrl = new URL(url + groupId.replaceAll("\\.", "/") + "/" + artifactId + "/" + version + "/" + artifactId + "-" + version + ".pom");
        if (pomFileExists(urlUrl)) {
            UrlModelSource urlModelSource = new UrlModelSource(urlUrl);
            ruleNameToModelSource.put(Rule.name(groupId, artifactId), urlModelSource);
            return urlModelSource;
        }
    } catch (MalformedURLException e) {
        throw new UnresolvableModelException("Bad URL " + url + ": " + e.getMessage(), groupId, artifactId, version, e);
    }
    return null;
}
Also used : MalformedURLException(java.net.MalformedURLException) UnresolvableModelException(org.apache.maven.model.resolution.UnresolvableModelException) UrlModelSource(org.apache.maven.model.building.UrlModelSource) URL(java.net.URL)

Example 64 with URL

use of java.net.URL in project bazel by bazelbuild.

the class HttpConnectorMultiplexerTest method threadIsInterrupted_throwsIeProntoAndDoesNothingElse.

@Test
public void threadIsInterrupted_throwsIeProntoAndDoesNothingElse() throws Exception {
    final AtomicBoolean wasInterrupted = new AtomicBoolean(true);
    Thread task = new Thread(new Runnable() {

        @Override
        public void run() {
            Thread.currentThread().interrupt();
            try {
                multiplexer.connect(asList(new URL("http://lol.example")), "");
            } catch (InterruptedIOException ignored) {
                return;
            } catch (Exception ignored) {
            // ignored
            }
            wasInterrupted.set(false);
        }
    });
    task.start();
    task.join();
    assertThat(wasInterrupted.get()).isTrue();
    verifyZeroInteractions(connector);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InterruptedIOException(java.io.InterruptedIOException) URL(java.net.URL) InterruptedIOException(java.io.InterruptedIOException) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) Test(org.junit.Test)

Example 65 with URL

use of java.net.URL in project bazel by bazelbuild.

the class HttpConnectorTest method redirectToDifferentPath_works.

@Test
public void redirectToDifferentPath_works() throws Exception {
    final Map<String, String> headers1 = new ConcurrentHashMap<>();
    final Map<String, String> headers2 = new ConcurrentHashMap<>();
    try (ServerSocket server = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"))) {
        @SuppressWarnings("unused") Future<?> possiblyIgnoredError = executor.submit(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                try (Socket socket = server.accept()) {
                    readHttpRequest(socket.getInputStream(), headers1);
                    sendLines(socket, "HTTP/1.1 301 Redirect", "Date: Fri, 31 Dec 1999 23:59:59 GMT", "Connection: close", "Location: /doodle.tar.gz", "Content-Length: 0", "", "");
                }
                try (Socket socket = server.accept()) {
                    readHttpRequest(socket.getInputStream(), headers2);
                    sendLines(socket, "HTTP/1.1 200 OK", "Date: Fri, 31 Dec 1999 23:59:59 GMT", "Connection: close", "Content-Type: text/plain", "Content-Length: 0", "", "");
                }
                return null;
            }
        });
        URLConnection connection = connector.connect(new URL(String.format("http://127.0.0.1:%d", server.getLocalPort())), ImmutableMap.<String, String>of());
        assertThat(connection.getURL()).isEqualTo(new URL(String.format("http://127.0.0.1:%d/doodle.tar.gz", server.getLocalPort())));
        try (InputStream input = connection.getInputStream()) {
            assertThat(ByteStreams.toByteArray(input)).isEmpty();
        }
    }
    assertThat(headers1).containsEntry("x-request-uri", "/");
    assertThat(headers2).containsEntry("x-request-uri", "/doodle.tar.gz");
}
Also used : InputStream(java.io.InputStream) ServerSocket(java.net.ServerSocket) ExpectedException(org.junit.rules.ExpectedException) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Test(org.junit.Test)

Aggregations

URL (java.net.URL)10796 IOException (java.io.IOException)2404 Test (org.junit.Test)2220 File (java.io.File)1991 MalformedURLException (java.net.MalformedURLException)1425 InputStream (java.io.InputStream)1263 HttpURLConnection (java.net.HttpURLConnection)1166 ArrayList (java.util.ArrayList)841 Bus (org.apache.cxf.Bus)748 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)722 URLConnection (java.net.URLConnection)653 QName (javax.xml.namespace.QName)633 InputStreamReader (java.io.InputStreamReader)605 Service (javax.xml.ws.Service)549 HashMap (java.util.HashMap)533 URLClassLoader (java.net.URLClassLoader)526 BufferedReader (java.io.BufferedReader)518 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)361 URISyntaxException (java.net.URISyntaxException)348 URI (java.net.URI)331