JLupin Next Server provides its own model of message processing via the HTTP protocol and the JSON language.

The flow of the message with the conversion of the JSON-JAVA-JSON objects is shown in the following pattern:

Calling a service via web service – HTTP-JSON is very easy. No programming works are needed to add many unnecessary interfaces and descriptors. For better understanding of web service model available via HTTP and JSON language, let’s take a look at the below example.

As usual, we create service interface:

public interface DigestService {
    String getMD5Digest(String name, String surname) throws Throwable;
}

Implementation:

package com.jlupin.sampleapp.paramsfunction.service.impl;

import com.jlupin.interfaces.service.access.annotation.JLupinServiceAccessMode;
import com.jlupin.interfaces.service.access.enums.JLupinServiceAccessModeEnum;
import com.jlupin.sampleapp.paramsfunction.service.DigestService;
import org.springframework.stereotype.Service;

import java.security.MessageDigest;

@JLupinServiceAccessMode(mode = JLupinServiceAccessModeEnum.PUBLIC)
@Service("digestService")
public class DigestServiceImpl implements DigestService {

    public DigestService2Impl() {
    }

    @Override
    public String getMD5Digest(String name, String surname) throws Throwable {
            String stringToDigest = name+surname;
            MessageDigest  messageDigest = MessageDigest.getInstance("MD5");
            byte [] buffer = stringToDigest.getBytes();
            messageDigest.update(buffer);
            byte [] digestBuffer  = messageDigest.digest();
            return byteToHex(digestBuffer);
    }

    private String byteToHex(byte in[]) {
        byte ch = 0x00;
        int i = 0;
        if (in == null || in.length <= 0) {
            return null;
        }
        StringBuilder out = new StringBuilder(in.length * 2);

        while (i < in.length) {
            ch = (byte) (in[i] & 0xF0);
            ch = (byte) (ch >>> 4);
            ch = (byte) (ch & 0x0F);
            out.append(pseudo[ (int) ch]);
            ch = (byte) (in[i] & 0x0F);
            out.append(pseudo[ (int) ch]);
            i++;
        }
        return out.toString();

    }

    private char pseudo[] = {'0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
}

Our example will use configuration by annotations provided by Spring. Our class will be available under the name of "digestService" – Spring annotation:

@Service("digestService")

Adding annotation:

@JLupinServiceAccessMode(mode = JLupinServiceAccessModeEnum.PUBLIC)

Informs the server that this class must be available outside as a service. Class and interface is compiled and digestMicroservice.jar file is created. Ok then, if we have our code written, we need to configure it and place on the server. Create Spring configuratgion file: (spring-services.xml).

Content:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <import resource="spring-default-configuration.xml"/>

    <context:annotation-config/>
    <context:component-scan base-package=" com.jlupin.sampleapp.paramsfunction.service.impl"/>
</beans>

In the above file, we import a file with classes provided by default with the server and we also determine a package with our service class. Our configuring file must import the file with default classes provided by JLupin, and they are in spring-default-configuration.xml file. We create an example to jar file – it will include class files and spring configuration file. We add our new microservice to the server configuration or we add another service within existing microservice, we send commands on appStart sampleMicroservice and try to call our service (in this example, microservice will be named "sampleMicroservice", the service will be available as "digestService"). All web services for http-JSON protocol are available at the following URL address (default server configuration):

http://127.0.0.1:8083/jLupinNextServerRestService/JLupinRestservice

Input:

{
  "jLupinInputParameter": {
    "applicationName": "sampleMicroservice",
    "locale": "pl",
    "methodName": "getMD5Digest",
    "privilegeList": [ "privilege_1", "privilege_2" ],
    "requestId": "request_1",
    "serviceName": "digestService",
    "sequenceName":"sampleParamArrayJsonInOutSequence",
    "paramArray":["java.lang.String:\"jon\"","java.lang.String:\"mcdowell\""],
    "sessionId": "session_1",
    "user": "test_user",
  }
}

Output:

{"jLupinOutputParameter": {
   "result": "50382149719ab04e47a966ad959f4241",
   "executedServiceError": false
}}

All web services for http-JSON protocol are available at the following URL address (default server configuration). And that’s all. JLupin Next Server automatically calls many access interfaces, including the mentioned web service interface – http – json .

Let’s note the most important issues:

  1. Encoding input parameters to the service – in "paramArray"
  2. Encoding corresponds to the format that is generated via Jackson mechanism https://github.com/FasterXML/jackson
  3. As a result of "jon" string coding, we receive json in a form of: "jon"
  4. As a result of "mcdowell" string coding, we receive json in a form of: "mcdowell"
  5. Before every parameter we provide the full qualified class name and then we add a colon and the encoded parameter. And we receive: "java.lang.String:"jon""
  6. Parameters are separated with a coma, and we receive: "java.lang.String:"jon"","java.lang.String:"mcdowell""
  7. ParamArray element itself is a board according to JSON language, so it looks as follows: "paramArray":["java.lang.String:"jon"","java.lang.String:"mcdowell""]

Input parameter developed this way will be decoded by a sequencer sampleParamArrayJsonInOutSequence (this name is included in "sequenceName" – this sequencer is provided by JLupin) and input objects ("jon", "mcdowell" ) will be changed to JAVA objects (via Jackson mechanism (that’s why we provide a class name) ) and submitted to getMD5Digest function. sampleParamArrayJsonInOutSequence sequencer is again responsible for output parameter encoding from getMD5Digest function. For output parameter encoding this sequencer uses Jackson mechanism and it will be sent in the result element:

{"jLupinOutputParameter": {
   "result": "50382149719ab04e47a966ad959f4241",
   "executedServiceError": false
}}

Programmer receiving a message will be responsible for message transformation to an object specific for the language/platform.