Saturday, January 19, 2019

2.0 Working with Citrix Virtual Channel SDK

Writing this blog to consolidate the steps involved to build Citrix virtual channel client side and server side components.

Software requirements :  Citrix Virtual channel sdk, WFAPI sdk, Visual Studio.

Install Citrix virtual channel SDK and WFAPI  sdk in your machine. Please go through the documentation that comes with Citrix sdk before proceeding with these steps, you may not need this blog at all :).. I faced a lot of challenges so decided to sum up the steps at one place and hence this blog. Virtual channel sdk comes with some pretty good examples, build one of the example using the steps mentioned in this blog. I used VS 2015 but other version will also be file. WFAPI  sdk is required to build the server side component of the example.  

Building Server side program using VS: Server side project will give an executable (.exe) file.

1. Create a new project in Visual Studio under "Visual C++" > "Empty project". Its better to follow the naming convention as suggested in documentation, append word ctx to the example name. Click Ok and this will create a blank template project.

2. Add the example source file(.c file) as an existing item into Source files folder of VS. 

3. Add paths of all the required header files in Project Properties > C/C++> General>Additional Include Directories section. 

4. To get rid of unsafe function or variable error, add _CRT_SECURE_NO_WARNINGS to Project Properties > C/C++> Preprocessor> Preprocessor Definitions section.

5. Add wfapi.lib as dependency in Project Properties > Linker>Input>Additional Dependencies section.


Building Client side program using VS: Unlike server side client side component  is a DLL file, which is a virtual driver for the application. 

1. Create a new project in Visual Studio under "Visual C++" > "Empty project". Its better to follow the naming convention as suggested in documentation, append word vd to the example name. Click Ok and this will create a blank template project. 

2. Change configuration type to Dynamic Library (.dll) under Project Properties >General> Configuration Type.

3. Add the example source file(.c file) as an existing item into Source files folder of VS. 

4. Add paths of all the required header files in Project Properties > C/C++> General>Additional Include Directories section.

5. Add vdapi.lib, clibdll.lib as dependency in Project Properties > Linker>Input>Additional Dependencies section.

6. Modify the function destinations of source file methods by adding __stdcall calling convention. Also modify calling convention of VdCallWd function in vd.h file by adding __stdcall.

7. In Source files folder of VS add new item Module-Definition File (.def) and add the below lines of code:
LIBRARY DLL_NAME
EXPORTS
     Load     @1

8. To deploy virtual driver dll add the below entries to host files.

Under the HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA
Client\Engine\Configuration\Advanced\Modules key, create a new <driver> key.
Add the following string REG_SZ values under the above key:
DriverName  =  DLL_NAME.dll
DriverNameWin16 = DLL_NAME.dll
DriverNameWin32 = DLL_NAME.dll

HKEY_LOCAL_MACHINE\SOFTWARE\Citrix\ICA
Client\Engine\Configuration\Advanced\Modules\ICA3.0 key. Append the name of the virtual
driver (<driver> created above) to the end of this line.


















Sunday, February 14, 2016

1.1 Iterate JSON Object in Apache Velocity

..in continuation with 1.0.

 If the jsonObject provides key() method. There is a slight modification in VelJSONObjectIerator method (step2 of Blog 1.0).


import java.nio.channels.UnsupportedAddressTypeException;
import java.util.Iterator;
import org.codehaus.jettison.json.JSONObject;

public class VelJSONObjectIerator implements Iterator<Object> {

    private final JSONObject jsonObject;

    private Iterator<String> iterator;

    public VelJSONObjectIerator(JSONObject jsonObject) {
        this.jsonObject = jsonObject;
        iterator = jsonObject.keys();
    }

    public boolean hasNext() {
        return iterator.hasNext();
    }

    public Object next() {
        return iterator.next();
    }

    public void remove() {
        throw new UnsupportedAddressTypeException();
    }
}


 for jsonObject = {"1":"un","2":"deux","3":"trois","4":"quatre"} 

Velocity template : 

 
#foreach ($key in $jsonObject)
   $key | $jsonObject.get($key)
#end


Output:

   1 | "un"
   2 | "deux"
   3 | "trois"
   4 | "quatre"






Friday, February 12, 2016

1.0 Iterate JSON Object in Apache Velocity

Well this is slightly json implementation (ex: gson, jettison, json) dependent solution. 

For example :
     
  • jsonObject.entrySet()  //  returns Set<Entry<String, JsonElement>> for gson 
  •  jsonObject.keys()         // returns Iterator<String>   for jettison
 So we are gonna write a Custom apache velocity Uberspector exploiting the above facts.
  1. Create a class MyUberspector which extends SecureUberspector 
import java.util.Iterator;
import org.apache.velocity.util.introspection.Info;
import org.apache.velocity.util.introspection.SecureUberspector;
import com.google.gson.JsonObject;

public class MyUberspector extends SecureUberspector {

    @Override
    public Iterator getIterator(Object object, Info info) throws Exception {
        if (object instanceof JsonObject) {
            return new VelJSONObjectIerator((JsonObject) object);
        } else {
            return super.getIterator(object, info);
        }
    }
}


 2. Create a class VelJSONObjectIerator which implements Iterator<Object>

import java.nio.channels.UnsupportedAddressTypeException;
import java.util.Iterator;
import java.util.Map.Entry;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

public class VelJSONObjectIerator implements Iterator<Object> {
    private Iterator<Entry<String, JsonElement>> iterator;

    public VelJSONObjectIerator(JsonObject object) {
        this.iterator = object.entrySet().iterator();
    }

    public boolean hasNext() {
        return iterator.hasNext();
    }

    public Object next() {
        return iterator.next();
    }

    public void remove() {
        throw new UnsupportedAddressTypeException();
    }
}


3. Set property "runtime.introspector.uberspect" to class name of MyUberspector class.


Thats it ..!!! 

 for jsonObject = {"1":"un","2":"deux","3":"trois","4":"quatre"} 

Velocity template :
 #foreach ($x in $jsonObject)
   $x.key | $x.value
#end


Output:

   1 | "un"
   2 | "deux"
   3 | "trois"
   4 | "quatre"




For  jsonObject.keys() solution, look for blog 1.1