[BAEL 1209] - Java RMI Files. (#3374)
* [BAEL 1209] - Java RMI Files. * Added parent tag and deleted dependency tag for junit. * Added java-rmi module. * Removed duplicate java-lite module entry. * Deleting this file as it is covered in test class. * Spell check.
This commit is contained in:
committed by
Grzegorz Piwowarek
parent
70e4a55256
commit
19e8849361
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.rmi;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Message implements Serializable {
|
||||
|
||||
private String messageText;
|
||||
|
||||
private String contentType;
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
public Message(String messageText, String contentType) {
|
||||
|
||||
this.messageText = messageText;
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public String getMessageText() {
|
||||
return messageText;
|
||||
}
|
||||
|
||||
public void setMessageText(String messageText) {
|
||||
this.messageText = messageText;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.rmi;
|
||||
|
||||
import java.rmi.Remote;
|
||||
import java.rmi.RemoteException;
|
||||
|
||||
public interface MessengerService extends Remote {
|
||||
|
||||
public String sendMessage(String clientMessage) throws RemoteException;
|
||||
|
||||
public Message sendMessage(Message clientMessage) throws RemoteException;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.rmi;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.rmi.registry.LocateRegistry;
|
||||
import java.rmi.registry.Registry;
|
||||
import java.rmi.server.UnicastRemoteObject;
|
||||
|
||||
public class MessengerServiceImpl implements MessengerService {
|
||||
|
||||
public String sendMessage(String clientMessage) {
|
||||
|
||||
String serverMessage = null;
|
||||
if (clientMessage.equals("Client Message")) {
|
||||
serverMessage = "Server Message";
|
||||
}
|
||||
|
||||
return serverMessage;
|
||||
}
|
||||
|
||||
public void createStubAndBind() throws RemoteException {
|
||||
|
||||
MessengerService stub = (MessengerService) UnicastRemoteObject.exportObject((MessengerService) this, 0);
|
||||
Registry registry = LocateRegistry.createRegistry(1099);
|
||||
registry.rebind("MessengerService", stub);
|
||||
}
|
||||
|
||||
public Message sendMessage(Message clientMessage) throws RemoteException {
|
||||
|
||||
Message serverMessage = null;
|
||||
if (clientMessage.getMessageText().equals("Client Message")) {
|
||||
serverMessage = new Message("Server Message", "text/plain");
|
||||
}
|
||||
|
||||
return serverMessage;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user