Book Image

Java EE 7 Development with WildFly

Book Image

Java EE 7 Development with WildFly

Overview of this book

Table of Contents (21 chapters)
Java EE 7 Development with WildFly
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Creating our first endpoint


Let's start with a simple example:

package com.packtpub.wflydevelopment.chapter8.boundary;

import javax.websocket.EndpointConfig;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;

@ServerEndpoint("/hello")
public class HelloEndpoint {

    @OnOpen
    public void open(Session session, EndpointConfig conf) throws IOException {
        session.getBasicRemote().sendText("Hi!");
    }
}

Java EE 7 specification has taken into account developer friendliness, which can be clearly seen in the given example. In order to define your WebSocket endpoint, you just need a few annotations on a Plain Old Java Object (POJO). The first annotation @ServerEndpoint("/hello") defines a path to your endpoint. It's a good time to discuss the endpoint's full address. We placed this sample in the application named ticket-agency-websockets. During the deployment of application, you can spot information...