by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 20:19
    moromindful commented #1808
  • 20:17
    moromindful commented #1808
  • 20:16
    moromindful commented #1808
  • 17:30
    moromindful commented #1808
  • Jul 03 16:54

    jknack on 2.x

    Add import of OpenAPIModule onl… Merge pull request #1836 from e… (compare)

  • Jul 03 16:54
    jknack closed #1836
  • Jul 03 16:54
    jknack milestoned #1836
  • Jul 03 16:54
    jknack labeled #1836
  • Jul 03 16:54
    jknack labeled #1836
  • Jul 03 14:38
    extbe opened #1836
  • Jul 03 12:58
    walkman90 commented #1835
  • Jul 03 12:45
    jknack commented #1835
  • Jul 03 12:41
    jknack commented #1835
  • Jul 03 12:30
    walkman90 opened #1835
  • Jul 03 12:29

    dependabot-preview[bot] on maven

    (compare)

  • Jul 03 12:28

    jknack on 2.x

    build(deps): bump ebean.version… Merge pull request #1833 from j… (compare)

  • Jul 03 12:28
    jknack closed #1833
  • Jul 03 12:28

    dependabot-preview[bot] on maven

    (compare)

  • Jul 03 12:28

    jknack on 2.x

    build(deps): bump jmespath-java… Merge pull request #1834 from j… (compare)

  • Jul 03 12:28
    jknack closed #1834
Hashim Sayyid
@Sayyiditow

my guess (but not sure) the issue is with the csrfhandler

@jknack I am passing the csrf. It works fine if i remove the file input and use a text input. But I'll let you look into it. Thanks!

Marcel Stör
@marcelstoer
Q3. what was env.router().err { request, response, error -> replaced with? We use that to extend the standard error handling. I know about app.router.error { ctx, cause, code -> } but I didn't find an equivalent for request, response.
Marcel Stör
@marcelstoer
Q4. use(Jackson().doWith { it.registerModule(KotlinModule()) }) is replaced by 2 lines as the module instance has to be bound to the services, correct?
    services.put(KotlinModule::class.java, KotlinModule())
    install(JacksonModule().module(KotlinModule::class.java))
Marcel Stör
@marcelstoer

Q3. wh

Ok, it appears all properties previously available on request, response are now shared on ctx.

Hashim Sayyid
@Sayyiditow

If you are trying to extend error handling, I have used it like this to show custom error pages:

error(NOT_FOUND, (ctx, cause, code) -> ctx.render(new ModelAndView("404.ftl")));

This is of course in the main class that extends Jooby.

You can replace "NOT_FOUND" with other StatusCode like "FORBIDDEN"
Marcel Stör
@marcelstoer
Yes, but we have a general error handler (hence, router.error) and I was wondering how to get access to the error/exception. The error in the old env.router().err { request, response, error -> is of type org.jooby.Err that became io.jooby.StatusCodeException. However, I don't see ctx or anything else giving me access to it.
Marcel Stör
@marcelstoer
Q5. What is the 2.x way of saying response.send(Results.json(myContent).status(myStatus)) (that's inside app.router.error)? Is it something like this:
ctx.responseCode = myStatus
ctx.responseType = MediaType.json
ctx.send(ctx.require(ObjectMapper::class.java).writeValueAsString(myContent))
Marcel Stör
@marcelstoer
Q6. There is no equivalent to environment-based feature toggles (on("environment")) in 2.x? Other than using if (environment.isActive("environment")).
Edgar Espina
@jknack
@marcelstoer
Q3. Hasim is right. It is: error((ctx, cause, code) -> {….}). Request and Response are merged into Context in 2.x. wrapper exception: org.jooby.Err is gone. Instead you have cause (original error) and code suggested status code
Q4. Jackson:
ObjectMapper mapper = JsonMapper.builder()
        .addModule(new ParameterNamesModule())
        .addModule(new Jdk8Module())
        .addModule(new JavaTimeModule())
        .addModule(new AfterburnerModule())
        .addModule(new KotlinModule())
        .build();

install(new Jackson(mapper));
Q5. ctx.setResponseType(JSON).setResponseCode(statusCode).send(myContent);
Edgar Espina
@jknack
Q6. Environment callbacks are gone. 2.x simplifies the configuration and enviroment access, so it is available at construction/init time (not at startup time like in 1.x). This simplifies everything and makes env callbacks useless:
{
   Environment env  = getEnvironment();
  if (env.isActice(“…”)) {
     // .. do something
  }
}
same for Config, you can check/test any property
Marcel Stör
@marcelstoer
Q4. I would argue that my example is probably more idomatic Jooby as all but the Kotlin Jackson module are part of the default object mapper you create in io.jooby.json.JacksonModule#create. The effect is the same, though.
Q5. I don't see how your example would work. I don't see a Context#send()implementation that accepts a generic type, only bytes, streams, etc. and string. Hence, I used Jackson to serialize my object first. I'm puzzled.
Q6. I'm using env.isActice("…") to guard calls against install to avoid installing extensions I don't need.
Edgar Espina
@jknack
Q5. Yea, so do ctx.render
Marcel Stör
@marcelstoer
Yep, that makes more sense.
Do you have any plans to migrate the metrics extension to 2.x?
Edgar Espina
@jknack
no plan yet
which metrics module exactly?
Marcel Stör
@marcelstoer
Marcel Stör
@marcelstoer

I'm slowly getting to terms with Jooby 2.x in my migration efforts :-/ DI is a bit of a mystery still but I want to preserve much of the Guice-based code I have.

I know I can/should migrate this

override fun configure(env: Env, conf: Config, binder: Binder) {
    binder.bind(Some::class.java).toInstance(Some())

to

override fun install(app: Jooby) {
    app.services.put(Some::class.java, Some())

However, what about classes that require Guice constructor injection and can thus not be instantiated directly and registered as a service? Example:

binder.bind(Some::class.java).`in`(Scopes.SINGLETON)
binder.bind(MyInterface::class.java).to(Some::class.java)
...
class Some @Inject constructor(foo: Foo) : MyInterface {

And what about invocations to the Guice multibinder while configuring/installing an extension? Current example: Multibinder.newSetBinder(binder, TransactionListener::class.java).addBinding().toInstance(MyTransactionLogger())

Edgar Espina
@jknack
@marcelstoer look at the guice example/doc: https://jooby.io/#dependency-injection-guice
You can do something like:
install(new GuiceModule(new MyGuiceModule(this)));
then MyGuiceModule will be something like:
import com.google.inject.AbstractModule;

class MyGuiceModule extends AbstractModule {
    private Jooby app;
    public MyGuiceModule(Jooby app) {
     this.app = app;
   }

  @Override
          protected void configure() {
              bind(Some::class.java).in(Scopes.SINGLETON);
          }
}
So if your module is already Guice friendly, I suggest you to extends AbstractModule (or implements Guice module) which give you access to the Binder already
No need to migrate them as Jooby Extension
cool?
Edgar Espina
@jknack
Hashim Sayyid
@Sayyiditow
Did 2.8.8 break the "ERR_TOO_MANY_REDIRECTS" issue that was fixed last time? After logging out, the app is now back to "ERR_TOO_MANY_REDIRECTS" whenever you visit any page. The issue in reference is #1737.
@jknack
Seems to be broken now, pac4j module doesnt work as expected. if you remove the pac4j module, the app is accessible, the moment you install the pac4j module, everything breaks with "ERR_TOO_MANY_REDIRECTS" on the web page.
Hashim Sayyid
@Sayyiditow
This could have been broken from 2.8.6 though, as I have jumped from 2.8.5 to 2.8.8. I will test 2.8.6 and 2.8.7.
2.8.6 is fine. The break happened on version 2.8.7 which was inherited to 2.8.8. I can't seem to see what changed in pac4j module on 2.8.7.
I'll open an issue.
LongkerDandy
@longkerdandy
Hi, I have a question about Cors, when using CorsHandler with MvcHandler, I added @Consumes(MediaType.JSON) to the mvc class, the Cors preflight request will result UnsupportedMediaType exception because the preflight request has null media type.
Right now I have to comment out the @Consumes annotation
Edgar Espina
@jknack
@longkerdandy can you file at github? Please add an example
Hashim Sayyid
@Sayyiditow
@jknack hi, for the "ERR_TOO_MANY_REDIRECTS" issue. I am not sure how to explain what is causing it. The moment I remove the line:
install(new Pac4jModule().client("/dashboard*", config -> new FormClient("/login", userAuthenticatorService)));
The app works, but if I install the module, the error comes back. Is it the redirect sending to the /login page which is causing this? The issue does not seem to be related with the sessionStore or csrfHandler as with/without them, the error still persists.
Yeah, I think there are too many redirects the the loginUrl (/login) which is related to the FormClient. When visiting any url, it tries to redirect to /login for some reason.
Edgar Espina
@jknack
williamjtodd
@williamjtodd
Hi, I feel like I'm missing something. I can't find docs for Mongo in V2? Is there no module in v2?
Edgar Espina
@jknack
Yea, there is no mongo module for v2
williamjtodd
@williamjtodd
Thanks. I have another question now:
I've created an extension for Mongo.
I'm not clear on how to do this, from any class or location I need it:
datastore = require(Datastore::class)
Is it possible, or only from an "App" that extends Kooby?