标签: java-ee-7

如何更改Activemq的默认端口号

我正在使用Windows 7OS.我apache-activemq-5.8.0.zip从这些链接下载并在C:\Users\Infratab Bangalore\Desktop\Queueing\apache-activemq-5.8.0目录中解压缩.

Activemq初始化时,我Pre-Installation Requirements从这些链中读取概念.

我已经安装apache-maven-3.0.5在我的系统中.对于我的构造,我在我的系统中运行以下命令.

   mvn -version
Run Code Online (Sandbox Code Playgroud)

我收到以下消息,所以Maven安装成功.

 Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 19:21:
 28+0530)
 Maven home: P:\Software\apache-maven-3.0.5
 Java version: 1.7.0_21, vendor: Oracle Corporation
 Java home: C:\Program Files\Java\jdk1.7.0_21\jre
 Default locale: en_US, platform encoding: Cp1252
 OS name: "windows 7", version: "6.1", arch: "x86", family: "windows" 
Run Code Online (Sandbox Code Playgroud)

geronimo-spec-corba-1.0.jar从这些链接下载并设置classpth.

在此输入图像描述

Activemq以下面的方式开始初始化.

  C:\Users\Infratab Bangalore\Desktop\Queueing\apache-activemq-5.8.0\bin>activemq
Run Code Online (Sandbox Code Playgroud)

我收到错误,所以我测试了是否61616(Activemq default port no) …

java apache activemq-classic jms java-ee-7

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

在Netbeans/Maven/Cargo插件中配置GlassFish 4域目录

我正在尝试使用Netbeans 从Java 7/8 EE教程*部署第一个示例(hello1),我遇到了问题.项目编译没有问题,但在部署时会出错:

Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.2:redeploy (deploy) on project hello1: Execution deploy of goal org.codehaus.cargo:cargo-maven2-plugin:1.4.2:redeploy failed: Failed to create deployer with implementation class org.codehaus.cargo.container.glassfish.GlassFish4xInstalledLocalDeployer for the parameters (container [id = [glassfish4x]], deployer type [installed]). InvocationTargetException: The container configuration directory "/home/DeltaLima/glassfish4/glassfish/domains" does not exist. Please configure the container before attempting to perform any local deployment. Read more on: http://cargo.codehaus.org/Local+Configuration -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

与教程相反,我在/ opt/glassfish-v4中安装了GlassFish服务器,而不是/ home/DeltaLima/glassfish4.在Netbeans中我以这种方式进行配置,因此我可以毫无问题地启动,停止和检查服务器的状态.服务器配置中的域文件夹已正确设置.

似乎与Netbeans捆绑的Maven安装期望服务器安装在用户的主目录中.

我是Java EE,Netbeans和Maven的新手,因此我没有配置Netbeans/Maven的经验,错误消息中提供的教程或链接都没有多大帮助.

如何在Netbeans中设置项目,使其部署在正确的目录中?

Netbeans版本7.3.1
Glassfish版本4.0
操作系统:Ubuntu

*答案已更新,以便考虑Java 8 EE

maven-cargo java-ee maven java-ee-7 java-ee-8

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

JSR-356:如何在握手期间中止websocket连接?

我需要能够在握手期间中止websocket连接,以防HTTP请求不符合某些条件.根据我的理解,正确的地方是我自己实现的ServerEndpointConfig.Configurator.modifyHandshake()方法Configurator.我只是无法弄清楚要做什么来中止连接.有一个HandshakeResponse参数,允许向响应添加标题但我找不到任何执行该工作的标题.

那么如何在握手期间中止websocket连接呢?这甚至可能吗?

java java-ee websocket java-7 java-ee-7

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

使用JAX-RS 2.0客户端API进行POST

我有一个REST服务,使用表单参数公开POST服务:

@POST
@Path("/add")
@Produces("text/html")
public Response create(@FormParam("key")String key,
            @FormParam("value")String value)
{    
    service.addToList(key,value);    
    return Response.ok(RESPONSE_OK).build();     

} 
Run Code Online (Sandbox Code Playgroud)

我需要找到一种方法来使用JAX-RS客户端API调用此服务.遗憾的是,网上唯一可用的示例使用了传递给Web目标资源的Entity类:

StoreOrder order = new StoreOrder(...);
WebTarget myResource = client.target("http://example.com/webapi/write");
TrackingNumber trackingNumber = myResource.request(MediaType.APPLICATION_XML)
                                   .post(Entity.xml(order), TrackingNumber.class);
Run Code Online (Sandbox Code Playgroud)

知道如何通过单个参数(可能是表单参数)调用我的服务吗?谢谢!

rest java-ee java-ee-7

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

模拟或构建Jersey InboundJaxrsResponse

我是一个相当新的开发球衣客户端,并在一些测试中遇到了一些问题.首先,我可能应该提到我的应用程序是所有客户端,没有服务器端的东西.

我的问题是我想创建一个Response实例的对象InboundJaxrsResponse,到目前为止,我试图通过模拟Response使用Mockito和实现这一点ResponseBuilder.build()

使用Mockito:

Response response = mock(Response.class);
when(response.readEntity(InputStream.class))
    .thenReturn(ClassLoader.getSystemResourceAsStream("example_response.xml");
Run Code Online (Sandbox Code Playgroud)

这工作正常,当我读出响应的实体时,response.readEntity(InputStream.class) 我得到了预期的实体.但是我需要多次从响应中读取实体.为了实现这一点,我response.bufferEntity()在读出实体之前使用.我第一次阅读实体一切正常,但第二次我得到一个异常I/O stream closed......好吧我想出了嘲笑方法bufferEntity,如下所示:

Response response = mock(Response.class);
when(response.bufferEntity()).thenCallRealMethod();
when(response.readEntity(InputStream.class))
    .thenReturn(ClassLoader.getSystemResourceAsStream("example_response.xml");
Run Code Online (Sandbox Code Playgroud)

但这只是导致错误被调用时抛出bufferEntity(),这是因为bufferEntity()Responseabstract.

我的另一个尝试是通过使用ResponseBuilder.build()如下:

ResponseBuilder responseBuilder = Response.accepted(ClassLoader.getSystemResourceAsStream("example_response.xml"));
Response response = responseBuilder.build();
Run Code Online (Sandbox Code Playgroud)

这个声明很好,通过调试我的响应我可以看到它有正确的实体等等.但是这次当我打电话的时候,我response.bufferEntity()得到一个异常抛出,说这个操作是非法的,OutboundJaxrsResponse所以通过这种方式构建响应会导致错误的实例Response.class:

所以最终有三个问题.

  1. 这是否可以模拟/构建此类型的对象进行测试?
  2. 有没有办法模拟入站响应?
  3. 有没有一种办法,而不是创建的实例OutboundJaxrsResponseResponseBuilder.build()创建的实例InboundJaxrsResponse,或至少铸造/实例转换OutboundJaxrsResponse到的实例OutboundJaxrsResponse

java unit-testing jersey jersey-client java-ee-7

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

在数据库中修改某些内容时,仅通过WebSockets通知特定用户

为了通过WebSockets通知所有用户,当在选定的JPA实体中修改某些内容时,我使用以下基本方法.

@ServerEndpoint("/Push")
public class Push {

    private static final Set<Session> sessions = new LinkedHashSet<Session>();

    @OnOpen
    public void onOpen(Session session) {
        sessions.add(session);
    }

    @OnClose
    public void onClose(Session session) {
        sessions.remove(session);
    }

    private static JsonObject createJsonMessage(String message) {
        return JsonProvider.provider().createObjectBuilder().add("jsonMessage", message).build();
    }

    public static void sendAll(String text) {
        synchronized (sessions) {
            String message = createJsonMessage(text).toString();

            for (Session session : sessions) {
                if (session.isOpen()) {
                    session.getAsyncRemote().sendText(message);
                }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

当修改选定的JPA实体时,会引发适当的CDI事件,该事件将由以下CDI观察者观察.

@Typed
public final class EventObserver {

    private EventObserver() {}

    public void …
Run Code Online (Sandbox Code Playgroud)

java-ee websocket real-time-updates java-ee-7

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

自Java EE 7/EL 3.0起,javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL不再起作用

<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)

在glassfish 4和wildfly 8 Final上不适用最新的Mojarra 2.2.5

Manfried Riem ,我已经看到了关于此的多个错误报告,

确定这是一个EL问题,EL实现已经修复以解决这个问题

修复版本说2.2.5,它也在2.2.5的发行说明中说明,我错过了什么?

jsf el jsf-2.2 java-ee-7

9
推荐指数
2
解决办法
4536
查看次数

Uncaught SecurityError:无法构造'WebSocket':可能无法从通过HTTPS加载的页面启动不安全的WebSocket连接

我正在使用GlassFish Server 4.1/Java EE 7.在我的web.xml文件中,我提到了以下安全约束.

<security-constraint>
    <display-name>UserConstraint</display-name>
    <web-resource-collection>
        <web-resource-name>Provide a Name</web-resource-name>
        <description/>
        <url-pattern>/admin_side/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>ROLE_ADMIN</role-name>
    </auth-constraint>
    <user-data-constraint>
        <description/>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
Run Code Online (Sandbox Code Playgroud)

其他当局也是如此.

由于transport-guarantee设置为CONFIDENTIAL,与指定的URL模式匹配的网页/admin_side/*通过安全通道(HTTPS)运行.

使用WebSockets时如下(JavaScript),

var ws = new WebSocket("ws://localhost:8181/Context/Push");
Run Code Online (Sandbox Code Playgroud)

它无法建立初始握手.浏览器在浏览器控制台上显示以下警告.

[blocked] The page at 'https://localhost:8181/Context/admin_side/Category' was loaded over HTTPS, but ran insecure content from 'ws://localhost:8080/Context/Push': this content should also be loaded over HTTPS.

Uncaught SecurityError: Failed to construct 'WebSocket': An insecure WebSocket connection may not be initiated from …
Run Code Online (Sandbox Code Playgroud)

ssl html5 java-ee websocket java-ee-7

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

Wildfly 9上的部署失败

我曾经遇到过wildfly 8这个问题,但解决了包含$ WILDFLY_HOME/modules/system/layers/base/org/eclipse/persistence/main中的eclipselink.jar并使用资源root更新module.xml

<resource-root path="eclipselink.jar" />
Run Code Online (Sandbox Code Playgroud)

并包括在我的ejb模块的POM.xml上

    <dependency>  
        <groupId>org.eclipse.persistence</groupId>  
        <artifactId>eclipselink</artifactId>  
        <version>2.6.0</version>  
        <scope>provided</scope>  
    </dependency>  
Run Code Online (Sandbox Code Playgroud)

这在Wildfly 8中运行良好.*.不幸的是,为Wildfly 9CR1采用相同的技术一直都没有通过以下日志:

08:52:31,028 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-6) MSC000001: Failed to start service jboss.deployment.unit."rga-ear-1.0.ear".FIRST_MODULE_USE: org.jboss.msc.service.StartException in service jboss.deployment.unit."rga-ear-1.0.ear".FIRST_MODULE_USE: WFLYSRV0153: Failed to process phase FIRST_MODULE_USE of deployment "rga-ear-1.0.ear"
    at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:163)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.util.ServiceConfigurationError: javax.persistence.spi.PersistenceProvider: Provider org.eclipse.persistence.jpa.PersistenceProvider could not be instantiated
    at java.util.ServiceLoader.fail(ServiceLoader.java:232)
    at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
    at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
    at org.jboss.as.jpa.persistenceprovider.PersistenceProviderLoader.loadProviderModuleByName(PersistenceProviderLoader.java:70)
    at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.lookupProvider(PersistenceUnitServiceHandler.java:998)
    at org.jboss.as.jpa.processor.PersistenceUnitServiceHandler.nextPhaseDependsOnPersistenceUnit(PersistenceUnitServiceHandler.java:1046) …
Run Code Online (Sandbox Code Playgroud)

deployment eclipselink java-ee-7 wildfly

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

如何在 Mapstruct 中管理延迟加载?

我正在处理与数据库中的延迟加载对象相关的问题。

假设我们有以下实体。

@Entity(name = "User")
@Table(name = "USERS")
public class User{
    @Id
    @GeneratedValue
    private int id

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="NOTES_ID")
    private List<Note> notes;
}
Run Code Online (Sandbox Code Playgroud)

而 Dto 将是

@Mapper
public interface UserDtoMapper{

    /** the INSTACE HERE **/

    User fromDto(UserDto dto);

    UserDto toDto(User user);

}
Run Code Online (Sandbox Code Playgroud)

那么哪个可能是获取所有用户而没有 EJBException 的最佳方法,因为我正在获取他们懒惰?

编辑:解决方案

假设您有以下数据模型

@Entity(name = "User")
@Table(name = "USERS")
public class User{
    @Id
    @GeneratedValue
    private int id

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="NOTES_ID")
    private List<Note> notes;
}
Run Code Online (Sandbox Code Playgroud)
  1. 没有地址的查询,异常:当从模型映射到 DTO 时,它将尝试映射addresses但因为延迟加载(通过休眠或任何其他框架)最终会出现异常。

此外,您可以忽略addressesfrom 被映射,如@Mehmet …

hibernate lazy-loading java-ee-7 mapstruct

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