Beispiel #1
0
  /**
   * Upload artifact.
   *
   * @param req the req
   * @param response the response
   * @throws ServletException the servlet exception
   * @throws IOException Signals that an I/O exception has occurred.
   */
  private void uploadArtifact(HttpServletRequest req, HttpServletResponse response)
      throws ServletException, IOException {
    // Get the URL request and prepare it to obtain the maven metadata
    // information
    String url = req.getRequestURI();
    String maven_url = ""; // $NON-NLS-1$
    if (url.contains(URL_CONTEXT_STR)) {
      maven_url = url.substring(url.indexOf(URL_CONTEXT_STR) + URL_CONTEXT_STR.length());
    } else {
      maven_url = url;
    }

    if (maven_url.startsWith("/")) { // $NON-NLS-1$
      maven_url = maven_url.substring(1);
    }

    // Extract the relevant content from the POST'd form
    Map<String, String> responseMap = new HashMap<String, String>();

    InputStream content = null;
    // Parse the request
    content = req.getInputStream();

    // Builder class that converts the url into a Maven MetaData Object
    MavenMetaData metadata = MavenMetaDataBuilder.build(maven_url);
    try {
      if (metadata.isArtifact()) {
        if (SNAPSHOT_ALLOWED || !metadata.isSnapshotVersion()) {
          String uuid = service.uploadArtifact(metadata, content);
          responseMap.put("uuid", uuid); // $NON-NLS-1$
        } else {
          response.sendError(
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              Messages.i18n.format("maven.servlet.put.snapshot.not.allowed")); // $NON-NLS-1$
        }

      } else {
        response.sendError(
            HttpServletResponse.SC_BAD_REQUEST,
            Messages.i18n.format("maven.servlet.put.url.without.artifact")); // $NON-NLS-1$
      }

    } catch (Throwable e) {
      logger.error(
          Messages.i18n.format("maven.servlet.artifact.content.put.exception"), e); // $NON-NLS-1$
      response.sendError(
          HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          Messages.i18n.format("maven.servlet.put.exception")); // $NON-NLS-1$
    } finally {
      if (content != null) {
        IOUtils.closeQuietly(content);
      }
    }
  }