/** * @param target something like {@code http://jenkins/cli?remoting=true} * which we then need to split into {@code http://jenkins/} + {@code cli?remoting=true} * in order to construct a crumb issuer request * @deprecated use {@link #FullDuplexHttpStream(URL, String, String)} instead */ @Deprecated public FullDuplexHttpStream(URL target, String authorization) throws IOException { this(new URL(target.toString().replaceFirst("/cli.*$", "/")), target.toString().replaceFirst("^.+/(cli.*)$", "$1"), authorization); }
paths.put( canonicalize( path ), pathValue( paths, pathKeys[i], path ) ); paths.put( url.toString(), pathValue( paths, "loader." + level, url.getPath() ) ); paths.put( loader.toString(), "<ClassLoader unexpectedly has null URL array>" ); for ( Map.Entry<String, String> path : paths.entrySet() ) result.add( " [" + path.getValue() + "] " + path.getKey() );
protected static void initProcessEngineFromSpringResource(URL resource) { try { Class<?> springConfigurationHelperClass = ReflectUtil.loadClass("org.activiti.spring.SpringConfigurationHelper"); Method method = springConfigurationHelperClass.getDeclaredMethod("buildProcessEngine", new Class<?>[] { URL.class }); ProcessEngine processEngine = (ProcessEngine) method.invoke(null, new Object[] { resource }); String processEngineName = processEngine.getName(); ProcessEngineInfo processEngineInfo = new ProcessEngineInfoImpl(processEngineName, resource.toString(), null); processEngineInfosByName.put(processEngineName, processEngineInfo); processEngineInfosByResourceUrl.put(resource.toString(), processEngineInfo); } catch (Exception e) { throw new ActivitiException("couldn't initialize process engine from spring configuration resource " + resource.toString() + ": " + e.getMessage(), e); } }
JarClassPath(String pathname) throws NotFoundException { JarFile jarfile = null; try { jarfile = new JarFile(pathname); jarfileEntries = new ArrayList<String>(); for (JarEntry je:Collections.list(jarfile.entries())) if (je.getName().endsWith(".class")) jarfileEntries.add(je.getName()); jarfileURL = new File(pathname).getCanonicalFile() .toURI().toURL().toString(); return; } catch (IOException e) {} finally { if (null != jarfile) try { jarfile.close(); } catch (IOException e) {} } throw new NotFoundException(pathname); }
@SuppressWarnings("unchecked") List<List<ConnectionInformations>> collectConnectionInformations() throws IOException { // récupération à la demande des connections final List<List<ConnectionInformations>> connectionInformations = new ArrayList<List<ConnectionInformations>>(); final URL connectionsUrl = new URL( url.toString() + '&' + HttpParameter.PART + '=' + HttpPart.CONNECTIONS); final Object result = collectForUrl(connectionsUrl); if (result instanceof List && !((List<?>) result).isEmpty() && ((List<?>) result).get(0) instanceof List) { // pour le serveur de collecte final List<List<ConnectionInformations>> connections = (List<List<ConnectionInformations>>) result; connectionInformations.addAll(connections); } else { final List<ConnectionInformations> connections = (List<ConnectionInformations>) result; connectionInformations.add(connections); } return connectionInformations; }
private static void downloadLicense(URL licenseURL) { assert remote2local != null; File downloadDir = new File(System.getProperty("mary.downloadDir", ".")); String filename = licenseURL.toString().replace('/', '_').replace(':', '_'); File licenseFile = new File(downloadDir, filename); System.out.println("Downloading license from " + licenseURL.toString()); try (FileOutputStream out = new FileOutputStream(licenseFile); InputStream in = licenseURL.openStream()) { IOUtils.copy(in, out); } catch (IOException e) { System.err.println("Cannot download license from " + licenseURL.toString()); e.printStackTrace(); } // Now we need to update remote2local and write an updated license-index.txt: remote2local.put(licenseURL, filename); saveIndex(); }
public String collectDataIncludingCurrentRequests() throws IOException { final List<URL> urlsWithCurrentRequests = new ArrayList<URL>(); for (final URL url : urls) { urlsWithCurrentRequests .add(new URL(url.toString() + "&part=defaultWithCurrentRequests")); } return collectDataWithUrls(urlsWithCurrentRequests); }
} catch (java.net.URISyntaxException e) { try { url = new URL(url.toString().replace(" ", "%20")); this.uri = url.toURI(); } catch (Throwable e2) { jarConn = (JarURLConnection) new URL(uriJarPrefix(this.uri, "!/")).openConnection(); jf = jarConn.getJarFile(); Enumeration<JarEntry> ens = jf.entries(); while (ens.hasMoreElements()) { JarEntry en = ens.nextElement(); names.add(en.getName());
@Test public void filterDoesNotChangeRequestUriIfHeaderIsInvalid() throws Exception { RequestHeaderToRequestUriGatewayFilterFactory factory = new RequestHeaderToRequestUriGatewayFilterFactory(); GatewayFilter filter = factory.apply(c -> c.setName("X-CF-Forwarded-Url")); MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost") .header("X-CF-Forwarded-Url", "example").build(); ServerWebExchange exchange = MockServerWebExchange.from(request); exchange.getAttributes().put(GATEWAY_REQUEST_URL_ATTR, URI.create("http://localhost")); GatewayFilterChain filterChain = mock(GatewayFilterChain.class); ArgumentCaptor<ServerWebExchange> captor = ArgumentCaptor .forClass(ServerWebExchange.class); when(filterChain.filter(captor.capture())).thenReturn(Mono.empty()); filter.filter(exchange, filterChain); ServerWebExchange webExchange = captor.getValue(); URI uri = (URI) webExchange.getAttributes().get(GATEWAY_REQUEST_URL_ATTR); assertThat(uri).isNotNull(); assertThat(uri.toURL().toString()).isEqualTo("http://localhost"); } }
String collectSqlRequestExplainPlan(String sqlRequest) throws IOException { final URL explainPlanUrl = new URL( url.toString() + '&' + HttpParameter.PART + '=' + HttpPart.EXPLAIN_PLAN); final Map<String, String> headers = new HashMap<String, String>(); headers.put(HttpParameter.REQUEST.getName(), sqlRequest); if (cookies != null) { headers.put("Cookie", cookies); } final LabradorRetriever labradorRetriever = new LabradorRetriever(explainPlanUrl, headers); return labradorRetriever.call(); }
@Test public void shouldProvideTheNamespaceUriAndTheLocation() throws MalformedURLException { ConfigElementImplementationRegistry registry = new ConfigElementImplementationRegistry(pluginExtns); URL resource = new File("file:///tmp/foo").toURI().toURL(); URL resource1 = new File("file:///tmp/bar").toURI().toURL(); registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "uri-1", PluginNamespace.XSD_NAMESPACE_URI, "uri1")), resource); registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "uri-2", PluginNamespace.XSD_NAMESPACE_URI, "uri2")), resource); registry.xsdFor(PluginTestUtil.bundleCtxWithHeaders(m(PluginNamespace.XSD_NAMESPACE_PREFIX, "uri-3", PluginNamespace.XSD_NAMESPACE_URI, "uri3")), resource1); assertThat(registry.xsds(), containsString(String.format("uri1 %s", resource.toString()))); assertThat(registry.xsds(), containsString(String.format("uri2 %s", resource.toString()))); assertThat(registry.xsds(), containsString(String.format("uri3 %s", resource1.toString()))); }
private static String getUnmigrationCommandLine(File jenkinsHome) { StringBuilder cp = new StringBuilder(); for (Class<?> c : new Class<?>[] {RunIdMigrator.class, /* TODO how to calculate transitive dependencies automatically? */Charsets.class, WriterOutputStream.class, BuildException.class, FastDateFormat.class}) { URL location = c.getProtectionDomain().getCodeSource().getLocation(); String locationS = location.toString(); if (location.getProtocol().equals("file")) { try { locationS = new File(location.toURI()).getAbsolutePath(); } catch (URISyntaxException x) { // never mind } } if (cp.length() > 0) { cp.append(File.pathSeparator); } cp.append(locationS); } return String.format("java -classpath \"%s\" %s \"%s\"", cp, RunIdMigrator.class.getName(), jenkinsHome); }
@org.junit.Test public void testSignedSAML() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = ActionTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); QName portQName = new QName(NAMESPACE, "DoubleItSignedSAMLPort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(port, PORT); assertEquals(50, port.doubleIt(25)); ((java.io.Closeable)port).close(); bus.shutdown(true); }
/** * @param igniteUrl Url to ignite. * @return Ignite file name. */ private String downloadIgnite(String igniteUrl) { try { URL url = new URL(igniteUrl); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); int code = conn.getResponseCode(); if (code == 200) { String fileName = fileName(url.toString()); String filePath = props.igniteLocalWorkDir() + File.separator + fileName; if (new File(filePath).exists()) return fileName; FileOutputStream outFile = new FileOutputStream(filePath); outFile.getChannel().transferFrom(Channels.newChannel(conn.getInputStream()), 0, Long.MAX_VALUE); outFile.close(); return fileName; } else throw new RuntimeException("Got unexpected response code. Response code: " + code); } catch (IOException e) { throw new RuntimeException("Failed update ignite.", e); } }
if (!base.toString().endsWith("/")) { throw new IllegalArgumentException(base.toString()); this.authorization = authorization; URL target = new URL(this.base, relativeTarget); HttpURLConnection con = (HttpURLConnection) target.openConnection(); con.setDoOutput(true); // request POST to avoid caching con.setRequestMethod("POST"); con = (HttpURLConnection) target.openConnection(); con.setDoOutput(true); // request POST con.setRequestMethod("POST");
@Test public void testPersistenceUnitRootUrl() throws Exception { URL url = PersistenceUnitReader.determinePersistenceUnitRootUrl(new ClassPathResource("/org/springframework/orm/jpa/persistence-no-schema.xml")); assertNull(url); url = PersistenceUnitReader.determinePersistenceUnitRootUrl(new ClassPathResource("/org/springframework/orm/jpa/META-INF/persistence.xml")); assertTrue("the containing folder should have been returned", url.toString().endsWith("/org/springframework/orm/jpa")); }
@Test public void testExternalProgram() throws Exception { TestEnvironment.setAsContext( MINI_CLUSTER, PARALLELISM, Collections.singleton(new Path(JAR_FILE)), Collections.emptyList()); String testData = getClass().getResource(TEST_DATA_FILE).toString(); PackagedProgram program = new PackagedProgram(new File(JAR_FILE), new String[]{testData}); program.invokeInteractiveModeForExecution(); } }