Tag: dropwizard

如何在dropwizard上使用guice自动连接HibernateBundle?

我试图用guice / dropwizard配置hibernatebundle并需要帮助。 我使用hubspot / dropwizard-guice / 0.7.0第三方库以及dropwizard lib。 下面的代码显然不会工作,需要帮​​助才能搞清楚。 我如何重写这个,以便hibernatebundle和最终的会话工厂自动注入任何需要它的bean。 MyApplication.java public class MyApplication extends Application { private final HibernateBundle hibernateBundle = new HibernateBundle(MyModel.class) { @Override public DataSourceFactory getDataSourceFactory(MyAppConfiguration configuration) { return configuration.getDataSourceFactory(); } }; @Override public void initialize(Bootstrap bootstrap) { bootstrap.addBundle(hibernateBundle); // ??? bootstrap.addBundle( GuiceBundle.newBuilder() .addModule(new MyAppModule()) .enableAutoConfig(getClass().getPackage().getName()) .setConfigClass(MyAppConfiguration.class) .build() ); } } […]

当前没有会话绑定到执行上下文

当我使用session.getCurrentSession()时,我得到了以下exception。 我已经提到了 hibernate.current_session_context_class: managed org.hibernate.HibernateException: No session currently bound to execution context at org.hibernate.context.internal.ManagedSessionContext.currentSession(ManagedSessionContext.java:75) at org.hibernate.internal.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:1014) at io.dropwizard.hibernate.AbstractDAO.currentSession(AbstractDAO.java:36) at io.dropwizard.hibernate.AbstractDAO.persist(AbstractDAO.java:149) 我用它与dropwizard。 任何人都可以帮我解决这个问题吗?

Dropwizard热部署

我正在寻找一个简单易用的Java系统,它为我创建了一个REST服务。 所以我找到了dropwizard,但据我可以使用谷歌,它发现它缺乏热部署,虽然docker能够这样做。 使用maven-shade-plugin时,至少需要10秒才能构建。 此外,我的IDE报告说,当涉及shade-plugin时,它无法使用编译保存function(也就是热部署)。 我能以某种方式使用hotdeployment吗? 或者我可以使用什么呢? 更新 :如果没有什么可以解决这个问题,我可能会使用泽西和guice等的组合,这在本文中有所解释

将Apache Shiro Security Library与基于Dropwizard的JAX-RS应用程序集成

我想改变Dropwizard以支持Shiro。 我已经阅读了文档并且很少有人感到困惑。 我想将Shiro与表单登录身份validation和Apache Shiro Annotations结合使用。 我认为我需要使用Jersey Filters来支持Shiro。 这是支持泽西的Shiro注释而不是经典的Shiro Filter方法的正确方法吗? 由于Jersey Filters可以很好地访问带注释的资源,因此对我来说使用注释似乎是完美的。 我宁愿不使用AOP方法,与JAX-RS作为独立模块进行动态集成可能真的很棒。

当CompleteableFuture抛出exception时返回500内部错误

我有一个具有端点的rest控制器: @GET @Path(“/reindex-record”) public String reindexRecord(@QueryParam(“id”) String id) { if (StringUtils.isEmpty(id)) { CompletableFuture.runAsync( () -> runWithException(Reindexer::reindexAll)); } else { CompletableFuture.runAsync(() -> runWithException( () -> Reindexer.reindexOne(id))); } // return “ok” or throw WebApplciationException from runWithException method below } 这里是我的包装器方法 – 两个方法 – reindexAll和reindexOne抛出已检查的exception,因此决定使用包装器方法和接口: public interface RunnableWithException { void run() throws Exception; } private void runWithException(RunnableWithException task) […]

使用jackson将json反序列化为java – 特殊字符问题

我使用jackson(泽西和docker)作为我的REST网络服务 – 一切进展顺利。 但是我要求在json post请求中的一个名称值对中包含一个特殊字符。 即json请求(在post正文中) – { “id”: “1”, “print-color” : “red” } //“print-color”中的“ – ”给出了问题。 现在在我对应的这个对象Item.java类的java bean中,我不能创建一个名为print-color的属性(因为不允许使用“ – ”)。 如何在映射中处理它? 谢谢。

@Context注入无效在Jersey ContainerRequestFilter(Dropwizard)

@Context注入适用于类,但不能使它与Objects一起使用。 ContainerRequestFilter中的httpServletRequest生成空指针。 Dropwizard版本: – 1.1.0 ContainerRequestFilter 公共类ApplicationIPAuthFilter实现ContainerRequestFilter {private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationIPAuthFilter.class); 私人HerculesRestAccessor restAccessor; private String applicationName; @Context private HttpServletRequest httpServletRequest; public ApplicationIPAuthFilter(){} public ApplicationIPAuthFilter(HerculesRestAccessor accessor,String applicationName){restAccessor = accessor; this.applicationName = applicationName; } @Override public void filter(ContainerRequestContext requestContext)throws IOException {//需要remote Ip String remoteIp = this.httpServletRequest.getRemoteAddr(); ….}} DynamicFeature @Provider 公共类ApplicationIPAuthFeature实现DynamicFeature { 私人决赛HerculesRestAccessor访问者; private final […]

如何使用带有dropwizard的自定义validation器?

我有一个由其他人编写的REST api,其中处理对特定url的请求的方法接受从路径参数填充的一堆参数。 @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) { // Code to do stuff and return a response } 写这篇文章的人使用了DropWizard,我以前没有使用它的经验。 我的任务是通过将studentId字段与db中的值进行比较来validationstudentId字段。 这将非常简单,但我被告知要使用自定义validation器。 我对编写注释很新,但经过多次挖掘写了这样的注释, @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) @Documented @Constraint(validatedBy = StudentIdValidator.StudentIdValidation.class) public @interface StudentIdValidator { String message() default “{Invalid Id}”; Class[] groups() default {}; Class[] […]

Swagger 1.5不显示我的1.2的@Api描述?

我最近将一个项目从Swagger API 1.2升级到2.0(或者用Swagger核心术语,从1.3升级到1.5)。 由于他们出色的移民指南 ,我设法在很短的时间内完成了这项工作,几乎没有任何障碍。 唯一困扰我的是缺乏对@Api注释的description值的支持。 端点被精心记录 – 包括顶级API端点 – 但它们的描述不再在UI中显示: 请注意,缺少某些东西? 一些研究(意思是,阅读源代码)产生了相同的description现在已经过时,为更@Tag注释@Tag 。 但是我找不到有关如何应用它们的信息,因此描述仍然存在于每个端点类中。 使用Dropwizard,有没有办法以编程方式在Swagger 1.5中实现这一点?

如何使用自定义Dropwizardfilter可选地保护资源

我正在使用Dropwizard 0.9.2,我想创建一个不需要GET身份validation的资源,并且需要对POST进行基本身份validation。 我努力了 @Path(“/protectedPing”) @Produces(MediaType.TEXT_PLAIN) public class ProtectedPing { @GET public String everybody() { return “pingpong”; } @PermitAll @POST public String authenticated(){ return “secret pingpong”; } 同 CachingAuthenticator ca = new CachingAuthenticator(environment.metrics(), ldapAuthenticator, cbSpec); AdminAuthorizer authorizer = new AdminAuthorizer(); BasicCredentialAuthFilter bcaf = new BasicCredentialAuthFilter.Builder().setAuthenticator(ca).setRealm(“test-oauth”).setAuthorizer(authorizer).buildAuthFilter(); environment.jersey().register(bcaf); environment.jersey().register(RolesAllowedDynamicFeature.class); environment.jersey().register(new AuthValueFactoryProvider.Binder(User.class)); environment.jersey().register(new ProtectedPing()); 这似乎导致所有要求“/ protectedPing”的请求需要基本身份validation。 在Dropwizard 0.9.2中,文档说如果我有一个可选的受保护资源,则创建一个自定义filter。 我假设我需要这样做,但我不知道从哪里开始,或者我是否真的需要做什么。