小编Ste*_*NYC的帖子

使用dropwizard覆盖带有env变量的服务器连接器配置

我已经在dw邮件列表上发布了这个问题,但没有得到答案.

我可以假设下面的YML格式不再适用于DW 0.7.0吗?(使用@ char插入env var)

server:
  applicationConnectors:
    - type: http
      bindHost: @OPENSHIFT_DIY_IP@
      port: @OPENSHIFT_DIY_PORT@
Run Code Online (Sandbox Code Playgroud)

错误:

格式错误的YAML在第28行,第17列; 扫描下一个标记时; 找到无法启动任何令牌的字符@'@'.(不要使用@代替缩进); 在'reader',第28行,第17列:bindHost:@ OPENSHIFT_DIY_IP @

所以我决定使用这种格式:

server:
  type: simple
  applicationContextPath: /
  adminContextPath: /admin
  connector:
      type: http
      bindHost: localhost
      port: 8080
Run Code Online (Sandbox Code Playgroud)

并尝试通过jvm选项覆盖它:

java -Ddw.server.connector.bindHost=$OPENSHIFT_DIY_IP -Ddw.server.connector.port=$OPENSHIFT_DIY_PORT -jar target/myapp.jar server myapp.yml
Run Code Online (Sandbox Code Playgroud)

我的本地env变量:

OPENSHIFT_DIY_IP=localhost
OPENSHIFT_DIY_PORT=8080
Run Code Online (Sandbox Code Playgroud)

我从这个设置得到的错误:

线程"main"中的异常java.lang.RuntimeException:java.net.SocketException:org.eclipse.jetty.setuid.SetUIDListener.lifeCycleStarting(SetUIDListener.java:213)中未解析的地址...引起:java.net.SocketException :sun.nio.ch.Net.translateToSocketException(Net.java:157)中未解析的地址... WARN [2014-05-03 20:11:19,412] org.eclipse.jetty.util.component.AbstractLifeCycle:FAILED org .eclipse.jetty.server.Server @ 91b85:java.lang.RuntimeException:java.net.SocketException:未解析的地址

我究竟做错了什么?

java dropwizard

18
推荐指数
2
解决办法
9558
查看次数

从wget解析http响应头

我试图从wget的结果中提取一条线但是遇到了麻烦.这是我的wget电话:

$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html
Run Code Online (Sandbox Code Playgroud)

输出:

--18:24:12--  http://xxx.xxxx.xxxx:15000/myhtml.html
           => `-'
Resolving xxx.xxxx.xxxx... xxx.xxxx.xxxx
Connecting to xxx.xxxx.xxxx|xxx.xxxx.xxxx|:15000... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 302 Found
  Date: Tue, 18 Nov 2008 23:24:12 GMT
  Server: IBM_HTTP_Server
  Expires: Thu, 01 Dec 1994 16:00:00 GMT
  Location: https://xxx.xxxx.xxxx/siteminderagent/...
  Content-Length: 508
  Keep-Alive: timeout=10, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1
Location: https://xxx.xxxx.xxxx//siteminderagent/...
--18:24:13--  https://xxx.xxxx.xxxx/siteminderagent/...
           => `-'
Resolving xxx.xxxx.xxxx... failed: Name or service not known.

如果我这样做:

$ wget -SO- -T 1 -t 1 http://myurl.com:15000/myhtml.html …
Run Code Online (Sandbox Code Playgroud)

parsing header http wget response

10
推荐指数
2
解决办法
3万
查看次数

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

我试图用guice/dropwizard配置hibernatebundle并需要帮助.我使用hubspot/dropwizard-guice/0.7.0第三方库以及dropwizard lib.

下面的代码显然不会工作,需要帮​​助才能搞清楚.我如何重写这个,以便hibernatebundle和最终的会话工厂自动注入任何需要它的bean.

MyApplication.java

public class MyApplication extends Application<MyAppConfiguration> {

    private final HibernateBundle<MyAppConfiguration> hibernateBundle = new HibernateBundle<MyAppConfiguration>(MyModel.class) {
        @Override
        public DataSourceFactory getDataSourceFactory(MyAppConfiguration configuration) {
            return configuration.getDataSourceFactory();
        }
    };

    @Override
    public void initialize(Bootstrap<MyAppConfiguration> bootstrap) {
        bootstrap.addBundle(hibernateBundle);  // ???

        bootstrap.addBundle(
            GuiceBundle.<MyAppConfiguration>newBuilder()
                    .addModule(new MyAppModule())
                    .enableAutoConfig(getClass().getPackage().getName())
                    .setConfigClass(MyAppConfiguration.class)
                    .build()
        );
    }

}   
Run Code Online (Sandbox Code Playgroud)

MyAppModule.java

public class MyAppModule extends AbstractModule {

    @Provides
    public SessionFactory provideSessionFactory(MyAppConfiguration configuration) {
            // really wrong as it creates new instance everytime.
        return configuration.getHibernateBundle().getSessionFactory(); // ???
    }

}
Run Code Online (Sandbox Code Playgroud)

MyAppConfiguration.java

public class …
Run Code Online (Sandbox Code Playgroud)

java hibernate guice dropwizard

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

REST POST不支持的媒体类型

我有这个VO

public class myVO {
    private final String latitude;
    private final String longtitude;
    private final String meterRadius;

    public myVO(String latitude, String longtitude, String meterRadius) {
        this.latitude = latitude;
        this.longtitude = longtitude;
        this.meterRadius = meterRadius;
    }

    public String getLatitude() {
        return latitude;
    }

    public String getLongtitude() {
        return longtitude;
    }

    public String getMeterRadius() {
        return meterRadius;
    }

}
Run Code Online (Sandbox Code Playgroud)

和休息服务

@Path("/listrs")
@Produces(MediaType.APPLICATION_JSON)
public class MyResource {
    Logger logger = LoggerFactory.getLogger(MyResource.class);

    private final AtomicLong counter;

    public MyResource(String template, String defaultName) {
        //this.template = …
Run Code Online (Sandbox Code Playgroud)

java rest curl jersey dropwizard

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

dropwizard ×3

java ×3

curl ×1

guice ×1

header ×1

hibernate ×1

http ×1

jersey ×1

parsing ×1

response ×1

rest ×1

wget ×1