dropwizard

Enabling cors in dropwizard not working

跟風遠走 提交于 2019-11-29 02:18:01
问题 I'm working on a dropwizard application and js ui to interacte with the api. I need to load json data to update views but I have to enable cors in dropwizard before that. I did some staff but it seems not working because dropwizard returns allways 204 no content. @Override public void run(final BGConfiguration configuration, final Environment environment) throws Exception { final Map<String, String> params = new HashMap<>(); params.put("Access-Control-Allow-Origin", "/*"); params.put("Access

Overriding server connector config with env variables with dropwizard

梦想的初衷 提交于 2019-11-28 23:19:45
I have posted this question on dw mailing list but didnt get an answer. Can I assume the YML format below doesnt work for DW 0.7.0 anymore? (The use of @ char to insert env var) server: applicationConnectors: - type: http bindHost: @OPENSHIFT_DIY_IP@ port: @OPENSHIFT_DIY_PORT@ Error: Malformed YAML at line: 28, column: 17; while scanning for the next token; found character @ '@' that cannot start any token. (Do not use @ for indentation); in 'reader', line 28, column 17: bindHost: @OPENSHIFT_DIY_IP@ So I decided to use this format: server: type: simple applicationContextPath: /

SIGTERM not received by java process using 'docker stop' and the official java image

血红的双手。 提交于 2019-11-28 20:06:31
问题 I am running a dropwizard Java application in a Docker container using the image java:7u79 based on debian/jessie . My Java application handles the SIGTERM signal to shutdown gracefully. The SIGTERM handling works perfect when I run the application without Docker. When I run it in a Docker container the SIGTERM does not reach the Java application when I issue a docker stop command. It kills the process abruptly after 10 seconds. My Dockerfile : FROM java:7u79 COPY dropwizard-example-1.0.0.jar

Custom Method Annotation using Jersey's AbstractHttpContextInjectable not Working

久未见 提交于 2019-11-28 19:00:22
I want to restrict some methods if they are being accessed in a non-secure manner. I'm creating a @Secure annotation that checks whether or not the request was sent over secure channels. However, I cannot create a method injectable that captures the HttpContext of the request. @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD}) public @interface Secure { } public class SecureProvider<T> implements InjectableProvider<Secure, AbstractResourceMethod> { @Override public ComponentScope getScope() { return ComponentScope.PerRequest; } @Override public Injectable<?>

DropWizard Metrics Meters vs Timers

元气小坏坏 提交于 2019-11-28 15:57:20
问题 I am learning the DropWizard Metrics library (formerly Coda Hale metrics) and I am confused as to when I should be using Meters vs Timers . According to the docs: Meter: A meter measures the rate at which a set of events occur and: Timer: A timer is basically a histogram of the duration of a type of event and a meter of the rate of its occurrence Based on these definitions, I can't discern the difference between these. What's confusing me is that Timer is not used the way I would have

Override DropWizard ConstraintViolation message

倾然丶 夕夏残阳落幕 提交于 2019-11-28 12:23:56
So I want to change the validation messages used to validate a model through a DropWizard resource. I'm using java bean validation annotations. For example here is one of the fields I want to validate: @NotEmpty(message = "Password must not be empty.") I can test this works as expected using a validator. However when I use DropWizard to do the validation on the resource it adds some extra stuff to that message. What I see is this - password Password must not be empty. (was null) and I've found the code that does this here - https://github.com/dropwizard/dropwizard/blob/master/dropwizard

Issue with custom Authorization in DropWizard

拟墨画扇 提交于 2019-11-28 09:24:40
问题 I am trying to add custom authorization in dropwizard but not able to successed. I have a custom authentication added for dropwizard by binding it to authFactory Authenticator ssoAuthenticator = createSSOAuthenticator(configuration.getSsoGrantClientConfiguration()); environment.jersey().register(AuthFactory.binder( new SSOTokenAuthFactory<SSOGrant>( ssoAuthenticator, SYSTEM_PREFIX, SSOGrant.class)) ); and adding a dynamicfeature for authorization environment.jersey().register

Getting object from @PathParam

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 06:38:26
问题 I'm creating a RESTful service for accessing data. So I started writing that service, first I created a ReadOnlyResource interface with the following code: public interface ReadOnlyResource<E, K> { Collection<E> getAll(); E getById(K id); } Where E is the returned type and K is the key element. So if I'm implementing with <Integer, Integer> I'll inject the key like t @GET @Path("/{id}") @Override public Integer getById(@PathParam("id") Integer id) { return null; } But when my key is more

jersey 2 context injection based upon HttpRequest without singleton

╄→гoц情女王★ 提交于 2019-11-28 06:27:03
问题 I want to inject a Datastore for a single request by field, like @Context protected HttpServletRequest request; Currently I have implemented a similar approach to this: Jersey 2.x Custom Injection Annotation With Attributes as follows: @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.PARAMETER, ElementType.FIELD}) public @interface TenantDatastore {} public class TenantDatastoreFactory extends AbstractContainerRequestValueFactory<Datastore> { public TenantDatastoreFactory() {}

Access HttpServletRequest from an Authenticator using Dropwizard

こ雲淡風輕ζ 提交于 2019-11-28 05:39:03
问题 Using DropWizard(Jersey Server), Is it possible to access HttpServletRequest from an Authenticator? I would give it an attribute. I tried with: @Context private HttpServletRequest servletRequest; But it's not injected. I registered my Authenticator using: env.jersey().register( new AuthDynamicFeature(new BasicCredentialAuthFilter.Builder<User>().setAuthenticator(new FooAuthentificator()) .setRealm("Realm").buildAuthFilter())); 回答1: It's possible, but the problem is, the Authenticator never