<commit_before>/*
 * Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.
 */

package com.haulmont.cuba.core.sys.remoting;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
import org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor;
import org.springframework.remoting.support.RemoteInvocationResult;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

/**
 * <p>$Id$</p>
 *
 * @author krivopustov
 */
public class ClusteredHttpInvokerRequestExecutor extends SimpleHttpInvokerRequestExecutor {

    private ClusterInvocationSupport support;

    public ClusteredHttpInvokerRequestExecutor(ClusterInvocationSupport support) {
        this.support = support;
    }

    @Override
    protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException {
        HttpURLConnection con = null;

        List<String> urlList = support.getUrlList(config.getServiceUrl());
        for (int i = 0; i < urlList.size(); i++) {
            String url = urlList.get(i);
            con = openConnection(url);
            try {
                prepareConnection(con, baos.size());
                writeRequestBody(config, con, baos);
                if (i > 0) {
                    support.updateUrlPriority(url);
                }
                break;
            } catch (IOException e) {
                List list = ExceptionUtils.getThrowableList(e);
                boolean isConnectException = false;
                for (Object throwable : list) {
                    if (throwable instanceof ConnectException) {
                        logger.info("Invocation of " + url + " failed: " + throwable);
                        isConnectException = true;
                        break;
                    }
                }
                if (isConnectException) {
                    if (i < urlList.size() - 1) {
                        logger.info("Trying to invoke the next available URL");
                        continue;<commit_msg>- reducing number of requests to server on booking screen loading   - removed unnecessary jpa properties from app-persistence.xml - renamed some config properties<commit_after>/*
 * Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.
 */

package com.haulmont.cuba.core.sys.remoting;

import org.apache.commons.lang.exception.ExceptionUtils;
import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
import org.springframework.remoting.httpinvoker.SimpleHttpInvokerRequestExecutor;
import org.springframework.remoting.support.RemoteInvocationResult;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

/**
 * <p>$Id$</p>
 *
 * @author krivopustov
 */
public class ClusteredHttpInvokerRequestExecutor extends SimpleHttpInvokerRequestExecutor {

    private ClusterInvocationSupport support;

    public ClusteredHttpInvokerRequestExecutor(ClusterInvocationSupport support) {
        this.support = support;
    }

    @Override
    protected RemoteInvocationResult doExecuteRequest(HttpInvokerClientConfiguration config, ByteArrayOutputStream baos) throws IOException, ClassNotFoundException {
        try {
            Thread.sleep(100);
        } catch (Exception e) {
            //
        }
        HttpURLConnection con = null;

        List<String> urlList = support.getUrlList(config.getServiceUrl());
        for (int i = 0; i < urlList.size(); i++) {
            String url = urlList.get(i);
            con = openConnection(url);
            try {
                prepareConnection(con, baos.size());
                writeRequestBody(config, con, baos);
                if (i > 0) {
                    support.updateUrlPriority(url);
                }
                break;
            } catch (IOException e) {
                List list = ExceptionUtils.getThrowableList(e);
                boolean isConnectException = false;
                for (Object throwable : list) {
                    if (throwable instanceof ConnectException) {
                        logger.info("Invocation of " + url + " failed: " + throwable);
                        isConnectException = true;
                        break;
                    }
                }
                if (isConnectException) {
                    if (i < urlList.size() - 1) {
                        logger.info("Trying to invoke the next available URL");
                        continue;
{'fraction_non_alphanumeric': 0.08439396906207167, 'fraction_numerical': 0.0033287644409633835, 'mean_word_length': 2.3363814500326585, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7155694', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1230, 'n_words': 306}