Search in sources :

Example 1 with HttpServiceException

use of com.github.noraui.exception.HttpServiceException in project NoraUi by NoraUi.

the class MailSteps method validateActivationLink.

private void validateActivationLink(String subjectMail, String firstCssQuery, Message message) throws MessagingException, IOException, TechnicalException, FailureException {
    final Document doc = Jsoup.parse(getTextFromMessage(message));
    final Element link = doc.selectFirst(firstCssQuery);
    try {
        final String response = httpService.get(link.attr("href"));
        log.debug("response is {}.", response);
    } catch (final HttpServiceException e) {
        log.error(Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_MAIL_ACTIVATION), subjectMail), e);
        new Result.Failure<>("", Messages.format(Messages.getMessage(Messages.FAIL_MESSAGE_MAIL_ACTIVATION), subjectMail), false, Context.getCallBack(Callbacks.RESTART_WEB_DRIVER));
    }
}
Also used : HttpServiceException(com.github.noraui.exception.HttpServiceException) Element(org.jsoup.nodes.Element) Document(org.jsoup.nodes.Document) Result(com.github.noraui.exception.Result)

Example 2 with HttpServiceException

use of com.github.noraui.exception.HttpServiceException in project NoraUi by NoraUi.

the class HttpServiceImpl method post.

/**
 * {@inheritDoc}
 */
@Override
public String post(String url, String json) throws HttpServiceException, TechnicalException {
    log.debug("HttpService POST on url: {}", url);
    Response response;
    try {
        response = getClient().newCall(new Request.Builder().url(url).post(RequestBody.create(MediaType.parse("application/json"), json)).build()).execute();
        String jsonResponse = response.body().string();
        log.info("JSON response is: {}", jsonResponse);
        response.close();
        return jsonResponse;
    } catch (IOException e) {
        log.error(Messages.getMessage(HttpServiceException.HTTP_SERVICE_ERROR_MESSAGE));
        throw new HttpServiceException(Messages.getMessage(HttpServiceException.HTTP_SERVICE_ERROR_MESSAGE), e);
    }
}
Also used : Response(okhttp3.Response) HttpServiceException(com.github.noraui.exception.HttpServiceException) IOException(java.io.IOException)

Example 3 with HttpServiceException

use of com.github.noraui.exception.HttpServiceException in project NoraUi by NoraUi.

the class HttpServiceImpl method get.

/**
 * {@inheritDoc}
 */
@Override
public String get(String url) throws HttpServiceException, TechnicalException {
    log.debug("HttpService GET on url: {}", url);
    Response response;
    try {
        response = getClient().newCall(new Request.Builder().url(new URL(url)).header("Accept", "application/json").build()).execute();
        if (response.code() == 200) {
            String jsonResponse = response.body().string();
            log.info("JSON response code:[{}] and body:[{}]", response.code(), jsonResponse);
            response.close();
            return jsonResponse;
        } else {
            log.info("JSON response code:[{}]", response.code());
            response.close();
            return "";
        }
    } catch (IOException e) {
        log.error(Messages.getMessage(HttpServiceException.HTTP_SERVICE_ERROR_MESSAGE));
        throw new HttpServiceException(Messages.getMessage(HttpServiceException.HTTP_SERVICE_ERROR_MESSAGE), e);
    }
}
Also used : Response(okhttp3.Response) HttpServiceException(com.github.noraui.exception.HttpServiceException) IOException(java.io.IOException) URL(java.net.URL)

Example 4 with HttpServiceException

use of com.github.noraui.exception.HttpServiceException in project NoraUi by NoraUi.

the class RestDataProvider method initColumns.

private void initColumns() throws EmptyDataFileContentException {
    final String url = this.norauiWebServicesApi + scenarioName + "/columns";
    log.debug("initColumns with this url [{}]", url);
    try {
        String httpResponse = httpService.get(url);
        if (!"".equals(httpResponse)) {
            columns = new Gson().fromJson(httpResponse, DataModel.class).getColumns();
            if (columns != null && !columns.isEmpty()) {
                resultColumnName = Messages.getMessage(ResultColumnNames.RESULT_COLUMN_NAME);
                columns.add(resultColumnName);
            } else {
                log.warn("No column could be returned at {}", url);
                throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
            }
        } else {
            log.warn("No column could be returned at {}", url);
            throw new EmptyDataFileContentException(Messages.getMessage(EmptyDataFileContentException.EMPTY_DATA_FILE_CONTENT_ERROR_MESSAGE));
        }
    } catch (TechnicalException | NumberFormatException | HttpServiceException e) {
        log.error("initColumns error", e);
    }
}
Also used : HttpServiceException(com.github.noraui.exception.HttpServiceException) TechnicalException(com.github.noraui.exception.TechnicalException) Gson(com.google.gson.Gson) EmptyDataFileContentException(com.github.noraui.exception.data.EmptyDataFileContentException)

Example 5 with HttpServiceException

use of com.github.noraui.exception.HttpServiceException in project NoraUi by NoraUi.

the class RestDataProvider method writeValue.

/**
 * {@inheritDoc}
 */
@Override
protected void writeValue(String column, int line, String value) {
    log.info("Writing: [{}] at line [{}] in column [{}]", value, line, column);
    final int colIndex = columns.indexOf(column);
    final String url = this.norauiWebServicesApi + scenarioName + COLUMN + colIndex + LINE + line;
    log.info("url: [{}]", url);
    try {
        final DataModel dataModel = new Gson().fromJson(httpService.post(url, value), DataModel.class);
        if (resultColumnName.equals(column)) {
            if (value.equals(dataModel.getRows().get(line - 1).getResult())) {
                log.info(Messages.getMessage(REST_DATA_PROVIDER_WRITING_IN_REST_WS_ERROR_MESSAGE), column, line, value);
            }
        } else {
            if (value.equals(dataModel.getRows().get(line - 1).getColumns().get(colIndex - 1))) {
                log.info(Messages.getMessage(REST_DATA_PROVIDER_WRITING_IN_REST_WS_ERROR_MESSAGE), column, line, value);
            }
        }
    } catch (TechnicalException | NumberFormatException | HttpServiceException e) {
        log.error("writeValue error", e);
    }
}
Also used : HttpServiceException(com.github.noraui.exception.HttpServiceException) TechnicalException(com.github.noraui.exception.TechnicalException) Gson(com.google.gson.Gson)

Aggregations

HttpServiceException (com.github.noraui.exception.HttpServiceException)5 TechnicalException (com.github.noraui.exception.TechnicalException)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Response (okhttp3.Response)2 Result (com.github.noraui.exception.Result)1 EmptyDataFileContentException (com.github.noraui.exception.data.EmptyDataFileContentException)1 URL (java.net.URL)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1