标签: dropwizard

如何在 Dropwizard 中使用 Jdbi 的 UserResource

我正在建立一个利用 mysql 数据库的 Dropwizard 项目。我从基本开始,使用 Dropwizard 站点本身上的示例代码(可以在此处找到)。但是,我的代码无法编译,因为它无法找到 UserResource 类。

这是我应该从某个地方提取的依赖项吗?我的 pom 引入了 dropwizard-core 和 dropwizard-jdbi3 的 1.3.5 版本。还缺什么吗?或者“UserResource”是我应该实现的资源类的占位符?

java jdbi dropwizard

1
推荐指数
1
解决办法
530
查看次数

如何在DropWizard视图上设置cookie并仍然返回View?

我正在帮助维护我们使用DropWizard的应用程序,这很不错.

我想设置一个cookie,然后仍然返回视图.

我看到人们提到这种方法:

响应r = javax.ws.rs.core.Response.ok().cookie(COOKIE_HERE).entity(view).build();

返回r;

但要使其工作,您必须返回"响应"对象,而不是视图.

反正这样做是否能够返回视图而不是响应?我知道我可以使用HttpServletResponse来设置cookie,但是如果可能的话,我更愿意使用视图或响应对象来避免额外的上下文.

java cookies response dropwizard

0
推荐指数
1
解决办法
3100
查看次数

在检索证书之前,InstallCert.java会崩溃服务器

我有一个在Dropwizard上运行的服务器(即为其Web服务器运行Jetty).我正在尝试为它设置SSL.

我有一个由CA签署的证书(特别是Comodo,通过Namecheap).我安装了根证书和中间证书,然后安装了我自己的证书(使用Comodo支持的说明.但是,当我第一次尝试连接到我的服务器时(它启动正常),我收到一个错误:( sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target当然堆栈跟踪更长,但这是根本原因.)

我已经尝试过搜索这个错误,并且一直有人说这应该只发生在自签名证书上,而我的证书不是.尽管如此,我尝试下载InstallCert.java程序,该程序似乎源自Sun博客上的一篇(现已删除)文章.具体来说,我从这个页面获得了学位.

在几次(失败的)尝试通过命令行使其工作(这是另一次的讨论)后,我最终让它运行正常.现在我从程序得到的输出是:

Loading KeyStore C:\Program Files\Java\jdk1.8.0_05\jre\lib\security\cacerts...
Opening connection to localhost:8443...
Starting SSL handshake...
Exception in thread "main" java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:150)
    at java.net.SocketInputStream.read(SocketInputStream.java:121)
    at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
    at sun.security.ssl.InputRecord.read(InputRecord.java:503)
    at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:954)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1343)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1371)
    at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1355)
    at com.aw.ad.util.InstallCert.main(InstallCert.java:98)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

同时,如果我用我的网站打开窗口,它会再次传递unable to find …

ssl ssl-certificate dropwizard

0
推荐指数
1
解决办法
1425
查看次数

dropwizard-giving-400-error-when-creating-new-resource 使用 POST

public class UserProfileData {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "firstName", nullable = false)
    private String firstName;

    @Column(name = "lastName", nullable = true)
    private String lastName;

    @Column(name = "country", nullable = true)
    private String country;

    public UserProfileData() {
    }

    public UserProfileData(String firstName, String lastName, String country) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.country = country;
    }


    public long getId() {
        return id;
    }


    public void setObjectId(long id) {
        this.id = id;
    }

    @JsonProperty
    public String getFirstName() …
Run Code Online (Sandbox Code Playgroud)

java rest post json dropwizard

0
推荐指数
1
解决办法
5964
查看次数

如何使用dropwizard将响应作为excel文件返回?

我正在将dropwizard用于我的其余api开发,该开发将返回json响应。我现在遇到了一个要求,我必须在调用一个特定api时返回一个excel文件。我发现apache poi是很好的库。但是我该如何返回Excel文件作为响应。然后,浏览器应显示下载选项。

excel response download apache-poi dropwizard

0
推荐指数
1
解决办法
1618
查看次数

将 dropwizard 项目部署到 heroku 时,yaml 中的“无法识别的字段:http”

我有一个非常简单的 dropwizard 项目(基于Dropwizard hello world),我想将其部署到 heroku。由于我还无法确定的原因,它在 heroku 中成功构建后无法运行。它在本地运行良好;我只在 heroku 上看到这个错误:

Heroku 日志:

2016-05-11T06:11:35.276279+00:00 heroku[slug-compiler]: Slug compilation started
2016-05-11T06:11:35.276284+00:00 heroku[slug-compiler]: Slug compilation finished
2016-05-11T06:11:35.317873+00:00 heroku[web.1]: State changed from crashed to starting
2016-05-11T06:11:37.914144+00:00 heroku[web.1]: Starting process with command `java $JAVA_OPTS -Ddw.http.port=56125 -Ddw.http.adminPort=56125 -jar target/myapp-1.0-SNAPSHOT.jar server hello-world.yml`
2016-05-11T06:11:39.645193+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2016-05-11T06:11:39.648486+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-05-11T06:11:40.723314+00:00 app[web.1]: hello-world.yml has an error:
2016-05-11T06:11:40.723347+00:00 app[web.1]:   * Unrecognized field at: …
Run Code Online (Sandbox Code Playgroud)

java yaml heroku dropwizard

0
推荐指数
1
解决办法
1037
查看次数

如何使用android模拟器测试在localhost上返回JSON的服务

我有一个在localhost上运行的dropwizard服务:8080.

它在此url上返回以下json: http://localhost:8080/users/johndoe/items

[
{
"id": 1,
"name": "Item1"
},
{
"id": 2,
"name": "Item 2"
},
{
"id": 7,
"name": "Item 3"
},
{
"id": 8,
"name": "Item4"
}
]
Run Code Online (Sandbox Code Playgroud)

当我尝试从我的Android模拟器访问此URL时,我收到此异常:

org.apache.http.conn.HttpHostConnectException: Connection to http://localhost:8080 refused
Run Code Online (Sandbox Code Playgroud)

在我的清单中,我已经获得了互联网权限

<!-- Permission - Internet Connect -->
<uses-permission android:name="android.permission.INTERNET" />

<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Run Code Online (Sandbox Code Playgroud)

我也试图改变localhost,以127.0.0.1无果

我知道API需要放在互联网可访问的服务器上,用于生产应用程序,但出于开发目的,解决此问题的方法是什么?

java rest android json dropwizard

-1
推荐指数
1
解决办法
5596
查看次数