dropwizard

dropwizard: produce both html and json from the same class

邮差的信 提交于 2019-12-23 01:17:52
问题 Is there a way to control the output format from the client side? I have a class which @Produces(MediaType.TEXT_HTML) and I want it to produce json when the client requests. I can copy the class verbatim, replacing only the @Path and @Produces annotations, but this looks like a total waste. I wonder if the client could append something like &content-type=application/json to the URL and have my server respond with json instead of html? 回答1: You'll need to annotate the resources as providing

dropwizard: produce both html and json from the same class

泄露秘密 提交于 2019-12-23 01:17:12
问题 Is there a way to control the output format from the client side? I have a class which @Produces(MediaType.TEXT_HTML) and I want it to produce json when the client requests. I can copy the class verbatim, replacing only the @Path and @Produces annotations, but this looks like a total waste. I wonder if the client could append something like &content-type=application/json to the URL and have my server respond with json instead of html? 回答1: You'll need to annotate the resources as providing

How to create and get started with Embedded Apache Derby database in Dropwizard project (Angular 7 front-end)

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-22 16:45:02
问题 I'm reading through Derby documentation and following all the instructions. I've successfully installed it (extracted it to my Linux machine and set the DERBY_HOME path). I have a complete REST API project with Angular 7 front-end and Dropwizard backend. I hard coded some data in the backend, and created all the HTTP API methods I need (GET, POST, PATCH, DELETE). The application is fully functional, but now I need to implement the Embedded version of Derby into it. I have 0 experience with

Dropwizard: BasicAuth

允我心安 提交于 2019-12-21 04:42:24
问题 Using Dropwizard Authentication 0.9.0-SNAPSHOT I want to check the credentials against database user (UserDAO). I get the following exception ! org.hibernate.HibernateException: No session currently bound to execution context How to bind the session to the Authenticator? Or are there better ways to check against the database user? The Authenticator Class package com.example.helloworld.auth; import com.example.helloworld.core.User; import com.example.helloworld.db.UserDAO; import com.google

Elements passed through a form not received by the server nor displayed on the front. PATCH method | Angular | Dropwizard

穿精又带淫゛_ 提交于 2019-12-19 11:51:23
问题 Server side shows that the PATCH method is called and adds a null at the end of the array, instead of a new Item array with the Name and Price taken from user input. PATCH method in the service component: patchAdd(menu: MenuModel | number, itemToAdd: ItemClass): Observable<any> { const id = typeof menu === 'number' ? menu: menu.id; const url = `${this.menusUrl}/add/${id}`; return this.http.patch(url, itemToAdd, httpOptions).pipe () } patchItAdd function which implements the patchAdd method

How to Update an Entity from a Thread in Dropwizard, Hibernate

耗尽温柔 提交于 2019-12-19 11:28:06
问题 I have a thread that waits until a process is complete and then needs to update an entity. But I get Exception in thread "Thread-22" org.hibernate.HibernateException: No session currently bound to execution context I have tried opening a new session (see the code below). Session management is normally handled by @UnitOfWork, but this annotation seems to apply only to resources. public class ConfigDAO extends AbstractDAO<Config> { private final SessionFactory sessionFactory; public ConfigDAO

How do I use a custom validator with dropwizard?

混江龙づ霸主 提交于 2019-12-19 04:52:27
问题 I have a REST api written by someone else in which the method that handles the request to a particular url accepts a bunch of parameters that are populated from path parameters. @POST @Path("/{classid}/{studentid}/details") @Consumes(MediaType.MULTIPART_FORM_DATA) @SuppressWarnings("unchecked") public Response processFile(@FormDataParam("sourceFile") InputStream aStream, @PathParam("classid") String classId, @PathParam("studentid") String studentId, @Context HttpServletRequest httpRequest) {

How to maintain user sessions in DropWizard?

血红的双手。 提交于 2019-12-19 00:19:29
问题 I am looking for a persistent session manager which saves the session on file system (like PHP) that can be used with DropWizard. I see there is one Environment.getSessionHandler() , but I see no documentation on it. I could write my own but I am hoping for a cooked meal. Will the above SessionHandler is what I am looking for? And how to use that? 回答1: With dropwizard>0.7 environment.jersey().register(HttpSessionProvider.class); environment.servlets().setSessionHandler(new SessionHandler());

Restricting dropwizard admin page

只谈情不闲聊 提交于 2019-12-18 13:16:45
问题 How to authenticate Dropwizard admin portal, so as to restrict normal users from accessing it? Please help 回答1: In your config, you can set adminUsername and adminPassword under http like so: http: adminUsername: user1234 adminPassword: pass5678 回答2: For DW 0.7 my approach would be: public class AdminConstraintSecurityHandler extends ConstraintSecurityHandler { private static final String ADMIN_ROLE = "admin"; public AdminConstraintSecurityHandler(final String userName, final String password)

Custom Method Annotation using Jersey's AbstractHttpContextInjectable not Working

*爱你&永不变心* 提交于 2019-12-17 22:37:27
问题 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