List of usage examples for org.apache.http.client.utils URIBuilder setUserInfo
public URIBuilder setUserInfo(final String username, final String password)
From source file:integration.IntegrationTestsConfig.java
public static URI getGlServerURL() throws MalformedURLException, URISyntaxException { URIBuilder result = new URIBuilder(GL_BASE_URI); if (GL_PORT != null) { result.setPort(Integer.parseInt(GL_PORT)); }//from www. j av a 2 s. c o m final String username; final String password; if (result.getUserInfo() == null) { username = GL_ADMIN_USER; password = GL_ADMIN_PASSWORD; } else { final String[] userInfo = result.getUserInfo().split(":"); username = (GL_ADMIN_USER != null ? GL_ADMIN_USER : userInfo[0]); password = (GL_ADMIN_PASSWORD != null ? GL_ADMIN_PASSWORD : userInfo[1]); } result.setUserInfo(firstNonNull(username, "admin"), firstNonNull(password, "admin")); return result.build(); }
From source file:org.eclipse.packagedrone.testing.server.channel.UploadApiV2Test.java
@Test public void upload1() throws URISyntaxException, IOException { final ChannelTester tester = getTester(); final File file = getAbsolutePath(CommonResources.BUNDLE_1_RESOURCE); final URIBuilder b = new URIBuilder( resolve("/api/v2/upload/channel/%s/%s", tester.getId(), file.getName())); b.setUserInfo("deploy", this.deployKey); b.addParameter("foo:bar", "baz"); try (final CloseableHttpResponse response = upload(b, file)) { Assert.assertEquals(200, response.getStatusLine().getStatusCode()); }/*from www . ja va 2 s . c om*/ final Set<String> arts = tester.getAllArtifactIds(); Assert.assertEquals(1, arts.size()); }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsStatus.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); String statusPath = String.format("%s%s", extraPath, propertiesProvider.getOwncloudStatusPath()); builder.setPath(statusPath);/*from w w w . j a v a 2 s . c o m*/ return builder.build(); }
From source file:de.dentrassi.pm.jenkins.UploaderV2.java
private URI makeUrl(final String file) throws URIException, IOException { final URI fullUri; try {/* ww w .j av a 2s . com*/ final URIBuilder b = new URIBuilder(this.serverUrl); b.setUserInfo("deploy", this.deployKey); b.setPath(b.getPath() + String.format("/api/v2/upload/channel/%s/%s", URIUtil.encodeWithinPath(this.channelId), file)); b.addParameter("jenkins:buildUrl", this.runData.getUrl()); b.addParameter("jenkins:buildId", this.runData.getId()); b.addParameter("jenkins:buildNumber", String.valueOf(this.runData.getNumber())); b.addParameter("jenkins:jobName", this.runData.getFullName()); final Map<String, String> properties = new HashMap<String, String>(); fillProperties(properties); for (final Map.Entry<String, String> entry : properties.entrySet()) { b.addParameter(entry.getKey(), entry.getValue()); } fullUri = b.build(); } catch (final URISyntaxException e) { throw new IOException(e); } return fullUri; }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsUploadFile.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); String statusPath = String.format("%s%s%s", extraPath, propertiesProvider.getOwncloudWebdavPath(), remotePath);//from w w w . j av a 2 s. co m builder.setPath(statusPath); return builder.build(); }
From source file:org.eclipse.packagedrone.testing.server.channel.UploadApiV3Test.java
@Test public void upload2Archive() throws URISyntaxException, IOException { final ChannelTester tester = ChannelTester.create(getWebContext(), "uploadapi2b"); tester.assignDeployGroup("m1"); final String deployKey = tester.getDeployKeys().iterator().next(); final File file1 = getAbsolutePath(CommonResources.BUNDLE_1_RESOURCE); final File file2 = getAbsolutePath(CommonResources.BUNDLE_2_RESOURCE); final Path tmp = Paths.get("upload-1.zip"); try (TransferArchiveWriter writer = new TransferArchiveWriter(Files.newOutputStream(tmp))) { final Map<MetaKey, String> properties = new HashMap<>(); properties.put(new MetaKey("foo", "bar"), "baz"); properties.put(new MetaKey("foo", "bar2"), "baz2"); writer.createEntry(file1.getName(), properties, ContentProvider.file(file1)); writer.createEntry(file2.getName(), properties, ContentProvider.file(file2)); }// w ww.j av a 2 s.c o m final URIBuilder b = new URIBuilder(resolve("/api/v3/upload/archive/channel/%s", tester.getId())); b.setUserInfo("deploy", deployKey); System.out.println("Request: " + b.build()); try (final CloseableHttpResponse response = upload(b, tmp.toFile())) { final String result = CharStreams .toString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); System.out.println("Result: " + response.getStatusLine()); System.out.println(result); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); } final Set<String> arts = tester.getAllArtifactIds(); Assert.assertEquals(2, arts.size()); }
From source file:org.eclipse.packagedrone.testing.server.channel.UploadApiV3Test.java
@Test public void upload1Plain() throws URISyntaxException, IOException { final ChannelTester tester = ChannelTester.create(getWebContext(), "uploadapi2a"); tester.assignDeployGroup("m1"); final String deployKey = tester.getDeployKeys().iterator().next(); final File file = getAbsolutePath(CommonResources.BUNDLE_1_RESOURCE); final URIBuilder b = new URIBuilder( resolve("/api/v3/upload/plain/channel/%s/%s", tester.getId(), file.getName())); b.setUserInfo("deploy", deployKey); b.addParameter("foo:bar", "baz"); System.out.println("Request: " + b.build()); try (final CloseableHttpResponse response = upload(b, file)) { final String result = CharStreams .toString(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); System.out.println("Result: " + response.getStatusLine()); System.out.println(result); Assert.assertEquals(200, response.getStatusLine().getStatusCode()); }/*from w w w . j a va2 s. co m*/ final Set<String> arts = tester.getAllArtifactIds(); Assert.assertEquals(1, arts.size()); }
From source file:com.anrisoftware.simplerest.owncloudocs.OwncloudOcsCreateShare.java
private URI getRequestURI0() throws URISyntaxException { URI baseUri = account.getBaseUri(); String extraPath = baseUri.getPath(); URIBuilder builder = new URIBuilder(baseUri); builder.setUserInfo(account.getUser(), account.getPassword()); addParameters(builder);/* w ww . ja v a 2 s.c o m*/ String statusPath = String.format("%s%s", extraPath, propertiesProvider.getOwncloudSharesPath()); builder.setPath(statusPath); return builder.build(); }
From source file:com.blackducksoftware.tools.scmconnector.integrations.mercurial.MercurialConnector.java
/** * Constructs a valid HTTP url if a user *and* password is provided. * * @throws Exception// w w w.j av a 2s . co m */ private void buildURL() throws Exception { if (StringUtils.isNotEmpty(user) && StringUtils.isNotEmpty(password)) { URL url = new URL(repositoryURL); String protocol = url.getProtocol(); int port = url.getPort(); String host = url.getHost(); String path = url.getPath(); URIBuilder builder = new URIBuilder(); builder.setScheme(protocol); builder.setHost(host); builder.setPort(port); builder.setPath(path); builder.setUserInfo(user, password); repositoryURL = builder.toString(); // log.info("Using path: " + repositoryURL); // Reveals password } }