Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1. Introduction
NextGen NMS, or OmniVista 4.1.1, is a network management system. NG NMS uses
AngularJS as framework at client side and uses Spring as framework at server side.
Server
(Service-Based)
Client
(Web-Based)
HTML5 + CSS3
JSON
REST
AngularJS
Spring MVC
MOM
(Message-Oriented Middleware)
MongoDB
Headless Client (OV Client)
RMI
OV 2500
At server side, we have 3 important components: AppServer, Framework and
Services.
-
APP Server
Requests
DB
Controllers
Controllers will expose the REST APIs so that web GUI can request or set data.
We will base on Spring MVC component and Servlet 3 for this purpose. An
example API look like:
@RequestMapping(method = RequestMethod.GET, value = "/licenses",
produces="application/json")
@ResponseBody
public DeferredResult<NGServerResponse> getLicenses(HttpServletRequest
request, HttpServletResponse response){
DeferredResult<NGServerResponse> dr = new
DeferredResult<NGServerResponse>();
ServiceRequest<String> serviceRequest = new ServiceRequest<String>();
serviceRequest.setOperation(NGServerUtils.READ_ALL);
serviceRequest.setServiceName(NGServerUtils.getServiceName
(request.getRequestURL()));
serviceRequest.setRequestType(NGServerUtils.ASYNC_SINGLE);
serviceRequest.setTarget(TARGET_PROCESSOR);
m_processor.processAsyncRequest(dr, serviceRequest);
return dr;
}
GUI
Controller
RequestProcessor
ISyncService
- Implement processRequest m
3.1.1.Controller Implementation
Introduce your own controller class in com.alu.ov.ngnms.appserver.controller
package. Below is an example GET method:
@Autowired
private IRequestProcessor m_processor;
/****************Sync*****************/
@RequestMapping(method = RequestMethod.GET, value = "/syncexample")
@ResponseBody
public NGServerResponse getExample(HttpServletRequest request,
HttpServletResponse response) {
ServiceRequest<ObjectExample> serviceRequest = new
ServiceRequest<ObjectExample>();
serviceRequest.setOperation(NGServerUtils.READ_ALL);
serviceRequest.setServiceName(NGServerUtils.getServiceName(
request.getRequestURL()));
NGServerResponse sr = m_processor.processSyncRequest(serviceRequest);
return sr;
}
Notes:
3.2.
GUI
- Listen to requests with POST/PUT/GET type.
- Call RequestProcessor.processAsyncRequest method to p
- Result is DeferredResult type
Controller
- Base on the service name (registered on the context file), it will call to
- Dont implement this. This class belongs to App Server framework.
- Call processResponse method.
RequestProcessor
IMessageListener
3.2.1.Controller
- Initialize IRequestProcessor variable to call processASyncRequest function of
RequestProcessor class.
- Initialize ServiceRequest variable and set its properties.
- Initialize DeferredResult variable to store received result.
- Example:
private static final String TARGET_PROCESSOR = "exampleMessageProcessor";
@Autowired
private IRequestProcessor m_processor;
3.2.2.IAsyncService Implementation
We have to implement 2 methods: processRequest and onMessage. In
processRequest method, we call MessageListener.postRequest to post the request
to processor. Inside onMessage method we call RequestProcessor.processResponse
to send the result to the client.
private IRequestProcessor m_requestProcessor;
private IMessageListener m_messageListener;
public AsyncExampleServiceImpl(IRequestProcessor requestProcessor,
IMessageListener messageListener){
m_requestProcessor = requestProcessor;
m_messageListener = messageListener;
}
@Override
public void processRequest(ServiceRequest serviceRequest)
throws NgnmsServiceException {
m_messageListener.postRequest(serviceRequest);
}
@Override
public void onMessage(ServiceResponse serviceResponse)
throws NgnmsServiceException {
m_requestProcessor.processResponse(serviceResponse);
}
3.2.3.ITargetMessageProcessor implementation
You have to implement the processMessage method to process the request and
build the result to send back to the client.
public void processMessage(ServiceRequest serviceRequest) throws
NgnmsServiceException;
After you have the result, you need to use MessageListener to send the
response. An example:
ServiceResponse<String> result = new ServiceResponse<String>();
result.setCorrelationID(requestContent.getRequestID());
result.setFinal(true);
result.setRequestType(requestContent.getRequestType());
result.setServiceName(requestContent.getServiceName());
String data = "";
Object status = response.getProperty(ExampleResponseType.STATUS);
if (status != null && "success".equals(String.valueOf(status))) {
try {
data = response.getBody(new TypeReference<String>() {});
} catch (NGMessagingException e) {
Note: the key string must match with the target string in
ServiceRequest object (see Controller).
3.3. Asynchronous Multiple Responses Service
The code flow is same with Asynchronous Single Response Service. We have some
differences:
3.3.1.Controller
Instead of using DeferedResult to post the response, we use AsyncContext of
Servlet:
private static final String TARGET_PROCESSOR = "exampleMessageProcessor";
@Autowired
private IRequestProcessor m_processor;
@RequestMapping(method = RequestMethod.GET, value = "/examples",
produces="application/json")
@ResponseBody
public void get2Example(HttpServletRequest request, HttpServletResponse response){
AsyncContext asyncContext = request.startAsync(request, response);
ServiceRequest<String> serviceRequest = new ServiceRequest<String>();
serviceRequest.setOperation(NGServerUtils.READ_ALL);
serviceRequest.setServiceName(NGServerUtils.getServiceName(
request.getRequestURL()));
serviceRequest.setRequestType(NGServerUtils.ASYNC_MULTI);
serviceRequest.setTarget(TARGET_PROCESSOR);
}
m_processor.processAsyncRequest(asyncContext, serviceRequest);
3.3.2.ITargetMessageProcessor Implementation
Because we have multiple parts, we need to set a flag to the ServiceResponse
object so that the client can determine a part is final or not. For example:
ServiceResponse<String> result = new ServiceResponse<String>();
result.setData(ngMessagePart.getBody(new TypeReference<String>(){}));
result.setCorrelationID(requestContent.getRequestID());
result.setRequestType(requestContent.getRequestType());
result.setServiceName(requestContent.getServiceName());
if (result.getData().equals("49")) {
result.setFinal(true);
} else {
result.setFinal(false);
}
m_mesageListener.postResponse(result);
GuideLine-Messaging
Framework.docx