private void checkResponse(HttpResponse response,
            HttpEntity responseEntity, String expectedContentType)
            throws IOException, NamiApiException {
        // Teste, ob der Statuscode der Antwort 200 (OK) ist
        if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
            // check if response is redirect to an error page
            Header locationHeader = response.getFirstHeader("Location");
            if (locationHeader != null) {
                String redirectTarget = locationHeader.getValue();
                // Extract error message from URL in location
                log.warning("Got redirect to: " + redirectTarget);
                // get query part (after '?')
                String redirectQuery = redirectTarget.substring(redirectTarget
                        .indexOf('?') + 1);
                if (redirectTarget.contains("error.jsp")) {
                    String message = URLDecoder.decode(redirectQuery, "UTF-8");
                    message = message.split("=", 2)[1];
                    throw new NamiApiException(message);
                }
            } else {
                // extract description from JBoss error page
                String error = "";
                try {
                    Document doc = getCleanedDom(response.getEntity()
                            .getContent());

                    XPathFactory xpathFac = XPathFactory.instance();
                    // XPath describes content of description field
                    String xpathStr = "/html/body/p[3]/u/text()";
                    XPathExpression<Text> xpath = xpathFac.compile(xpathStr,
                            Filters.textOnly());
                    Text xpathResult = xpath.evaluateFirst(doc);
                    if (xpathResult != null) {
                        error = StringEscapeUtils.unescapeHtml4(xpathResult
                                .getText());
                    }
                } catch (Exception e) {
                    throw new NamiApiException(e);
                }
                throw new NamiApiException(error);
            }
            throw new NamiApiException("Statuscode of response is not 200 OK.");
        }

        // Teste, ob die Antwort den richtigen Content-Type liefert
        Header contentTypeHdr = responseEntity.getContentType();
        if (contentTypeHdr == null) {
            throw new NamiApiException("Response has no Content-Type.");
        } else {
            String contentType = contentTypeHdr.getValue();
            if (!contentType.equals(expectedContentType)
                    && !contentType.contains(expectedContentType + ";")) {
                throw new NamiApiException("Content-Type of response is "
                        + contentType + "; expected " + expectedContentType
                        + ".");
            }
        }
    }