For the love of false, Jersey client edition!


  • Discourse touched me in a no-no place

    Dear god, I wrote this today. It's so wrong, but the Jersey WADL→client generator is just so broken when you need a multi-element path. All I wanted was to get that false passed to buildFromMap to turn off the quoting engine for a specific call, but this was the only way to inject the change that I could think of, and required doing great violence to the privacy of fields just so that the steaming pile of code that uses it wouldn't choke.

    // This is so AWFUL! This is all just so that we can force the path to be
    // built without encoding the slashes in it.
    private void hackTheUB(Object path) throws IllegalAccessException,
            NoSuchFieldException {
        class HackedUriBuilder extends JerseyUriBuilder {
            @Override
            public URI buildFromMap(Map<String, ?> values) {
                return buildFromMap(values, false);
            }
    
            @Override
            public JerseyUriBuilder clone() {
                HackedUriBuilder ub = new HackedUriBuilder();
                try {
                    ub.copyFields(this);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("failed to clone UriBuilder", e);
                }
                return ub;
            }
    
            void copyFields(JerseyUriBuilder source)
                    throws IllegalAccessException {
                for (Field field : JerseyUriBuilder.class.getDeclaredFields()) {
                    field.setAccessible(true);
                    field.set(this, field.get(source));
                }
            }
        }
        HackedUriBuilder ub = new HackedUriBuilder();
        Field uriBuilderField = path.getClass().getDeclaredField("_uriBuilder");
        uriBuilderField.setAccessible(true);
        ub.copyFields((JerseyUriBuilder) uriBuilderField.get(path));
        uriBuilderField.set(path, ub);
    }
    

    Fuck you, Java. Fuck you, Jersey. Fuck!


  • Discourse touched me in a no-no place

    And Discourse is TRWTF for fucking up the indentation after cooking. Gaaah!


Log in to reply