JLupin Next Server provides a mechanism of sequencers.

The mechanism of sequencers allows making several services (JAVA class) and their methods in a determined order.

Of course, at this point a question arises - how to create several services with different methods, different parameters, different results returned - how will the sequential engine know how to send various parameters to a specific class, how to send a return object of a given class and send it to the next one? The answer is - it will not know :). We need to tell it what to do.

AFTER START SERVER YOU CAN GENERATE INPUTS BELOW AND TESTS THEM

We tell it through configuration. Let us start with the interface of the sequencer.

package com.jlupin.interfaces.service.sequence;

public interface JLupinParamArraySequence {
     public Object [] sequence(Object...args) throws Throwable;
}  

When JLupinServiceProcessor (more about it in the chapter on JLupinServiceProcessor) detects that it has to execute the instance of the JLupinParamArraySequence, it transfers the control to the interface. In this document we will focus on a default implementation of the JLupinParamArraySequence interface which is JLupinNamedMethodWithParamArraySequencerImpl. The sequencer allows performing different methods with different parameters.

The sequencer of this type is best suited to convert objects from a given data transfer protocol (e.g. WEB SERVICE - XML, HTTP-JSON) to Java objects and back.

In the first part of the following example, we will show how to use the sequencer to translate an XML message (sent using SOAP protocol) to perform a specific Java code and then return the reply in the XML language using SOAP-WebService. In the second part we will show how to use the sequencer to translate a JSON message (sent using the HTTP protocol) to perform a specific Java code and then return the reply in the JSON language using the HTTP protocol.

NOTICE ! All sequencers are available in default configuration file: spring-jlupin-default-configuration.xml

The file is contained in catalogue SERVER_HOME/server-resources, content of this file:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

    <bean id="jLupinAccessServices" class="com.jlupin.interfaces.service.access.enums.JLupinServiceAccessModeEnum"
          factory-method="valueOf">
        <constructor-arg>
            <value>PUBLIC</value>
        </constructor-arg>
    </bean>

    <bean id="jLupinMessageProducer"
          class="com.jlupin.impl.producer.service.errormessage.JLupinDefaultErrorMessageProducerImpl">
        <constructor-arg index="0" type="java.lang.String[]" value="messages, global_messages"/>
        <constructor-arg index="1"><ref bean="locale"/></constructor-arg>
        <constructor-arg index="2" type="java.lang.String" value="ISO-8859-1"/>
        <constructor-arg index="3" type="java.lang.String" value="UTF-8"/>
    </bean>

    <bean id="jLupinServiceExceptionHandler"
          class="com.jlupin.impl.handler.service.JLupinDefaultServiceExceptionHandlerImpl">
        <constructor-arg index="0"><ref bean="jLupinMessageProducer"/></constructor-arg>
    </bean>

    <bean id="locale" class="java.util.Locale">
        <constructor-arg index="0" type="java.lang.String" value="en"/>
    </bean>

    <!-- XML defaults converters -->
    <bean id="jLupinXMLToObjectParamArraySequenceImpl"
          class="com.jlupin.impl.service.converter.xml.paramarray.JLupinXMLToObjectParamArraySequenceImpl">
    </bean>

    <bean id="jLupinObjectToXMLParamArraySequenceImpl"
          class="com.jlupin.impl.service.converter.xml.paramarray.JLupinObjectToXMLParamArraySequenceImpl">
    </bean>

    <!-- JSON defaults converters -->

    <bean id="jLupinJsonToObjectParamArraySequenceImpl"
          class="com.jlupin.impl.service.converter.json.paramarray.JLupinJsonToObjectParamArraySequenceImpl">
    </bean>

    <bean id="jLupinObjectToJsonParamArraySequenceImpl"
          class="com.jlupin.impl.service.converter.json.paramarray.JLupinObjectToJsonParamArraySequenceImpl">
    </bean>

    <bean id="jLupinSampleObjectToXmlService" class="com.jlupin.impl.service.converter.xml.service.JLupinObjectToXMLServiceImpl">
    </bean>

    <bean id="jLupinSampleXmlToObjectService" class="com.jlupin.impl.service.converter.xml.service.JLupinXMLToObjectServiceImpl">
    </bean>

    <bean id="sampleXmlInOutSequence" class="com.jlupin.impl.service.sequencer.JLupinDoServiceSequencerImpl">
        <constructor-arg>
            <list>
                <ref bean="jLupinSampleXmlToObjectService" />
                <value>X{1}</value>
                <ref bean="jLupinSampleObjectToXmlService" />
            </list>
        </constructor-arg>
    </bean>

    <bean id="sampleParamArrayXmlInOutSequence" class="com.jlupin.impl.service.sequencer.JLupinMultiParamsNamedMethodWithParamArraySequencerImpl">
        <constructor-arg>
            <list>
                <ref bean="jLupinXMLToObjectParamArraySequenceImpl" />
                <value>X{1}</value>
                <ref bean="jLupinObjectToXMLParamArraySequenceImpl" />
            </list>
        </constructor-arg>
    </bean>

    <bean id="sampleParamArrayJsonInOutSequence" class="com.jlupin.impl.service.sequencer.JLupinMultiParamsNamedMethodWithParamArraySequencerImpl">
        <constructor-arg>
            <list>
                <ref bean="jLupinJsonToObjectParamArraySequenceImpl" />
                <value>X{1}</value>
                <ref bean="jLupinObjectToJsonParamArraySequenceImpl" />
            </list>
        </constructor-arg>
    </bean>

    <bean id="jLupinProxyFactory" class="com.jlupin.impl.proxy.factory.JLupinProxyFactory"/>

</beans>

All application spring definition file must import this file if want use server functionality

1. WEBSERVICE-SOAP-XML

Configuration:

1.1 Definition of input/output converters

<!-- XML defaults converters -->
<bean id="jLupinXMLToObjectParamArraySequenceImpl"
       class="com.jlupin.impl.service.converter.xml.paramarray.JLupinXMLToObjectParamArraySequenceImpl">
</bean>

<bean id="jLupinObjectToXMLParamArraySequenceImpl"
      class="com.jlupin.impl.service.converter.xml.paramarray.JLupinObjectToXMLParamArraySequenceImpl">
</bean>

The object available at id="jLupinXMLToObjectParamArraySequenceImpl" is part of the server distribution, and is responsible for converting an array of parameters in the form of the XML language into Java objects (using XMLDecoder).

The object available at id=" jLupinObjectToXMLParamArraySequenceImpl" is part of the distribution server, and is responsible for converting an array of parameters of Java objects to an array of parameters in the XML language (using XMLEncoder).

1.2 Definition of the JLupinNamedMethodWithParamArraySequencerImpl sequencer

<bean id="sampleParamArrayXmlInOutSequence" class="com.jlupin.impl.service.sequencer.JLupinMultiParamsNamedMethodWithParamArraySequencerImpl">
    <constructor-arg>
        <list>
            <ref bean="jLupinXMLToObjectParamArraySequenceImpl" />
            <value>X{1}</value>
            <ref bean="jLupinObjectToXMLParamArraySequenceImpl" />
        </list>
    </constructor-arg>
</bean>

In this configuration, we see a regular expression symbol "X{1}" in the sequence. Mark X{1} means that at this point the main service is to be called. What does it mean? Putting this mark in a series of planned services means that a service given in JLupinInputParameter as a variable of serviceName will be called. Let us look at the example.

Interface:

package com.jlupin.sampleapp.paramsfunction.service;

import java.util.Date;

public interface SampleParamArrayService {
    public Integer getAndResultParam(Integer i, Long l, Date date) throws Throwable;
}

Implementation:

public class SampleParamArrayServiceImpl implements SampleParamArrayService {

    protected JLupinLogger jLupinLogger;

    public SampleParamArrayServiceImpl() {
        jLupinLogger = JLupinRuntimeContainer.getInstance().getJLupinLogger();
    }

    @Override
    public Integer getAndResultParam(Integer i, Long l, Date date) throws Throwable {
        jLupinLogger.info("received integer:" + i);
        jLupinLogger.info("received long:"    + l);
        jLupinLogger.info("received date:"    + date);
        return new Integer(100);
    }
}

The service itself, apart from logging the received parameters, returns the output object, i.e. Integer(100).

Description of the sequence:

As input parameters we provide objects coded into the XML form: Integer, Long, Date.

The first service in the sequence (jLupinXMLToObjectParamArraySequenceImpl) converts the given objects from the XML form to JAVA objects.

The second service (the main one – {X1}) SampleParamArrayServiceImpl performs its function: getAndResultParam.

The third service in the sequence (jLupinObjectToXMLParamArraySequenceImpl) converts the output parameter (Integer(100)) to the XML form.

As has already been mentioned, in the above example the converters use the XMLEncoder and XMLDecoder objects. The objects can be encoded/decoded using the Jackson mechanism or other ones - only change the sequencers acting as the converters - that is implement the JLupinParamArraySequence interface - this will be shown in the second part of this chapter. So, let us call our class in the XML language using SOAP Web Service.

Pay attention to the "sequenceName" tag, which contains the name of the sequence shown above - sampleParamArrayXmlInOutSequence. The request on the server will be directed at this sequence.

Input (parameters in the "paramArray" tag are separated by the symbol ";"):

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ent="http://entrypoint.impl.jlupin.org/">
   <soapenv:Header/>
   <soapenv:Body>
      <ent:jLupinService>
         <jLupinInputParameter>
         <applicationName>firstSampleApplication</applicationName>
           <locale>pl</locale>
            <methodName>getAndResultParam</methodName>
              <privilegeList>
               <privilegeName>privilege</privilegeName>
            </privilegeList>
            <requestId>request1</requestId>
            <sequenceName>sampleParamArrayXmlInOutSequence</sequenceName>
             <serviceName>sampleParamArrayService</serviceName>
            <sessionId>session1</sessionId>
            <user>test_user</user>
             <busName>busName</busName>
             <paramArray><![CDATA[<int>10</int>;
             <long>100</long>;
             <object class="java.util.Date">
                <long>1422948308645</long>
            </object>]]>
            </paramArray>
         </jLupinInputParameter>
     </ent:jLupinService>
   </soapenv:Body>
</soapenv:Envelope>

Output (the Integer(100) object encoded to the XML form):

<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <env:Header/>
   <env:Body>
      <jlns:jLupinServiceResponse xmlns:jlns="http://entrypoint.impl.jlupin.org/">
       <jLupinOutputParameter>
        <executedServiceError>false</executedServiceError>
        <result><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
                <java version="1.8.0_45" class="java.beans.XMLDecoder">
                <int>100</int>
        ]]></result>
       </jLupinOutputParameter>
      </jlns:jLupinServiceResponse>
   </env:Body>
</env:Envelope

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

2. WEBSERVICE-HTTP-JSON

Using this sequencer we can also call any Java code using JSON messages. The only thing changed will be the converters shown above:

Configuration:

2.1 Definition of input/output converters

<!-- JSON defaults converters -->
<bean id="jLupinJsonToObjectParamArraySequenceImpl"
      class="com.jlupin.impl.service.converter.json.paramarray.JLupinJsonToObjectParamArraySequenceImpl">
</bean>

<bean id="jLupinObjectToJsonParamArraySequenceImpl"
      class="com.jlupin.impl.service.converter.json.paramarray.JLupinObjectToJsonParamArraySequenceImpl">
</bean>

2.2 Definition of sequencer

<bean id="sampleParamArrayJsonInOutSequence" class="com.jlupin.impl.service.sequencer.JLupinMultiParamsNamedMethodWithParamArraySequencerImpl">
    <constructor-arg>
        <list>
            <ref bean="jLupinJsonToObjectParamArraySequenceImpl" />
            <value>X{1}</value>
            <ref bean="jLupinObjectToJsonParamArraySequenceImpl" />
        </list>
    </constructor-arg>
</bean>

In this example, the input parameters are objects encoded to the JSON form (using Jackson): Integer, Long, Date. These variables are placed in the "paramArray" parameter in the input message as shown below.

["java.lang.Integer:1000","java.lang.Long:100","java.util.Date:1441882807117"]

The objects are encoded using the Jackson framework mechanisms. Before the ":" sign there is placed the class name. After the ":" sign there is placed the encoded value as a JSON representation of a given object.

Pay attention to the "sequenceName" tag, which contains the name of the sequence shown above - sampleParamArrayJsonInOutSequence. The request on the server will be directed at this sequence.

Description of sequence:

As input parameters we provide objects coded into the JSON form: Integer, Long, Date.

The first service in the sequence (jLupinJsonToObjectParamArraySequenceImpl) converts the given objects from the JSON form to JAVA objects.

The second service (the main service – {X1}) SampleParamArrayServiceImpl performs its function: getAndResultParam.

The third service in the sequence (jLupinObjectToJsonParamArraySequenceImpl) converts the output parameter (Integer(100)) to the JSON form.

Calling.

Input:

{
  "jLupinInputParameter": {
    "applicationName": "firstSampleApplication",
    "locale": "das",
    "methodName": "getAndResultParam",
    "privilegeList": [ "privilege_1", "privilege_2" ],
    "requestId": "req1",
    "serviceName": "sampleParamArrayService",
    "sequenceName":"sampleParamArrayJsonInOutSequence",
    "paramArray":["java.lang.Integer:1000","java.lang.Long:100","java.util.Date:1441882807117"],
    "sessionId": "sess1",
    "user": "test_user",
  }
}

Output:

{"jLupinOutputParameter": {
   "result": "100",
   "executedServiceError": false
}}

The "result" parameter contains the Integer(100) object encoded to JSON (using Jackson).

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