是否可以使用EE 6中的@ApplicationPath和@Path注释来模拟servlet过滤器链?
例:
@ApplicationPath("/api")
class Filter extends Application {
@Path("/*")
public void filter() {
log.info("Request to API");
}
}
Run Code Online (Sandbox Code Playgroud)
...
@Path("/foo")
class Foo {
@GET
@Path("/bar")
@Produces("text/plain")
public String bar() {
return "Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
URL的位置是http://foobar.com/api/foo/bar,但"filter"方法将被调用,就像它是一个servlet过滤器链一样.我知道上面的方法不会起作用,但是在这种方法中是否有一个带注释的方法,就像从web.xml文件配置"过滤器"一样?
是否可以从RESTeasy接口返回HTTP错误?我目前正在使用链式网络过滤器,但我想知道是否可以直接从界面...
示例sudo-code:
@Path("/foo")
public class FooBar {
@GET
@Path("/bar")
@Produces("application/json")
public Object testMethod(@HeaderParam("var_1") @DefaultValue("") String var1,
@HeaderParam("var_2") @DefaultValue("") String var2 {
if (var1.equals(var2)) {
return "All Good";
} else {
return HTTP error 403;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个关于从自定义配置文件加载属性的问题.我已经尝试了两种不同的方法来加载我的oauth.properties文件,但我无法工作,所以我希望有人可以帮助我.
我尝试的第一种方法是将文件添加到conf目录并因此引用它:
String oauthPropertiesFile = ClassLoader.getSystemResource("oauth.properties").getFile();
Run Code Online (Sandbox Code Playgroud)
但那刚刚回来了NULL.
我尝试的第二种方法是添加:
@include.oauthProperties = oauth.properties
Run Code Online (Sandbox Code Playgroud)
到application.conf文件,然后在我的控制器中引用它,如:
String clientId = oauthProperties.clientId;
Run Code Online (Sandbox Code Playgroud)
但是这不会编译.
任何人都可以解释我在这里做错了什么吗?
我一直在研究JPA/Hibernate @Entity继承一段时间,似乎无法找到解决我想要实现的问题的任何东西.
基本上我希望能够根据需要定义@Entity所有列和表映射.然后,我希望能够使用@Entity在@Transient每个"子实体"的主体中定义的不同方法集来扩展许多不同的位置.这是我想要实现的基本示例,但到目前为止没有成功:
@Entity
@Table(name = "mountain")
public class MountainEntityBase implements Serializable {
public Integer mountainId = 0;
public Integer height = 0;
public List<ExplorerEntityBase> explorers = new ArrayList<ExplorerEntityBase>();
@Id
@GeneratedValue
@Column(name = "mountain_id")
public Integer getMountainId() { return mountainId; }
public void setMountainId(Integer mountainId) { this.mountainId = mountainId; }
@Column(name="height")
public String getHeight() { return height; }
public void setHeight(String height) { this.height = height; }
@OneToMany(mappedBy="mountainId")
public List<ExplorerEntityBase> getExplorers() { return …Run Code Online (Sandbox Code Playgroud) 我试图id="someId"在每种情况下删除someId不同的所有出现.我试图使用这种语法:(id="\w+\"\(\))因为它在其他海报的类似情况下使用.但我不懂语法,当然它不起作用.
有人可以告诉我为什么这种语法不正确,并可能指向一个解释语法的资源?
可以将Android APK档案导入另一个Android项目,并以与JAR档案相同的方式访问吗?
我有一个文本字段后跟一个静态文本字段,我正在尝试用它做两件事:
两个字段都包含在一个框架中.
我将两个字段设置为positionType = float,将文本字段设置为stretchWithOverflow = true,这样可以使文本垂直包装但不能水平拉伸.
是否有可能实现上面的1和2?如果是这样如何?
是否可以生成检测 XML 数据源文件中最后一个元素的“Print When Expression”?
基本上,我有一个报告,在详细信息带中的子报告之后插入了一个分栏符,因此我可以清楚地定义新记录开头的新页面。但它总是给我留下空白的最后一页。所以我希望如果我有一个打印条件可以防止这种情况,如果它是 XML 数据源中的最后一个记录元素,则可以防止列中断。
这甚至可能吗?
我正在尝试使用spymemcached-2.8.4客户端在memcached中设置一个非常基本的命中率监视器,但是存储在memcached中的值实际上似乎从未增加...这是一个错误还是我错过了什么?
public static void checkHitRate(String clientId) throws FatalException, ForbiddenException {
MemcachedClient memcachedClient;
try {
memcachedClient = new MemcachedClient(new InetSocketAddress("localhost", 11211));
Integer hitRate = (Integer) memcachedClient.get(clientId);
if (hitRate == null) {
memcachedClient.set(clientId, 1800, 1);
} else if (hitRate > 500) {
throw new ForbiddenException("Hit rate too high. Try again later");
} else if (hitRate <= 500) {
memcachedClient.incr(clientId, 1);
}
} catch (IOException e) {
throw new FatalException("Could not read hit rate from Memcached.");
}
}
Run Code Online (Sandbox Code Playgroud)
我知道它在memcached中是可能的:
(TELENT输出)
set clientId_1 0 …Run Code Online (Sandbox Code Playgroud) 问题:
我试图将服务注入bean,但服务实例始终为null.
背景:
我有两个豆子从另一个叫来.这是它们在XML配置中的定义方式:
<context:annotation-config />
<bean class="com.test.MyBeanImpl" name="myBean"/>
<bean id="myService" class="com.test.MyServiceImpl" />
Run Code Online (Sandbox Code Playgroud)
和bean的实现方式如下:
MyServiceImpl.java
class MyServiceImpl implements MyService {
public void getString() {
return "Hello World";
}
}
Run Code Online (Sandbox Code Playgroud)
MyBeanImpl.java
@Component
class MyBeanImpl implements MyBean, SomeOtherBean1, SomeOtherBean2 {
@Resource(name="myBean")
private MyService myService;
public MyBeanImpl() {}
}
Run Code Online (Sandbox Code Playgroud)
问题:
是否有一些原因与我的bean实现3个接口阻止服务被注入的事实相关?如果没有其他因素可能会影响它?
java ×5
android ×1
annotations ×1
apk ×1
archive ×1
counter ×1
eclipse ×1
field ×1
file ×1
formatting ×1
hibernate ×1
hitcounter ×1
http ×1
httpresponse ×1
increment ×1
inheritance ×1
java-ee ×1
jpa ×1
memcached ×1
persistence ×1
regex ×1
replace ×1
resteasy ×1
servlets ×1
spring ×1
spymemcached ×1
stretch ×1
wildcard ×1