Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HttpURLConnection: Invalid HTTP method PATCH

User_YB3RXJul 18 2018 — edited Jul 18 2018

Hi,

I am working on one ADF application(Using Jdeveloper 11.1.1.7.0, JDK 1.7.0.80), where I am calling one REST API patch operation using HttpURLConnection . I got to know that HttpURLConnection does not support PATCH operation. I tried some solutions found on some forums and finally one solution worked in my application.

Solution:

    /**

     * This method is used to allows PATCH operation for HttpURLConnection class

     * @param methods is a method name

     */

    public void allowMethods(String methods) {

        try {

            Field methodsField =

                HttpURLConnection.class.getDeclaredField("methods");

            Field modifiersField = Field.class.getDeclaredField("modifiers");

            modifiersField.setAccessible(true);

            modifiersField.setInt(methodsField,

                                  methodsField.getModifiers() & ~Modifier.FINAL);

            methodsField.setAccessible(true);

            String[] oldMethods = (String[])methodsField.get(null);

            Set<String> methodsSet =

                new LinkedHashSet<>(Arrays.asList(oldMethods));

            methodsSet.addAll(Arrays.asList(methods));

            String[] newMethods = methodsSet.toArray(new String[0]);

            methodsField.set(null, /*static field*/newMethods);

        } catch (NoSuchFieldException | IllegalAccessException e) {

            throw new IllegalStateException(e);

        }

    }

The above solution  is using reflection method and add the 'PATCH' to the HttpURLConnection methods. This solution is working fine, however foritfy security tool  is reporting the issue for the method setAccessible(). Can we use setAccessible() method on production? I mean can we use the  above workaround on production environment ? Is there any issue if we deploy the application with this workaround on production?

Can anyone please suggest me on this.

Thanks,

Kratika

Comments

3047598
Answer

Hi,

For the purpose of completion:

X5-2 machines support USB 2.0 compliant devices, that support a maximum power draw of 500mA.

All USB 2.0 compliant devices support this specification. Due to layout design, the front USB ports are more sensitive to this overdraw.

We may plug the HDD to the rear ports or

use a Y cable, enabling the HDD to draw power from both the USB ports.

There is a Bug 23092904 raised for this and it not being fixed, as the device is not strictly USB 2.0 compliant.

Warm Regards,

balaji R

Marked as Answer by DK kanta · Sep 27 2020
1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Aug 15 2018
Added on Jul 18 2018
0 comments
9,476 views