Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    ruslan
    @unoexperto
    Folks, how do I build Javalin ? mvn install -Dmaven.test.skip -DskipTests gives me following error:
    [ERROR] Failed to execute goal on project javalin-openapi: Could not resolve dependencies for project io.javalin:javalin-openapi:jar:4.2.1-SNAPSHOT: Failure to find io.javalin:javalin:jar:tests:4.2.1-SNAPSHOT in https://oss.sonatype.org/content/repositories/snapshots was cached in the local repository, resolution will not be reattempted until the update interval of sonatype-nexus-snapshots has elapsed or updates are forced -> [Help 1]
    A. Bos
    @adhesivee

    Hi all, I am trying to use OpenAPI DSL, but running into an issue.
    I have this Kotlin model:

    class Hal<T>(
        @JsonProperty("_links") val links: Map<String, HalLink>?,
        @JsonUnwrapped val entity: T
    )

    And I try to document it:

    document()
        .result("200", oneOf(
            documentedContent<User>("application/json", false),
            documentedContent<Hal<User>>("application/hal+json", false)
        ))

    Two things are not happening:

    1. JsonUnwrapped is not detected properly, /swagger-docs still shows that property entity exists which should not be there.
    2. Generic in Hal<User> is not detected, and not exposed to /swagger-docs at all. This can be worked around with creating a specific UserHal class that inherits Hal<User> then properties show. But it would safe a lot of boilerplating if it could be done inline
    t101
    @t101
    Hi. I've been trying to update the version of Javalin I've been using and I'm having some issues with the validators (probably just being dumb)
    here is an example:
    //in MyObjectController.java
    MyObject object = ctx.bodyValidator(MyObject.class)
        .check(o -> o.isValid()) //issue is on this line, "cannot resolve method 'isValid'"
        .get();
    //in MyObject.java
    public boolean isValid() {
        return true;
    }
    t101
    @t101
    okay wait a sec - downgrading to the older version is resulting in the same error. I must be doing something dumb. Please disregard.
    t101
    @t101

    Okay, figured it out. Javalin 3.13.12 uses kotlin:1.3.71:* and that had a reported vulnerability, I added in dependency management stuff to use kotlin:1.6.10:* and that's what's causing the issue above.

    (updating to javalin 4.3.0 also results in the above error, and it looks like it's using kotlin:1.5.something)

    uhmm... the code still compiles and seems to work but I'm nervous about that.
    David (javalin.io)
    @tipsy
    The validators should be pretty well tested
    t101
    @t101
    This seems to be caused by something between kotlin:1.3.x -> kotlin:1.5.x (which is to say, also between javalin 3.13.12 -> 4.3.0 )
    the vulnerability I was trying to fix is reported from org.jetbrains.kotlin:* before 1.4.21 (https://nvd.nist.gov/vuln/detail/CVE-2020-29582) so I guess I could uhm...
    t101
    @t101
    I dunno, everything seems to still work fine? ...maybe i need to update my IDE or something
    Paul Harris
    @rolfyone
    anyone parsed complex content types with the framework or jetty somehow? like if someone passes in Accept: application/octet-stream,application/json;q=0.9 etc...
    David (javalin.io)
    @tipsy
    @rolfyone seems it's just comma separated?
    Paul Harris
    @rolfyone
    comma separated with quality
    so according to RFC each field may have qualtiy
    eg. application/octet-stream;q=0.1,application-json;q=0.9 should result in prefering json :/
    because the q is 0-1, and it'd be too simple to specify what you ideally want first apparently
    David (javalin.io)
    @tipsy
    aha
    but that still seems simple enough to parse?
    Paul Harris
    @rolfyone
    simple-ish, just applying preferences is pretty annoying
    ended up using a library to do it
    not a lot of code but better tested than i'd probably have done
    org.commonjava.mimeparse:mimeparse:0.1.3.3
    David (javalin.io)
    @tipsy
    nice
    although that versioning is suspect
    Paul Harris
    @rolfyone
    it's ancient - 2013, not really maintained
    but its 1 file with tests so worst case could take it on under MIT (for my project at least)
    Paul Harris
    @rolfyone
    it could be extended to return the weighted list i guess, rather than just best match, but it gets me out of my current hole :)
    Mihael Koep
    @miq
    hi, when using javaling-without-jetty, how can I serve static resources?
    i do not find something like addStaticFiles when using Javalin.createStandalone...
    David (javalin.io)
    @tipsy
    You cannot, that is a Jetty feature, not a servlet feature
    Mihael Koep
    @miq
    ok, thanks, I managed to implement a WebServlet to accomplish serving files from the WAR-file
    David (javalin.io)
    @tipsy
    Paul Tomlin
    @ptomli
    Hi all. Is anyone aware if Javalin (on Jetty) supports Transfer-Encoding: chunked for responses, particularly in a situation where one is trying to issue multiple flushs on the response body? My reading of the JavalinServlet and JavalinResponseWrapper would suggest that this is not a supported model, though my Kotlin-fu is weak, and it might be somehow handled by ctx.future
    David (javalin.io)
    @tipsy
    @ptomli it's not handled by ctx.future - you can write directly to ctx.res.outputStream if you want
    nexthorMoreno
    @nexthorMoreno
    Hi, please, do we have a possibility to make Javalin work with JSONObject or at least create something to convert from JSONObject to JsonNode?.
    Thank you!.
    David (javalin.io)
    @tipsy
    @nexthorMoreno javalin doesn't really have any opinion on how you do json, there is a JsonMapper interface you can implement, but that's it
    1 reply
    nexthorMoreno
    @nexthorMoreno

    Hi, please. There are some possibilities to call from one handler to another handler and get the ctx.result object inside the first one handler to finally response the merge of two answers?:

    Here what Im trying to do:

    public void start() {
    create(config -> {
                config.defaultContentType = "application/json";
                config.enableDevLogging();
                config.registerPlugin(new RouteOverviewPlugin("/overview"));
                config.requestLogger((ctx, execTime) -> {
                    LOGGER.debug("[{}] {} - {} ms.", ctx.fullUrl(), ctx.userAgent(), execTime);
                });
            }).start(apiPort).
                get("/hello2/{name}", ctx -> this.handleHello2(ctx, ctx.pathParam("name"), rawSchema.toString())).
                    get("/hello3/{tons}", ctx -> this.handleHello3(ctx, ctx.pathParam("tons")));
        }
        private void handleHello2(final Context ctx, final String name, final String rawSchema) throws IOException {
            String handleHello3Message = "";
            handleHello3(ctx, "TONS");  //how to get ctx.result from handleHello3???
            buildResponse(ctx, HttpCode.OK, rawSchema + " \n RESPONSE_2: " + handleHello3Message);
        }
        private void handleHello3(final Context ctx, final String name) {
            buildResponse(ctx, HttpCode.OK, "{\"yes\": \"It worked fine!!. \"}");
        }
        protected static Object buildResponse(Context ctx, HttpCode status, String data) {
            return ctx
                    .status(status)
                    .result(data);
        }
    David (javalin.io)
    @tipsy
    //how to get ctx.result from handleHello3???
    ctx.resultString()
    7 replies
    but..
    you are trying to do something very strange
    so i would look for a different way
    David (javalin.io)
    @tipsy
    Mihael Berčič
    @MihaelBercic
    Hello, It's me again!
    I was wondering if there is anything regarding JWT in Javalin now?
    I remember in 2018 it was not yet included
    Mihael Berčič
    @MihaelBercic
    Or what would you suggest for an authentication
    David (javalin.io)
    @tipsy
    David (javalin.io)
    @tipsy
    Bernard Crnković
    @macabrus
    Screenshot 2022-07-12 at 14.09.30.png
    Can anyone help me with this problem in swagger dependencies of javalin bundle
    Unresolved dependency: 'com.github.java-json-tools.jackson-coreutils:jackson-coreutils:jar:2.0'
    Unresolved dependency: 'com.github.java-json-tools.jackson-coreutils:jackson-coreutils-equivalence:jar:2.0'
    I tried adding https://oss.sonatype.org/content/repositories/releases to pom.xml repositories but that didn't work