如何使用Jersey 2客户端提交空机构的帖子请求?
final MyClass result = ClientBuilder.newClient()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(What to fill in here if the body should be left empty??, MyClass.class);
Run Code Online (Sandbox Code Playgroud)
更新:这有效:
final MyClass result = ClientBuilder
.newBuilder().register(JacksonFeature).build()
.target("http://localhost:8080")
.path("path")
.queryParam("key", "value")
.request(APPLICATION_JSON)
.post(null, MyClass.class);
Run Code Online (Sandbox Code Playgroud) 让我们说在我的弹性搜索索引中我有一个名为"点"的字段,它将包含一串标点符号分隔的单词(例如"first.second.third").
我需要搜索例如"first.second",然后获取所有条目,其"dots"字段包含一个字符串正好是"first.second"或以"first.second"开头.
我在理解文本查询的工作原理时遇到了问题,至少我无法创建一个完成工作的查询.
我想在Elasticsearch中已经存在的索引上设置以下设置和映射:
{
"analysis": {
"analyzer": {
"dot-analyzer": {
"type": "custom",
"tokenizer": "dot-tokenizer"
}
},
"tokenizer": {
"dot-tokenizer": {
"type": "path_hierarchy",
"delimiter": "."
}
}
}
}
{
"doc": {
"properties": {
"location": {
"type": "string",
"index_analyzer": "dot-analyzer",
"search_analyzer": "keyword"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图添加这两行代码:
client.admin().indices().prepareUpdateSettings(Index).setSettings(settings).execute().actionGet();
client.admin().indices().preparePutMapping(Index).setType(Type).setSource(mapping).execute().actionGet();
Run Code Online (Sandbox Code Playgroud)
但这是结果:
org.elasticsearch.index.mapper.MapperParsingException: Analyzer [dot-analyzer] not found for field [location]
Run Code Online (Sandbox Code Playgroud)
任何人?非常感谢,
斯坦
这似乎有效:
if (client.admin().indices().prepareExists(Index).execute().actionGet().exists()) {
client.admin().indices().prepareClose(Index).execute().actionGet();
client.admin().indices().prepareUpdateSettings(Index).setSettings(settings.string()).execute().actionGet();
client.admin().indices().prepareOpen(Index).execute().actionGet();
client.admin().indices().prepareDeleteMapping(Index).setType(Type).execute().actionGet();
client.admin().indices().preparePutMapping(Index).setType(Type).setSource(mapping).execute().actionGet();
} else {
client.admin().indices().prepareCreate(Index).addMapping(Type, mapping).setSettings(settings).execute().actionGet();
}
Run Code Online (Sandbox Code Playgroud) 我正在努力使我的GWT应用程序的结构正确.(我是唯一一个发现GWT代码很容易变得非常混乱和难以理解的人吗?)
该应用程序应该是几个截然不同的区域的接口 - 让我们说区域A和B.目前我正在尝试将它作为一个带有两个标签的界面实现 - 一个带你到A区,一个带你去区域B.我不知道如何通过这种方式将两个不同区域所需的代码分离得很好 - 应用MVP模式(我实际上并不清楚如何做到这一点我的选项卡之类的分层接口)我最终将区域A和区域B代码放在例如client.view和client.presenter包中:
src
- main
- java
- client
+ event
- presenter
+ a_stuff
+ b_stuff
- view
+ a_stuff
+ b_stuff
:
我还没有找到任何关于如何以及何时使用多个模块的好例子,我想知道我的案例是否可能是多个模块有意义的案例?在这种情况下,代码将如何构建?
也许有必要提一下,我正在使用最新的GWT,Maven和IntelliJ IDEA.
非常感谢提示,非常感谢Stine :)
我正在使用带有Guice的RESTEasy开发REST API,目前我正在尝试使用类似于Dropwizard中的@Auth的注释来合并基本身份验证.同
@Path("hello")
public class HelloResource {
@GET
@Produces("application/json")
public String hello(@Auth final Principal principal) {
return principal.getUsername();
}
}
Run Code Online (Sandbox Code Playgroud)
hello资源调用应该被一些使用Authorization HTTP请求头中传递的凭据执行基本身份验证的代码拦截,并且成功将主体注入方法主体参数.我还希望能够将允许的角色列表传递给注释,例如@Auth("admin").
我真的需要一些建议,以实现这一目标的方向?
我正在努力按照我想要的方式在弹性搜索中提升工作量.
假设我有一些索引包含性别,兴趣和年龄的个人资料,让我们说我发现性别匹配最相关,那么兴趣和最不重要的标准就是用户的年龄.我期待下面的查询导致根据刚刚提到的原则对匹配的配置文件进行排序,但是当我执行它时,我首先得到一些男性,然后我得到50岁的女性安娜,然后是喜欢汽车的女性玛丽亚...为什么玛丽亚得分不比安娜高?
{
"query": {
"bool" : {
"should" : [
{ "term" : { "gender" : { "term": "male", "boost": 10.0 } } },
{ "term" : { "likes" : { "term": "cars", "boost" : 5.0 } } },
{ "range" : { "age" : { "from" : 50, "boost" : 1.0 } } }
],
"minimum_number_should_match" : 1
}
}
}
Run Code Online (Sandbox Code Playgroud)
提示将不胜感激,
斯坦
这些是执行的curl命令:
$ curl -XPUT http://localhost:9200/users/profile/1 -d '{
"nickname" : "bob",
"gender" : "male",
"age" : …Run Code Online (Sandbox Code Playgroud) 我应该如何进行ValueFactoryProvider绑定,以便在Jersey 2中共存两个自定义注入注释?下面我已经包含了一个当前方法的示例,您可以看到Hello注释注入"隐藏"SmallTalk注释注入.
你好注释:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface Hello {
}
Run Code Online (Sandbox Code Playgroud)
SmallTalk注释:
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.PARAMETER})
public @interface SmallTalk {
}
Run Code Online (Sandbox Code Playgroud)
Hello注释解析器:
@Singleton
public class HelloResolver {
public static class HelloInjectionResolver extends ParamInjectionResolver<Hello> {
public HelloInjectionResolver() {
super(HelloValueFactoryProvider.class);
}
}
@Singleton
public static class HelloValueFactoryProvider extends AbstractValueFactoryProvider {
@Inject
public HelloValueFactoryProvider(final MultivaluedParameterExtractorProvider extractorProvider,
final ServiceLocator injector) {
super(extractorProvider, injector, UNKNOWN);
}
@Override
protected Factory<?> createValueFactory(final Parameter parameter) {
final Class<?> classType = parameter.getRawType();
if (classType == null || (!classType.equals(String.class))) return null;
return new …Run Code Online (Sandbox Code Playgroud) 我正在使用Jersey 2开发REST API,我需要在启动时实例化一些类,而不仅仅是在某些资源请求触发它时.
所以我要问的是:我如何实现SomethingImpl下面定义的实例是在服务器启动时创建的,而不仅仅是当有人点击某些资源时?在Guice我会用.asEagerSingleton().
应用:
public class MyApplication extends ResourceConfig {
public MyApplication() {
register(new AbstractBinder() {
@Override
protected void configure() {
bind(" else").to(String.class);
bind(SomethingImpl.class).to(Something.class).in(Singleton.class);
}
});
register(SomeResource.class);
}
}
Run Code Online (Sandbox Code Playgroud)
东西:
public interface Something {
String something();
}
public class SomethingImpl implements Something {
@Inject
public SomethingImpl(final String something) {
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
System.out.println(something() + something);
try {
Thread.sleep(4000);
} catch (final InterruptedException e) {
break;
} …Run Code Online (Sandbox Code Playgroud) 如何检测用户何时在UIDatePicker中点击选择指示符?
如果没有这个,用户必须滚动到其他日期,然后再返回以选择日期选择器向上滑动时显示在选择指示器下的日期.
非常感谢,
Stine

更新:这是我能想出的唯一解决方案:
UIDatePicker *aDatePicker = [[UIDatePicker alloc] init];
self.datePicker = aDatePicker;
[aDatePicker release];
[self.datePicker addTarget:self action:@selector(datePicked:) forControlEvents:UIControlEventValueChanged];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(datePicked:)];
[self.datePicker addGestureRecognizer:tap];
[tap release];
Run Code Online (Sandbox Code Playgroud)
这意味着datePicked当用户实际旋转车轮时将被调用两次.
更新:上述解决方案不适用于UIPickerViews.在这些情况下,我不知道如何实现通缉行为.
我必须通过SSL双重身份验证连接到服务器.我已将自己的私钥加证书添加到keystore.jks,并将服务器的自签名证书添加到truststore.jks,这两个文件都复制到/ usr/share/tomcat7.我的代码使用的套接字工厂由以下提供者提供:
@Singleton
public static class SecureSSLSocketFactoryProvider implements Provider<SSLSocketFactory> {
private SSLSocketFactory sslSocketFactory;
public SecureSSLSocketFactoryProvider() throws RuntimeException {
try {
final KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
final InputStream trustStoreFile = new FileInputStream("/usr/share/tomcat7/truststore.jks");
trustStore.load(trustStoreFile, "changeit".toCharArray());
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
final InputStream keyStoreFile = new FileInputStream("/usr/share/tomcat7/keystore.jks");
keyStore.load(keyStoreFile, "changeit".toCharArray());
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, "changeit".toCharArray());
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);
this.sslSocketFactory = sslContext.getSocketFactory();
} catch (final KeyStoreException e) { …Run Code Online (Sandbox Code Playgroud) 我在使RestEasy(3.0.10.Final)将路径参数解析为枚举值时遇到问题.
有枚举定义......
package com.stines;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
public enum MyNumber {
One("number-one"), Two("number-two");
@JsonIgnore private final String text;
@JsonIgnore
private MyNumber(final String text) {
this.text = text;
}
@JsonValue
public String getText() {
return text;
}
@JsonCreator
public static MyNumber byText(final String text) {
for (final MyNumber value : MyNumber.values()) {
if (value.getText().equals(text)) return value;
}
throw new IllegalArgumentException("Unknown number");
}
}
Run Code Online (Sandbox Code Playgroud)
......和终点......
@PUT
@Path("{number}")
void putNumber(
@PathParam("number") MyNumber number
);
Run Code Online (Sandbox Code Playgroud)
......我希望能打到PUT http://my-server/number-one.
我看到以下情况:
Caused …Run Code Online (Sandbox Code Playgroud) java ×6
jersey ×3
guice ×2
hk2 ×2
rest ×2
resteasy ×2
annotations ×1
enums ×1
fasterxml ×1
gwt ×1
inject ×1
iphone ×1
jackson ×1
keystore ×1
objective-c ×1
self-signed ×1
ssl ×1
truststore ×1