Package org.purl.sword.base

Examples of org.purl.sword.base.DepositResponse


    if (doAuthentication) {
      setBasicCredentials(username, password);
    }

    DepositResponse response = null;

    String messageBody = "";
   
    try {
      if (message.isUseMD5()) {
        String md5 = ChecksumUtils.generateMD5(message.getFilepath());
        if (message.getChecksumError()) {
          md5 = "1234567890";
        }
        log.debug("checksum error is: " + md5);
        if (md5 != null) {
          httppost.addHeader(HttpHeaders.CONTENT_MD5, md5);
        }
      }

      String filename = message.getFilename();
      if (! "".equals(filename)) {
        httppost.addHeader(HttpHeaders.CONTENT_DISPOSITION,
                        " filename=" + filename);
      }

      if (containsValue(message.getSlug())) {
        httppost.addHeader(HttpHeaders.SLUG, message.getSlug());
      }

            if(message.getCorruptRequest())
            {
                // insert a header with an invalid boolean value
                httppost.addHeader(HttpHeaders.X_NO_OP, "Wibble");
            }else{
                httppost.addHeader(HttpHeaders.X_NO_OP, Boolean
          .toString(message.isNoOp()));
            }
      httppost.addHeader(HttpHeaders.X_VERBOSE, Boolean
          .toString(message.isVerbose()));

      String packaging = message.getPackaging();
      if (packaging != null && packaging.length() > 0) {
        httppost.addHeader(HttpHeaders.X_PACKAGING, packaging);
      }

      String onBehalfOf = message.getOnBehalfOf();
      if (containsValue(onBehalfOf)) {
        httppost.addHeader(HttpHeaders.X_ON_BEHALF_OF, onBehalfOf);
      }
     
      String userAgent = message.getUserAgent();
      if (containsValue(userAgent)) {
        httppost.addHeader(HttpHeaders.USER_AGENT, userAgent);
      }


      FileEntity requestEntity = new FileEntity(
                    new File(message.getFilepath()),
                    ContentType.create(message.getFiletype()));
      httppost.setEntity(requestEntity);

      HttpResponse httpResponse = client.execute(httppost);
            StatusLine statusLine = httpResponse.getStatusLine();
            int statusCode = statusLine.getStatusCode();
      status = new Status(statusCode, statusLine.getReasonPhrase());

      log.info("Checking the status code: " + status.getCode());

      if (status.getCode() == HttpStatus.SC_ACCEPTED
          || status.getCode() == HttpStatus.SC_CREATED) {
        messageBody = readResponse(httpResponse.getEntity().getContent());
        response = new DepositResponse(status.getCode());
        response.setLocation(httpResponse.getFirstHeader("Location").getValue());
        // added call for the status code.
        lastUnmarshallInfo = response.unmarshall(messageBody, new Properties());
      }
      else {
        messageBody = readResponse(httpResponse.getEntity().getContent());
        response = new DepositResponse(status.getCode());
        response.unmarshallErrorDocument(messageBody);
      }
      return response;

    } catch (NoSuchAlgorithmException nex) {
      throw new SWORDClientException("Unable to use MD5. "
View Full Code Here


      message.setChecksumError(errorMD5);
      message.setVerbose(verbose);
      message.setNoOp(noOp);

      // Post the file
      DepositResponse resp = client.postFile(message);

      // Set the status
      Status status = client.getStatus();
      request.setAttribute("status", status.toString());
      if ((status.getCode() == 201) || (status.getCode() == 202)) {
        // Set the debug response
        String xml = resp.marshall();

                String validateXml = xml;
                validateXml = validateXml.replaceAll("&", "&");
                validateXml = validateXml.replaceAll("<", "&lt;");
                validateXml = validateXml.replaceAll(">", "&gt;");
                validateXml = validateXml.replaceAll("\"", "&quot;");
                validateXml = validateXml.replaceAll("'", "&apos;");
                request.setAttribute("xmlValidate", validateXml); // for passing to validation

        xml = xml.replaceAll("<", "&lt;");
        xml = xml.replaceAll(">", "&gt;");
        request.setAttribute("xml", xml);
        SWORDEntry se = resp.getEntry();
        request.setAttribute("id", se.getId());
        request.setAttribute("authors", se.getAuthors());
        request.setAttribute("contributors", se.getContributors());
        request.setAttribute("title", se.getTitle().getContent());
        request.setAttribute("updated", se.getUpdated());
        request.setAttribute("categories", se.getCategories());
        request.setAttribute("treatment", se.getTreatment());
        request.setAttribute("summary", se.getSummary().getContent());
        request.setAttribute("generator", se.getGenerator().getContent());
        request.setAttribute("userAgent", se.getUserAgent());
        request.setAttribute("packaging", se.getPackaging());
        request.setAttribute("links", se.getLinks());
        request.setAttribute("location", resp.getLocation());
       
        // Set the ServiceDocument and associated values
        request.getRequestDispatcher("deposit.jsp").forward(request, response);
        return;
      } else {
        String error = status.getCode() + " " + status.getMessage() + " - ";
        try {
          error += resp.getEntry().getSummary().getContent();
        } catch (Exception e) {
          // Do nothing - we have default error message
                    e.printStackTrace();
        }
        request.setAttribute("error", error);
       
        // Try and get an error document in xml
        String xml = resp.marshall();
        xml = xml.replaceAll("<", "&lt;");
        xml = xml.replaceAll(">", "&gt;");
        request.setAttribute("xml", xml);
       
        request.getRequestDispatcher("depositform.jsp").forward(request, response);
View Full Code Here

TOP

Related Classes of org.purl.sword.base.DepositResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.