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)));
}
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();
}
}
}
}
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;
}
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);
}
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");
}
Aggregations