question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bind a resource programatically

See original GitHub issue

Trying to bind a programatically created resource results in this error

WARN [2021-01-13 03:13:22,564] org.glassfish.jersey.internal.inject.Providers: A provider org.glassfish.jersey.server.model.Resource registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider org.glassfish.jersey.server.model.Resource will be ignored.

val resource = Resource.builder(uriPath.removeSuffix("/")).apply {
	addMethod(HttpMethod.GET)
		.consumes(MediaType.WILDCARD)
		.produces(MediaType.TEXT_HTML)
		.handledBy { return@handledBy configuredIndex }
}
.build()
environment.jersey().register(resource)

Is it possible to register a resource programatically?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
zUniQueXcommented, Feb 11, 2022

I should have stated this more clearly. Dropwizard provides access to the underlying Jersey container and my provided code snippet registeres a programmatically created resource. I just meant, that we wouldn’t use this issue as a placeholder for an outstanding doc update.

So if your question is answered, please feel free to close this.

1reaction
zUniQueXcommented, Nov 23, 2021

According to the Jersey documentation, this can be done with the registerResources(...) method.

A minimal example in Dropwizard would then look like this:

Resource.Builder builder = new Resource.builder("/");
builder.addMethod(HttpMethod.GET).handledBy(cRC -> "Hello World!");
environment.jersey().getResourceConfig().registerResources(builder.build());
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to bind button Content to Dynamic Resource ...
I am trying to bind programmatically the Content property of my WPF Button to a Dynamic Resource (Business Object) I have previously defined ......
Read more >
Programmatically bind to a StaticResource - MSDN - Microsoft
ColorPreview is a rectangle BrushName is a string that is the key to a StaticResource. Valid Approach but not Programmatic
Read more >
Resource Binding | DotVVM Documentation
The resource binding is used to access resources and constants, or to evaluate any expression on the server. Consider the following markup:
Read more >
Invisible reCAPTCHA - Google Developers
Programmatically bind the challenge to a button or invoke the challenge. Programmatically invoke the challenge. Configuration. JavaScript resource (api.js) ...
Read more >
Resources - The complete WPF tutorial
A DynamicResource on the other hand, is resolved once it's actually needed, and then again if the resource changes. Think of it as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found