How to build and deploy .NET application on JLupin Next Server
Purpose
In this tutorial you will learn how build and deploy your first .NET application as microservice or SOA service on JLupin Next Server platform.
Javonet JLupin Extension
JJE is the extension module for JLNS platform version 1.2 or higher. JJE extends the capabilities of JLNS platform with the ability to host and execute .NET modules as JLNS applications.
JLupin Next Server
JLupin Next Server is an amazing application server technology for enterprise solutions covering out of the box most of the needs defined by good microservices architecture:
- Extreme performance
- Zero downtime deployments
- Built-in JVM multicontainer approach
- Simplified & scalable architecture
- Highest availability of microservices and SOA services
Read more at: JLupin Home Page
Prerequisites
Before reading further, make sure that you have installed Javonet JLupin Extension on your JLupin Next Server instance following this guide: How to install Javonet JLupin extension on JLupin Next Server.
Or use the button below to download preconfigured JLupin Next Server instance with Javonet JLupin Extension installed:
Building and Deploying First Application
To create the .NET application for JLNS platform all you have to do is create simple .NET Class Library project and provide the Microsoft Unity IoC framework configuration file which will specify which objects should be exposed for clients through JLNS platform.
Please notice that you can use any existing .NET module that expose at least one public class.
Creating .NET Application for JLNS – Step by Step Guide
This guide will show you how to build sample project that can be hosted on JLNS platform using Visual Studio 2013.
- First create the new Class Library project
- Edit you “Class1.cs” file and add new method that will sum two numbers:
- Add new XML file to your project called “unity-services.config”
- Right click on the new file and choose properties. Next set the “Copy to Output Directory” to “Copy Always”
- Now edit the content of unity-services.config file and paste following XML:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration" /> </configSections> <unity> <typeAliases> <typeAlias alias="singleton" type="Microsoft.sdncePractices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" /> <typeAlias alias="Class1Alias" type="MyJLupinApplication.Class1, MyJLupinApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> </typeAliases> <containers> <container> <types> <type name="myService" type="Class1Alias"> <lifetime type="singleton" /> </type> </types> </container> </containers> </unity> </configuration>
This is the standard Microsoft Unity IoC configuration file. The file can be either provided as separate file or compiled as embedded resources. Remember that while using the compiled embedded resource you should properly declare the file name with library namespace in JLNS application configuration file as described in 2.5.2 step 4.
Please notice two important sections. First the typeAlias where the name of your sample “Class1” type is configured. Make sure that you are always using types identified by full qualified assembly name like: MyJLupinApplication.Class1, MyJLupinApplication, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
Next please have a look at “type” registration. Currently JJE supports only the types registered with name as the name is used to identify the service in JLNS requests. Give the name for your object that you want to be exposed on JLNS platform and mark it as singleton.
Marking as singleton is optional however due to the architecture of JLNS it is recommended to use singleton for objects that will be exposed on the platform. In this way you can be sure that your object will be initialized while starting the application and will properly serve all the clients and will support the hot-redeploy failure prevention mechanism.
- Compile your project and you are ready to deploy on JLNS platform.
Deploying .NET Application on JLNS Platform
Once you have prepared your first .NET project for deployment on JLNS or you have taken your existing .NET library and defined which objects should be exposed using the unity-services.config file, you can deploy your application on JLNS.
To deploy the .NET application on JLNS platform follows these steps:
- Go to your JLNS_HOME directory and navigate to “\server\application” folder
- Create the folder for your new application called “MyJLupinApplication”
- Copy the content of your compiled .NET application with unity-service.config file to the “MyJlupinApplication” folder on JLNS.
- Go to the applications configuration folder JLNS_HOME\server\start\configuration
- Copy the sample .NET application configuration file from JJE-Package folder JLupinSampleDotNetApplicationConfigurationImpl.javaThe only difference between standard and .NET application configuration file is the definition of JLupinApplicationContainer.
As you can see on the snippet above instead of standard ApplicationContainer the JavonetSingleApplicationContainerForLocalProcessImpl container is initialized.
Additionally in the configurations array we provide two files:
- “classpath:javonet-default-configuration.xml” – this one points to the global JJE configuration file which configures JLNS to load .NET process and use .NET objects and .NET input/output converters
- “embeddedresource:unity-services.config” – this points to the unity-service.config file stored in our application folder or file compiled to your library as embedded resource. While providing file as embedded resource remember to include the library namespace in the file name declaration in example: embeddedresource:MyJLupinApplication.unity-services.config.
- Now edit the JLupinGlobalMultiProcessConfigurationImpl.java to add new entry for your application.Following entry should be appended to “getJLupinMultiProcessManager” method:
JLupinLocalServerProcessConfigurator sampleDotNetApplication = new JLupinLocalServerProcessConfigurator(); sampleDotNetApplication.setLocalServerName("localhost"); sampleDotNetApplication.setPrimaryPort(3001); sampleDotNetApplication.setSecondaryPort(3002); sampleDotNetApplication.setPrimaryCommandPort(3003); sampleDotNetApplication.setSecondaryCommandPort(3004); sampleDotNetApplication.setConnectionSocketTimeout(30000); sampleDotNetApplication.setWaitForProcessStartResponseTime(45000); sampleDotNetApplication.setWaitForProcessDestroyResponseTime(10000); sampleDotNetApplication.setPrimaryJvmOptions("-Xms128M -Xmx256M"); sampleDotNetApplication.setSecondaryJvmOptions("-Xms128M -Xmx256M"); sampleDotNetApplication.setConfigurationClassFileName("JLupinSampleDotNetApplicationConfigurationImpl.java"); jLupinDefaultMultiProcessManagerImpl.addApplicationConfiguration("MyJLupinApplication", sampleDotNetApplication);
Make sure that the name provided in last method “MyJLupinApplication” is the same as your .NET application folder on JLNS created in step 2.
- Now you are ready to start your application. Either start the whole JLNS server or if it is already running call the command “appStart MyJLupinApplication”
- You should see the confirmation of successful execution and be ready to call your service.The whole getJLupinMultiProcessManager should contain following code:
@Override public JLupinMultiProcessManager getJLupinMultiProcessManager() { JLupinLocalServerProcessConfigurator sampleDotNetApplication = new JLupinLocalServerProcessConfigurator(); sampleDotNetApplication.setLocalServerName("localhost"); sampleDotNetApplication.setPrimaryPort(3001); sampleDotNetApplication.setSecondaryPort(3002); sampleDotNetApplication.setPrimaryCommandPort(3003); sampleDotNetApplication.setSecondaryCommandPort(3004); sampleDotNetApplication.setConnectionSocketTimeout(30000); sampleDotNetApplication.setWaitForProcessStartResponseTime(45000); sampleDotNetApplication.setWaitForProcessDestroyResponseTime(10000); sampleDotNetApplication.setPrimaryJvmOptions("-Xms128M -Xmx256M"); sampleDotNetApplication.setSecondaryJvmOptions("-Xms128M -Xmx256M"); sampleDotNetApplication.setConfigurationClassFileName("JLupinSampleDotNetApplicationConfigurationImpl.java"); JLupinDefaultNewMultiProcessManagerImpl jLupinDefaultMultiProcessManagerImpl = new JLupinDefaultNewMultiProcessManagerImpl(); jLupinDefaultMultiProcessManagerImpl.addApplicationConfiguration("MyJLupinApplication", jLupinFirstSampleApplication); return jLupinDefaultMultiProcessManagerImpl; }
Calling .NET Service on JLNS
.NET applications hosted on JLNS platform are automatically exposing all objects stored in .NET DLLs and registered in unity configuration file with name for all the other services on JLNS platform and external clients through variety of different protocols like: WS-XML, WS-JSON, Java Remote Object (binary).
How to Call .NET Service Using XML
Now to make a trial call to your .NET service using XML you need to send the XML request to the JLNS server. The JLNS server is by default listening for XML requests on port 8082 at following path:
http://localhost:8082/jLupinNextServerWebService/JLupinWebservice
Use the SoapUI or other XML webservice client to send following request message to invoke your application.
<?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>MyJLupinApplication</applicationName> <locale>pl</locale> <methodName>Sum</methodName> <privilegeList> <privilegeName>privilege</privilegeName> </privilegeList> <requestId>request1</requestId> <sequenceName>javonetParamArrayXmlInOutSequence</sequenceName> <serviceName>myService</serviceName> <sessionId>session1</sessionId> <user>test_user</user> <busName>busName</busName> <paramArray><![CDATA[<int>5</int>;<int>7</int>]]></paramArray> </jLupinInputParameter> </ent:jLupinService> </soapenv:Body> </soapenv:Envelope>
Please notice following key parameters of the XML call:
Application Name
<applicationName>MyJLupinApplication</applicationName>
In “ApplicationName” you should specify the name of your JLNS application as configured in the JLupinGlobalMultiProcessConfigurationImpl.java configuration file and as your application folder is named.
Method Name
<methodName>Sum</methodName>
In “MethodName” you should specify the name of your .NET method that you want to invoke.
Sequence Name
<sequenceName>javonetParamArrayXmlInOutSequence</sequenceName>
In “SequenceName” you should specify the name of Javonet sequencer for JLupin and by default it should be set to: javonetParamArrayXmlInOutSequence.
Service Name
<serviceName>myService</serviceName>
In “ServiceName” you should specify the name of your .NET service as defined in unity-services.config file.
Param Array
<paramArray><![CDATA[<int>5</int>;<int>7</int>]]></paramArray>
In “ParamArray” tag you should provide escaped with CDATA arguments in JLNS format. The arguments should provided as XML tags separated by “;”. For complex object arguments you can provide the serialized .NET object in XML format. The first tag of the argument should contain the full qualified name of .NET type with namespace:
<CustomClassNamespace.Customer xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Name>John</Name> <LastName>Smith</LastName> <Id>9</Id> <AccountBalance>75139</AccountBalance> </CustomClassNamespace.Customer>
Calling .NET Service on JLNS with JSON
Now to make a trial call to your .NET service using JSON you need to send the JSON request to the JLNS server. The JLNS server is by default listening for JSON requests on port 8083 at following path:
http://localhost:8083/jLupinNextServerRestService/JLupinRestservice
Use the SoapUI or other JSON webservice client to send following request message to invoke your application.
{ "jLupinInputParameter": { "applicationName": "MyJLupinApplication", "locale": "pl", "methodName": "Sum", "privilegeList": [ "privilege_1", "privilege_2" ], "requestId": "request_1", "serviceName": "myService", "sequenceName":"javonetParamArrayJsonInOutSequence", "paramArray":["System.Int32:5", "System.Int32:7"], "sessionId": "session_1", "user": "test_user", } }
Param Array
In the param array input you should provide the json formatted array of input parameters. The name of the element should be the type of the argument and the value should contain the json serialized value of that argument.
The arguments can be of any .NET value type, java value-type (which will be automatically converted to .NET types) or .NET complex object serialized to Json like in this example:
"paramArray":["MyJLupinApplication.Customer:{\"Account\":4.45,\"Age\":29,\"Lastname\":\"Smith\",\"Name\":\"John\"}"],
Additional Resources and Information
For all the details regarding the JLNS platforms features, configuration and administration including the details for the application configuration files refer to JLNS documentation at:
http://jlupin.com/documentation.html
If you have any additional questions regarding the development, deployment and management of .NET applications on JLNS platform contact our support department at:
Download Links
Below you will find download links to the sources of samples included in this document and full configured JLupin Next Server with sample .NET application deployed.
Sample .NET application source code:
http://download.javonet.com/extensions/MyJLupinApplication_src.zip
Preconfigured JLupin Next Server 1.3 with JJE installed and sample .NET application deployed:
http://download.javonet.com/extensions/JLupinNexServer_v_1.3.0_JJE.zip
JJE-Package with all the binaries of JLupin Javonet Extension: