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

The following examples show how to use java.net.URLConnection#getRequestProperty() . 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: RequestPropertyValues.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
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
Source File: RequestPropertyValues.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
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 File: Headers.java    From cxf with 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);
    }
}