我想知道Java EE 7的核心接口是否扩展AutoCloseable.(通过核心接口我的主要意思EntityManager和喜欢,但我不确定是否有其他接口或类可能会自动关闭.)
我认为他们应该而且这里是我假设的基础.
Java 6Connection甚至没有扩展Closeable,但Java 7的Connection扩展AutoCloseable(就像java.sql包中的其他几个接口一样).
在Java 7的声明中,接口是否可以EntityManager扩展AutoCloseable以便为我们提供良好的服务?或者自动神奇地关闭太复杂了?try-with-resourcesEntityManager
这个特殊功能是否被认为是JSR-342的一部分?
我正在使用JPA 2.1.我想生成mysql枚举类型列,如:gender enum('male','female').我的Enum课程是
public enum Gender {
MALE,
FEMALE
}
Run Code Online (Sandbox Code Playgroud)
在JPA实体类中
@Enumerated
private Gender gender;//generate int type column
Run Code Online (Sandbox Code Playgroud)
和
@Enumerated(EnumType.STRING)
private Gender gender; //generate varchar type column.
Run Code Online (Sandbox Code Playgroud)
有没有办法在MySql中生成枚举类型列?
我在我的应用程序中使用基于JavaEE 7的Websocket-API.
我需要访问我的websocket端点中的cookie中设置的值[Annotated one : @ServerEndpoint ("/websocket") ].我该怎么办?
@onOpen()方法就在那里,当建立与此websocket端点的连接时,将自动调用该方法.我想在这个方法中访问那里的cookie值.
我知道如何在servlet或JSP中做到这一点,但我是Websockets的新手.
请帮我这样做.提前致谢.
我已经从Java EE 6迁移到Java EE 7,现在使用JSF 2.2,上下文参数INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL似乎不起作用.在JSF 2.1中我将它设置为"true"并且它完美地工作,但现在我总是得到空字符串.
<context-param>
<param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
<param-value>true</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)
谁能说点什么呢?
我正在实现一个应用程序范围的服务(要进一步注入JAX-RS/JAX-WS服务或servlet,无关紧要),这将通过ManagedExecutorService或ManagedThreadFactory产生一些处理.在内部处理代码(Runnable实例)中,我想使用注入的资源,如EntityManager,DataSource和Web服务引用.第一个解决方案是这样的:
@ApplicationScoped
class MyService {
@Resource private ManagedExecutorService mes;
public void request(String param) {
mes.submit(new MyTask(param));
}
}
class MyTask implements Runnable {
// constructor skipped
@Resource private DataSource ds;
public void run() {
// do processing
}
}
Run Code Online (Sandbox Code Playgroud)
在MyTask.run()内部,该ds字段显示为null.好的,这是因为MyTask实例不是托管bean,即它不是由DI容器创建的,因此注入不可用.让我们将直接实例化更改为上下文实例:
@ApplicationScoped
class MyService {
@Resource ManagedExecutorService mes;
@Inject private Instance<MyTask> instance;
public void request(String param) { // <- no way to pass param to MyTask()!
mes.submit(instance.get());
}
}
Run Code Online (Sandbox Code Playgroud)
这可以按预期工作.但这是实现我想要的正确/最佳方式吗?通常,问题是,如何在运行时按需创建注入/托管实例.此外,在后一种情况下,我无法将任何参数传递给MyTask构造函数 - 这是否可能,或者我是否必须引入MyTask.setParam()方法来配置MyTask的实例?
我想写一个CDI拦截器.如果我的注释仅包含1个参数,则截取效果很好,但如果使用2个参数则会中断.问题是为什么?
拦截器类:
@Monitored
@Interceptor
@Priority(APPLICATION)
public class MonitoringInterceptor {
@AroundInvoke
public Object logInvocation(InvocationContext ctx) throws Exception {
LOGGER.error("METHOD CALLED!!!"); //this is not called when annotation has 2 parameters
return ctx.proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
注释:
@InterceptorBinding
@Target({TYPE, METHOD})
@Retention(RUNTIME)
@Inherited
public @interface Monitored {
public String layer() default "BUSINESS";
public String useCase() default "N/A";
}
Run Code Online (Sandbox Code Playgroud)
现在有趣的部分:
@Stateless
public class MyBean {
//this does not work, why?
@Monitored(layer = "BUSINESS", useCase = "test")
//if I use the following annotation it works well
//@Monitored(layer …Run Code Online (Sandbox Code Playgroud) 如何使用认可的标准机制在GlassFish 4.0 WAR应用程序中使用xerces?根据文档*,你应该把它放进去domain-dir/lib/endorsed.但是,当我将xercesImpl,xml-apis以及xml-resolver放在那里时,这些类在WAR中的类中不可用.这最可能是由于文档和默认配置之间的不一致:domain.xml不列出domain-dir/lib/endorsed.
当我包含它或放入文件时glassfish-install-dir/lib/endorsed,启动失败,出现以下异常:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.sun.enterprise.glassfish.bootstrap.GlassFishMain.main(GlassFishMain.java:97)
at com.sun.enterprise.glassfish.bootstrap.ASMain.main(ASMain.java:54)
Caused by: A MultiException has 5 exceptions. They are:
1. javax.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxOutputFactory not found
2. java.lang.IllegalStateException: Unable to perform operation: create on com.sun.enterprise.v3.server.DomainXmlPersistence
3. javax.xml.stream.FactoryConfigurationError: Provider com.ctc.wstx.stax.WstxInputFactory not found
4. java.lang.IllegalArgumentException: While attempting to resolve the dependencies of com.sun.enterprise.v3.server.GFDomainXml errors were found
5. java.lang.IllegalStateException: Unable …Run Code Online (Sandbox Code Playgroud) 我在Java EE 7后端使用AngularJS和REST API.该项目部署在Wildfly应用程序服务器上,我有一些问题重新分类证券:
加密/解密数据我使用CryptoJS在服务器端(Java)加密和解密,但显然我们必须清除密码,密码和盐只加密.我的问题是为什么密码短语是明文?它应该是秘密的,然后加密也没有?
对于REST API,Java EE 7使用的标准是什么,HTTP安全头(basic-auth)?Json Access令牌?它是如何工作的,在cookie上存储用户会话/令牌的位置?我只是想知道如何使用Angular.
也许我可以使用经典的JAAS进行基于表单的身份验证,然后让服务器端的request.login()进行身份验证,然后我的EJB将全部受@Role保护.
在AngularJS中保护页面的方法是什么?目前我正在使用web.xml并放置URL模式,也许有更好的方法?
我已经找到了很多像这样的例子:
AngularJs和Jboss以及JAAS(omnisecurity)
如何集成angularjs和基于java jaas的身份验证?
有些用户提到这个:
* index.html page should contain token inside html to avoid CSRF
* token shouldn't be stored in a cookie storage
* Each request should be signed with header param
* Server should validate every request by passed header
* If cookie usage is a must you should validate referer in order to prevent CSRF
Run Code Online (Sandbox Code Playgroud)
但是没有关于如何实现这一点的具体例子,尤其是CSRF.
我有以下GenericRest类,我用它来扩展基于使用@XmlRootElement注释的Entity类的rest类.
public class GenericRest<T extends BaseEntity> {
@Inject @Service
GenericService<T> service;
public GenericService<T> getService() {
return service;
}
@GET
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response getAll() {
// This works for JSON but does not work for XML Requests.
List<T> list = getService().findAll();
// This just gives the attributes for the BaseEntity.
//GenericEntity<List<T>> list = new GenericEntity<List<T>>(getService().findAll()) {};
return Response.ok(list).build();
}
}
Run Code Online (Sandbox Code Playgroud)
将APPLICATION_JSON在目前注释掉情况做工精细,但APPLICATION_XML给错误:
找不到类型的响应对象的MessageBodyWriter:java.util.Array媒体类型列表:application/xml
注释的情况适用于两种MediaTypes,但只返回BaseEntity扩展类的属性,而不是添加的属性.如何获取扩展类的属性并使两个MediaType都有效?
可在此处找到完整的存储库(正在进行中):https://github.com/martijnburger/multitenant
===更新1 ===
我更改@XmlSeeAlso了实体上的注释.这是在特定的实体,但需要在 …
我正在使用JAVA EE,JAX-RS,JPA,GLASSFISH进行应用.对于MediaType.APPLICATION_XML,响应正常.它不适用于MediaType.APPLICATION_JSON.
这是我的pojo课程
@Entity
@XmlRootElement
public class Book {
private int id;
private String name;
private String publication;
private String price;
@Id
@Column(name = "id")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Basic
@Column(name = "name")
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Basic
@Column(name = "publication")
public String getPublication() {
return publication;
}
public void setPublication(String publication) …Run Code Online (Sandbox Code Playgroud)