@Override
 public void intercept(RequestFacade request) {
   // add header
   request.addHeader("User-Agent", USER_AGENT);
   request.addHeader("Accept", ACCEPT);
   request.addQueryParam("access_token", mAccessToken);
 }
  protected boolean deleteFromRepository(String repository, String groupOrArtifactPath)
      throws IOException {
    String serviceURI =
        "service/local/repositories/" + repository + "/content/" + groupOrArtifactPath;

    Response response = RequestFacade.doGetRequest(serviceURI);
    if (response.getStatus().equals(Status.CLIENT_ERROR_NOT_FOUND)) {
      log.debug("It was not deleted because it didn't exist " + serviceURI);
      return true;
    }

    log.debug("deleting: " + serviceURI);
    response = RequestFacade.sendMessage(serviceURI, Method.DELETE);

    boolean deleted = response.getStatus().isSuccess();

    if (!deleted) {
      log.debug("Failed to delete: " + serviceURI + "  - Status: " + response.getStatus());
    }

    // fake it because the artifact doesn't exist
    // TODO: clean this up.
    if (response.getStatus().getCode() == 404) {
      deleted = true;
    }

    return deleted;
  }
示例#3
0
    @Override
    public void intercept(RequestFacade request) {
      long unixTime = System.currentTimeMillis();
      request.addQueryParam("p1", String.valueOf(unixTime));

      String hash = AppUtils.HMAC(String.valueOf(unixTime)).toLowerCase();
      request.addQueryParam("p2", hash);
    }
  @Override
  public void intercept(RequestFacade request) {

    // Add header to set content type of JSON
    request.addHeader("Content-Type", "application/json");

    // Add auth info for PARSE, normally this is where you'd add your auth info for this request (if
    // needed).
    request.addHeader(HEADER_PARSE_REST_API_KEY, PARSE_REST_API_KEY);
    request.addHeader(HEADER_PARSE_APP_ID, PARSE_APP_ID);

    // Add the user agent to the request.
    request.addHeader("User-Agent", userAgentProvider.get());
  }
  protected Metadata downloadMetadataFromRepository(Gav gav, String repoId)
      throws IOException, XmlPullParserException {
    // File f =
    // new File( nexusWorkDir, "storage/" + repoId + "/" + gav.getGroupId() + "/" +
    // gav.getArtifactId()
    // + "/maven-metadata.xml" );
    //
    // if ( !f.exists() )
    // {
    // throw new FileNotFoundException( "Metadata do not exist! " + f.getAbsolutePath() );
    // }

    String url =
        this.getBaseNexusUrl()
            + REPOSITORY_RELATIVE_URL
            + repoId
            + "/"
            + gav.getGroupId()
            + "/"
            + gav.getArtifactId()
            + "/maven-metadata.xml";

    Response response = RequestFacade.sendMessage(new URL(url), Method.GET, null);
    if (response.getStatus().isError()) {
      return null;
    }

    InputStream stream = response.getEntity().getStream();
    try {
      MetadataXpp3Reader metadataReader = new MetadataXpp3Reader();
      return metadataReader.read(stream);
    } finally {
      IOUtil.close(stream);
    }
  }
 @Override
 public void intercept(RequestFacade requestFacade) {
   if (StringUtils.isNotBlank(username)) {
     final String authorizationValue = encodeCredentialsForBasicAuthorization();
     requestFacade.addHeader("Authorization", authorizationValue);
   }
 }
  @SuppressWarnings("deprecation")
  public File downloadSnapshotArtifact(String repository, Gav gav, File parentDir)
      throws IOException {
    // @see http://issues.sonatype.org/browse/NEXUS-599
    // r=<repoId> -- mandatory
    // g=<groupId> -- mandatory
    // a=<artifactId> -- mandatory
    // v=<version> -- mandatory
    // c=<classifier> -- optional
    // p=<packaging> -- optional, jar is taken as default
    // http://localhost:8087/nexus/service/local/artifact/maven/redirect?r=tasks-snapshot-repo&g=nexus&a=artifact&
    // v=1.0-SNAPSHOT
    String serviceURI =
        "service/local/artifact/maven/redirect?r="
            + repository
            + "&g="
            + gav.getGroupId()
            + "&a="
            + gav.getArtifactId()
            + "&v="
            + gav.getVersion();
    Response response = RequestFacade.doGetRequest(serviceURI);
    Status status = response.getStatus();
    if (status.isError()) {
      throw new FileNotFoundException(status + ": (" + status.getCode() + ")");
    }
    Assert.assertEquals(
        "Snapshot download should redirect to a new file\n "
            + response.getRequest().getResourceRef().toString()
            + " \n Error: "
            + status.getDescription(),
        301,
        status.getCode());

    Reference redirectRef = response.getRedirectRef();
    Assert.assertNotNull(
        "Snapshot download should redirect to a new file "
            + response.getRequest().getResourceRef().toString(),
        redirectRef);

    serviceURI = redirectRef.toString();

    File file = FileUtils.createTempFile(gav.getArtifactId(), '.' + gav.getExtension(), parentDir);
    RequestFacade.downloadFile(new URL(serviceURI), file.getAbsolutePath());

    return file;
  }
示例#8
0
  @Override
  public void intercept(RequestFacade request) {
    final String authVal = Preferences.getUserAuth(context);

    if (authVal != null && !authVal.equals("") && !authVal.equals(":")) {
      request.addHeader("Authorization", authVal);
    }

    Log.d("LOGIN INTERCEPTOR", "Authorization: " + authVal);
  }
  public File downloadFile(URL url, String targetFile) throws IOException {

    return RequestFacade.downloadFile(url, targetFile);
  }
示例#10
0
 @Override
 public void intercept(RequestFacade request) {
   request.addQueryParam("client_id", "d21f2469b3b84eb68d95a44b88c96d38");
 }
 @Override
 public void intercept(RequestFacade request) {
   if (accessToken != null) request.addHeader("Authorization", "Bearer " + accessToken);
 }
 @Override
 public void intercept(RequestFacade request) {
   super.intercept(request);
   request.addHeader("Content-Length", "0");
 }
 @Override
 public void intercept(RequestFacade request) {
   if (TextUtils.isEmpty(TOKEN) || TextUtils.isEmpty(UID)) return;
   request.addHeader("uid", UID);
   request.addHeader("token", TOKEN);
 }
 public void intercept(RequestFacade request) {
   request.addHeader(USER_AGENT_HEADER, "Android");
   request.addHeader(ACCEPT_HEADER, "application/json");
   request.addHeader(TOKEN, AccessUtils.getDeviceId());
 }