Java Code Examples for java.net.URLConnection#getRequestProperty()

The following examples show how to use java.net.URLConnection#getRequestProperty() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 2
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 3
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 4
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 5
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 6
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 7
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 8
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 9
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 10
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 11
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 12
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 13
public static void part2() throws Exception {
    URL url = null;
    String[] goodKeys = {"", "$", "key", "Key", " ", "    "};
    String[] goodValues = {"", "$", "value", "Value", " ", "    "};

    URLConnection conn = getConnection(url);

    for (int i = 0; i < goodKeys.length; ++i) {
        for (int j = 0; j < goodValues.length; ++j) {
            // If a property with the key already exists, overwrite its value with the new value
            conn.setRequestProperty(goodKeys[i], goodValues[j]);
            String value = conn.getRequestProperty(goodKeys[i]);

            if (!((goodValues[j] == null && value == null) || (value != null && value.equals(goodValues[j]))))
                throw new RuntimeException("Method setRequestProperty(String,String) works incorrectly");
        }
    }
}
 
Example 14
Source Project: cxf   File: Headers.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * This procedure sets the URLConnection request properties
 * from the PROTOCOL_HEADERS in the message.
 */
private void transferProtocolHeadersToURLConnection(URLConnection connection) {
    boolean addHeaders = MessageUtils.getContextualBoolean(message, ADD_HEADERS_PROPERTY, false);
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        String header = entry.getKey();
        if (HttpHeaderHelper.CONTENT_TYPE.equalsIgnoreCase(header)) {
            continue;
        }

        List<String> headerList = entry.getValue();
        if (addHeaders || HttpHeaderHelper.COOKIE.equalsIgnoreCase(header)) {
            headerList.forEach(s -> connection.addRequestProperty(header, s));
        } else {
            connection.setRequestProperty(header, String.join(",", headerList));
        }
    }
    // make sure we don't add more than one User-Agent header
    if (connection.getRequestProperty("User-Agent") == null) {
        connection.addRequestProperty("User-Agent", USER_AGENT);
    }
}