Skip to content

devsoftech/portal-java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

241 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portal for Java

The Portal for Java is a reference implementation written in Java of the server counterpart of the Portal project which provides useful semantics and concepts for modern web application development in the server side as well as server implementation.

The Portal and Portal for Java project is developed and maintained by Donghwan Kim. If you are interested, please subscribe to the discussion group.

Modules

The following list of modules are available.

Required

  • core: provides API and SPI.
  • bridge: makes the application run in the following environment.

Optional

  • objectfactory: delegates bean creation to the following framework.
  • evaluator: evaluate an expression using the following expression language.
    • spel: Spring Expression Language.

Demos

The easiest way to get started with Portal is to try out and look at examples. Thanks to Ralph, various online demos and source codes are available now at http://ha-bio.rasc.ch/portal-demos Try out!

Also, officialy a very simple chat application is provided with each bridge module to help getting started.

Snippets

Echoing a message

A simple echo handler which echoes back any message.

Browser

portal.open("/echo").send("message", "hello").message(function(data) {
    console.log(data);
});

Server

@Bean
public class EchoHandler {

    @On
    public void message(Socket socket, @Data String message) {
        socket.send("message", message);
    }

}

Broadcasting a message using room

A simple chat handler which broadcasts a received message to the room.

Browser

portal.open("/chat").on({
    open: function() {
        this.send("message", "Hi, there");
    },
    message: function(message) {
        console.log(message);
    }
});

Server

@Bean
public class ChatHandler {

    @Wire
    private Room hall;
    
    @On
    public void message(@Data String message) {
        hall.send(message);
    }

}

Notification delivery

Any event which occurs in anywhere in the server side can be sent to the client.

Browser

portal.open("/notifications").on(notifiers);

Server

@Component
public class NotificationEventListener implements ApplicationListener<NotificationEvent> {

    @Inject
    private App app;

    @Override
    public void onApplicationEvent(NotificationEvent e) {
        Notification n = e.notification();
        app.hall().send(n.type(), n.data());
    }

}

Notifying changes of model

Changes in domain layer can be applied to presentation layer in real time as well.

Browser

portal.find("/entity").on("account#" + id, function(model) {
    console.log(model);
});

Server

@Entity
public class Account extend Model {

    @PostUpdate
    public void updated() {
        App.find("/entity").room("account#" + id).send("updated", this);
    }

}

Type conversion of event data

Event data can be object and be converted to the specific type based on JSON format.

Browser

portal.find().send("account.save", {username: "flowersinthesand", email: "flowersinthesand@gmail.com"});

Server

@Bean
public class AccountHandler {

    @On("account.save")
    public void save(@Data Account account) {
        account.save();
    }

}

Retrieving data

Using reply callback, the client can retrieve data from the server asynchronously like AJAX.

Browser

portal.find("/band")
.send("find", 45, function(band) {
    console.log(band);
})
.send("query", query, function(bands) {
    console.log(bands);
});

Server

@Bean
public class BandHandler {

    @On
    @Reply
    public Band find(@Data Long id) {
        return Band.byId(id));
    }
    
    @On
    public void query(@Data String query, @Reply final Reply.Fn reply) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    reply.done(query...list);
                } catch (EntityException e) {
                    reply.fail(e);
                }
            }
        })
        .start();
    }

}

Calling a service bean method remotely

Service bean can be executed directly via the portal.

Browser

portal.find("/account")
.send("find", 23, function(account) {
    console.log('found');
    console.log(account);
}, function(error) {
    console.log(error.type + ":" + error.message);
})
.send("remove", 45, function() {
    console.log('deleted');
}, function(error) {
    console.log(error.type + ":" + error.message);
});

Server

@Bean
@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountDao dao;
    
    @Override
    @On
    @Reply
    public Account find(@Data long id) throws EntityNotFoundException {
        return dao.find(id);
    }

    @Override
    @On
    @Reply(failFor = EntityNotFoundException.class)
    public void remove(@Data long id) {
        dao.remove(id);
    }
    
}

About

The server counterpart of the Portal written in Java

Resources

Stars

Watchers

Forks

Packages

No packages published