Java Code Examples for org.apache.commons.httpclient.HttpStatus#SC_NOT_FOUND

The following examples show how to use org.apache.commons.httpclient.HttpStatus#SC_NOT_FOUND . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResponseMappers.java    From feign-reactive with Apache License 2.0 6 votes vote down vote up
public static <T> BiFunction<MethodMetadata, ReactiveHttpResponse, ReactiveHttpResponse> ignore404() {
  return (MethodMetadata methodMetadata, ReactiveHttpResponse response) -> {
    if (response.status() == HttpStatus.SC_NOT_FOUND) {
      return new DelegatingReactiveHttpResponse<T>(response) {
        @Override
        public int status() {
          return HttpStatus.SC_OK;
        }

        @Override
        public Publisher body() {
          return Mono.empty();
        }
      };
    }
    return response;
  };
}
 
Example 2
Source File: S3ProxyImpl.java    From pravega with Apache License 2.0 6 votes vote down vote up
@Synchronized
@Override
public void putObject(String bucketName, String key, Range range, Object content) {
    byte[] existingBytes = new byte[Math.toIntExact(range.getFirst())];
    try {
        if (range.getFirst() != 0) {
            int bytesRead = client.getObject(bucketName, key).getObject().read(existingBytes, 0,
                    Math.toIntExact(range.getFirst()));
            if (bytesRead != range.getFirst()) {
                throw new S3Exception("InvalidRange", HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, "InvalidRange", key);
            }
        }
        val contentBytes  = IOUtils.toByteArray((InputStream) content);
        if (contentBytes.length != Math.toIntExact(range.getLast()  - range.getFirst() + 1)) {
            throw new S3Exception("InvalidRange", HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE, "InvalidRange", key);
        }

        val objectAfterPut = ArrayUtils.addAll(existingBytes, contentBytes);
        client.putObject(new PutObjectRequest(bucketName, key, (Object) objectAfterPut));
        aclMap.put(key, aclMap.get(key).withSize(range.getLast() - 1));
    } catch (IOException e) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
}
 
Example 3
Source File: S3FileSystemImpl.java    From pravega with Apache License 2.0 6 votes vote down vote up
@Override
public ListObjectsResult listObjects(String bucketName, String prefix) {
    ListObjectsResult result = new ListObjectsResult();
    ArrayList<S3Object> list = new ArrayList<>();
    Path path = Paths.get(this.baseDir, bucketName, prefix);
    try {
        if (Files.exists(path)) {
            if (Files.isDirectory(path)) {
                Files.list(path).forEach(file -> {
                    addFileAsObjectToList(file, list, bucketName);
                });
            } else {
                addFileAsObjectToList(path, list, bucketName);
            }
        }
    } catch (IOException e) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    result.setObjects(list);
    return result;
}
 
Example 4
Source File: S3FileSystemImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Override
public void deleteObject(String bucketName, String key) {
    Path path = Paths.get(this.baseDir, bucketName, key);
    try {
        Files.delete(path);
    } catch (IOException e) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
}
 
Example 5
Source File: MorphologicalServiceFRImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
private InputStream retreiveXMLReply(String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (log.isDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString(), null);
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString(), null);
        }
    } catch (Exception e) {
        log.error("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
        // error
        log.error("URL not found!", null);
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}
 
Example 6
Source File: MorphologicalServiceFRImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
private InputStream retreiveXMLReply(String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (log.isDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString(), null);
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString(), null);
        }
    } catch (Exception e) {
        log.error("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
        // error
        log.error("URL not found!", null);
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}
 
Example 7
Source File: S3ProxyImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Override
public AccessControlList getObjectAcl(String bucketName, String key) {
    AclSize retVal = aclMap.get(key);
    if (retVal == null) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
    return retVal.getAcl();
}
 
Example 8
Source File: S3ProxyImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Synchronized
@Override
public void setObjectAcl(SetObjectAclRequest request) {
    AclSize retVal = aclMap.get(request.getKey());
    if (retVal == null) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", request.getKey());
    }
    aclMap.put(request.getKey(), retVal.withAcl(request.getAcl()));
}
 
Example 9
Source File: MorphologicalServiceDEImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
private InputStream retreiveXMLReply(String partOfSpeech, String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair posValues = new NameValuePair(PART_OF_SPEECH_PARAM, partOfSpeech);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (log.isDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + PART_OF_SPEECH_PARAM + "=" + partOfSpeech + "&" + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { posValues, wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString());
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString());
        }
    } catch (Exception e) {
        log.error("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
        // error
        log.error("URL not found!");
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}
 
Example 10
Source File: S3FileSystemImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Synchronized
@Override
public CompleteMultipartUploadResult completeMultipartUpload(CompleteMultipartUploadRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    try {
        partMap.forEach((index, copyPart) -> {
            if (!copyPart.getKey().equals(copyPart.getSourceKey())) {
                Path sourcePath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getSourceKey());
                Path targetPath = Paths.get(this.baseDir, copyPart.getBucketName(), copyPart.getKey());
                try (FileChannel sourceChannel = FileChannel.open(sourcePath, StandardOpenOption.READ);
                     FileChannel targetChannel = FileChannel.open(targetPath, StandardOpenOption.WRITE)) {
                    targetChannel.transferFrom(sourceChannel, Files.size(targetPath),
                            copyPart.getSourceRange().getLast() + 1 - copyPart.getSourceRange().getFirst());
                    targetChannel.close();
                    AclSize aclMap = this.aclMap.get(copyPart.getKey());
                    this.aclMap.put(copyPart.getKey(), aclMap.withSize(Files.size(targetPath)));
                } catch (IOException e) {
                    throw new S3Exception("NoSuchKey", 404, "NoSuchKey", "");
                }
            }
        });
    } finally {
        multipartUploads.remove(request.getKey());
    }

    return new CompleteMultipartUploadResult();
}
 
Example 11
Source File: MorphologicalServiceDEImpl.java    From olat with Apache License 2.0 5 votes vote down vote up
private InputStream retreiveXMLReply(String partOfSpeech, String word) {
    HttpClient client = HttpClientFactory.getHttpClientInstance();
    HttpMethod method = new GetMethod(MORPHOLOGICAL_SERVICE_ADRESS);
    NameValuePair posValues = new NameValuePair(PART_OF_SPEECH_PARAM, partOfSpeech);
    NameValuePair wordValues = new NameValuePair(GLOSS_TERM_PARAM, word);
    if (log.isDebugEnabled()) {
        String url = MORPHOLOGICAL_SERVICE_ADRESS + "?" + PART_OF_SPEECH_PARAM + "=" + partOfSpeech + "&" + GLOSS_TERM_PARAM + "=" + word;
        log.debug("Send GET request to morph-service with URL: " + url);
    }
    method.setQueryString(new NameValuePair[] { posValues, wordValues });
    try {
        client.executeMethod(method);
        int status = method.getStatusCode();
        if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
            if (log.isDebugEnabled()) {
                log.debug("got a valid reply!");
            }
        } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
            log.error("Morphological Service unavailable (404)::" + method.getStatusLine().toString());
        } else {
            log.error("Unexpected HTTP Status::" + method.getStatusLine().toString());
        }
    } catch (Exception e) {
        log.error("Unexpected exception trying to get flexions!", e);
    }
    Header responseHeader = method.getResponseHeader("Content-Type");
    if (responseHeader == null) {
        // error
        log.error("URL not found!");
    }
    HttpRequestMediaResource mr = new HttpRequestMediaResource(method);
    InputStream inputStream = mr.getInputStream();

    return inputStream;
}
 
Example 12
Source File: S3FileSystemImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Override
public CopyPartResult copyPart(CopyPartRequest request) {
    Map<Integer, CopyPartRequest> partMap = multipartUploads.get(request.getKey());
    if (partMap == null) {
        throw new S3Exception("NoSuchKey", HttpStatus.SC_NOT_FOUND, "NoSuchKey", "");
    }
    partMap.put(request.getPartNumber(), request);
    CopyPartResult result = new CopyPartResult();
    result.setPartNumber(request.getPartNumber());
    result.setETag(request.getUploadId());
    return result;
}
 
Example 13
Source File: S3FileSystemImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Override
public AccessControlList getObjectAcl(String bucketName, String key) {
    AclSize retVal = aclMap.get(key);
    if (retVal == null) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
    return retVal.getAcl();
}
 
Example 14
Source File: S3FileSystemImpl.java    From pravega with Apache License 2.0 5 votes vote down vote up
@Synchronized
@Override
public void setObjectAcl(String bucketName, String key, AccessControlList acl) {
    AclSize retVal = aclMap.get(key);
    if (retVal == null) {
        throw new S3Exception("NoObject", HttpStatus.SC_NOT_FOUND, "NoSuchKey", key);
    }
    aclMap.put(key, retVal.withAcl(acl));
}
 
Example 15
Source File: HttpClientStub.java    From jenkins-mattermost-plugin with MIT License 5 votes vote down vote up
@Override
public int executeMethod(HttpMethod httpMethod) {
  numberOfCallsToExecuteMethod++;
  if (failAlternateResponses && (numberOfCallsToExecuteMethod % 2 == 0)) {
    return HttpStatus.SC_NOT_FOUND;
  } else {
    return httpStatus;
  }
}
 
Example 16
Source File: DavExchangeSession.java    From davmail with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void deleteItem(String folderPath, String itemName) throws IOException {
    String eventPath = URIUtil.encodePath(getFolderPath(folderPath) + '/' + convertItemNameToEML(itemName));
    int status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
    if (status == HttpStatus.SC_NOT_FOUND && isMainCalendar(folderPath)) {
        // retry in tasks folder
        eventPath = URIUtil.encodePath(getFolderPath(TASKS) + '/' + convertItemNameToEML(itemName));
        status = DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, eventPath);
    }
    if (status == HttpStatus.SC_NOT_FOUND) {
        LOGGER.debug("Unable to delete " + itemName + ": item not found");
    }
}
 
Example 17
Source File: SourceCodeDisclosureCVE20121823.java    From zap-extensions with Apache License 2.0 4 votes vote down vote up
@Override
public void scan() {
    try {

        if (!getBaseMsg().getResponseHeader().isText()) {
            return; // Ignore images, pdfs, etc.
        }
        if (getAlertThreshold() != AlertThreshold.LOW
                && getBaseMsg().getResponseHeader().isJavaScript()) {
            return;
        }
        // at Low or Medium strength, do not attack URLs which returned "Not Found"
        AttackStrength attackStrength = getAttackStrength();
        if ((attackStrength == AttackStrength.LOW || attackStrength == AttackStrength.MEDIUM)
                && (getBaseMsg().getResponseHeader().getStatusCode()
                        == HttpStatus.SC_NOT_FOUND)) return;

        URI originalURI = getBaseMsg().getRequestHeader().getURI();

        // construct a new URL based on the original URL, but without any of the original
        // parameters
        String attackParam = "?-s";
        URI attackURI = createAttackUri(originalURI, attackParam);
        if (attackURI == null) {
            return;
        }
        // and send it as a GET, unauthorised.
        HttpMessage attackmsg = new HttpMessage(attackURI);
        sendAndReceive(attackmsg, false); // do not follow redirects

        if (attackmsg.getResponseHeader().getStatusCode() == HttpStatus.SC_OK) {
            // double-check: does the response contain HTML encoded PHP?
            // Ignore the case where it contains encoded HTML for now, since thats not a source
            // code disclosure anyway
            // (HTML is always sent back to the web browser)
            String responseBody = new String(attackmsg.getResponseBody().getBytes());
            String responseBodyDecoded = new Source(responseBody).getRenderer().toString();

            Matcher matcher1 = PHP_PATTERN1.matcher(responseBodyDecoded);
            Matcher matcher2 = PHP_PATTERN2.matcher(responseBodyDecoded);
            boolean match1 = matcher1.matches();
            boolean match2 = matcher2.matches();

            if ((!responseBody.equals(responseBodyDecoded)) && (match1 || match2)) {

                if (log.isDebugEnabled()) {
                    log.debug("Source Code Disclosure alert for: " + originalURI.getURI());
                }

                String sourceCode = null;
                if (match1) {
                    sourceCode = matcher1.group(1);
                } else {
                    sourceCode = matcher2.group(1);
                }

                // bingo.
                newAlert()
                        .setConfidence(Alert.CONFIDENCE_MEDIUM)
                        .setDescription(
                                Constant.messages.getString(
                                        "ascanbeta.sourcecodedisclosurecve-2012-1823.desc"))
                        .setOtherInfo(sourceCode)
                        .setSolution(
                                Constant.messages.getString(
                                        "ascanbeta.sourcecodedisclosurecve-2012-1823.soln"))
                        .setMessage(attackmsg)
                        .raise();
            }
        }
    } catch (Exception e) {
        log.error(
                "Error scanning a Host for Source Code Disclosure via CVE-2012-1823: "
                        + e.getMessage(),
                e);
    }
}
 
Example 18
Source File: SystemRegistrationWorker.java    From olat with Apache License 2.0 4 votes vote down vote up
protected boolean doTheWork(String registrationData, String url, String version) {
    String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY);
    boolean regStatus = false;
    if (StringHelper.containsNonWhitespace(registrationData)) {
        // only send when there is something to send
        final HttpClient client = HttpClientFactory.getHttpClientInstance();
        client.getParams().setParameter("http.useragent", "OLAT Registration Agent ; " + version);

        log.info("URL:" + url, null);
        final PutMethod method = new PutMethod(url);
        if (registrationKey != null) {
            // updating
            method.setRequestHeader("Authorization", registrationKey);
            if (log.isDebugEnabled()) {
                log.debug("Authorization: " + registrationKey, null);
            } else {
                log.debug("Authorization: EXISTS", null);
            }
        } else {
            log.info("Authorization: NONE", null);
        }
        method.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
        try {
            method.setRequestEntity(new StringRequestEntity(registrationData, "application/xml", "UTF8"));
            client.executeMethod(method);
            final int status = method.getStatusCode();
            if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
                log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null);
                registrationKey = method.getResponseBodyAsString();
                propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey);
                regStatus = true;
            } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null);
                regStatus = false;
            } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                log.info(method.getResponseBodyAsString() + method.getStatusText());
                regStatus = false;
            } else {
                log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null);
                regStatus = false;
            }
        } catch (final Exception e) {
            log.error("Unexpected exception during registration call", e);
            regStatus = false;
        }
    } else {
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
        log.warn(
                "* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *",
                null);
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
    }
    return regStatus;
}
 
Example 19
Source File: SystemRegistrationWorker.java    From olat with Apache License 2.0 4 votes vote down vote up
protected boolean doTheWork(String registrationData, String url, String version) {
    String registrationKey = propertyService.getStringProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY);
    boolean regStatus = false;
    if (StringHelper.containsNonWhitespace(registrationData)) {
        // only send when there is something to send
        final HttpClient client = HttpClientFactory.getHttpClientInstance();
        client.getParams().setParameter("http.useragent", "OLAT Registration Agent ; " + version);

        log.info("URL:" + url, null);
        final PutMethod method = new PutMethod(url);
        if (registrationKey != null) {
            // updating
            method.setRequestHeader("Authorization", registrationKey);
            if (log.isDebugEnabled()) {
                log.debug("Authorization: " + registrationKey, null);
            } else {
                log.debug("Authorization: EXISTS", null);
            }
        } else {
            log.info("Authorization: NONE", null);
        }
        method.setRequestHeader("Content-Type", "application/xml; charset=utf-8");
        try {
            method.setRequestEntity(new StringRequestEntity(registrationData, "application/xml", "UTF8"));
            client.executeMethod(method);
            final int status = method.getStatusCode();
            if (status == HttpStatus.SC_NOT_MODIFIED || status == HttpStatus.SC_OK) {
                log.info("Successfully registered OLAT installation on olat.org server, thank you for your support!", null);
                registrationKey = method.getResponseBodyAsString();
                propertyService.setProperty(PropertyLocator.SYSTEM_REG_SECRET_KEY, registrationKey);
                regStatus = true;
            } else if (method.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
                log.error("File could be created not on registration server::" + method.getStatusLine().toString(), null);
                regStatus = false;
            } else if (method.getStatusCode() == HttpStatus.SC_NO_CONTENT) {
                log.info(method.getResponseBodyAsString() + method.getStatusText());
                regStatus = false;
            } else {
                log.error("Unexpected HTTP Status::" + method.getStatusLine().toString() + " during registration call", null);
                regStatus = false;
            }
        } catch (final Exception e) {
            log.error("Unexpected exception during registration call", e);
            regStatus = false;
        }
    } else {
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
        log.warn(
                "* This OLAT installation is not registered. Please, help us with your statistical data and register your installation under Adminisration - Systemregistration. THANK YOU! *",
                null);
        log.warn(
                "****************************************************************************************************************************************************************************",
                null);
    }
    return regStatus;
}
 
Example 20
Source File: EwsExchangeSession.java    From davmail with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Get item content.
 *
 * @param itemId EWS item id
 * @return item content as byte array
 * @throws IOException on error
 */
protected byte[] getContent(ItemId itemId) throws IOException {
    GetItemMethod getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, true);
    byte[] mimeContent = null;
    try {
        executeMethod(getItemMethod);
        mimeContent = getItemMethod.getMimeContent();
    } catch (EWSException e) {
        LOGGER.warn("GetItem with MimeContent failed: " + e.getMessage());
    }
    if (getItemMethod.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
        throw new HttpNotFoundException("Item " + itemId + " not found");
    }
    if (mimeContent == null) {
        LOGGER.warn("MimeContent not available, trying to rebuild from properties");
        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            getItemMethod = new GetItemMethod(BaseShape.ID_ONLY, itemId, false);
            getItemMethod.addAdditionalProperty(Field.get("contentclass"));
            getItemMethod.addAdditionalProperty(Field.get("message-id"));
            getItemMethod.addAdditionalProperty(Field.get("from"));
            getItemMethod.addAdditionalProperty(Field.get("to"));
            getItemMethod.addAdditionalProperty(Field.get("cc"));
            getItemMethod.addAdditionalProperty(Field.get("subject"));
            getItemMethod.addAdditionalProperty(Field.get("date"));
            getItemMethod.addAdditionalProperty(Field.get("body"));
            executeMethod(getItemMethod);
            EWSMethod.Item item = getItemMethod.getResponseItem();

            if (item == null) {
                throw new HttpNotFoundException("Item " + itemId + " not found");
            }

            MimeMessage mimeMessage = new MimeMessage((Session) null);
            mimeMessage.addHeader("Content-class", item.get(Field.get("contentclass").getResponseName()));
            mimeMessage.setSentDate(parseDateFromExchange(item.get(Field.get("date").getResponseName())));
            mimeMessage.addHeader("From", item.get(Field.get("from").getResponseName()));
            mimeMessage.addHeader("To", item.get(Field.get("to").getResponseName()));
            mimeMessage.addHeader("Cc", item.get(Field.get("cc").getResponseName()));
            mimeMessage.setSubject(item.get(Field.get("subject").getResponseName()));
            String propertyValue = item.get(Field.get("body").getResponseName());
            if (propertyValue == null) {
                propertyValue = "";
            }
            mimeMessage.setContent(propertyValue, "text/html; charset=UTF-8");

            mimeMessage.writeTo(baos);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Rebuilt message content: " + new String(baos.toByteArray(), StandardCharsets.UTF_8));
            }
            mimeContent = baos.toByteArray();

        } catch (IOException | MessagingException e2) {
            LOGGER.warn(e2);
        }
        if (mimeContent == null) {
            throw new IOException("GetItem returned null MimeContent");
        }
    }
    return mimeContent;
}