How to run the example from Custom Unit Guide?

11 Jan '13, 02:25 PM
16,765 Views
No Forum Badges

I try to run the example http://wiki.webratio.com/index.php/Custom_Unit_Guide. I followed exactly the given sample and created the Custom Unit:

I defined input, output and logic templates like suggested in the example and I made a copy and paste for the java class HttpClientUnitService. Now I can add this custom unit in the view of my projects. But I have no idea how to use it.

1.) What could be the source unit of the incoming link for the Custom Unit?

2.) Which parameter I have to couple?

3.) If I try a link, just from any unit, to this Custom Unit coupling only offers to couple URI (defined in the input.template). But from where a coming the values for Host, Method, Port and Parameters?

4.) And at the end I have no Idea how to show the potential (xml formatted) output of the called servlet.

Greetings, Ralf

 
x 0
Follow
Answer Answer at this question and get points!
Forum Hero - Level 9

Hi,

referring to your questions:

1) Yes, you can retrieve the required inputs by another unit like a Selctor Unit and set them on the input Link. Moreover you can set the "uri" directly on the Coupling of the input Link by writing the url. In this example the Host, Port and Method Parameters are defined as Properties (related to the unit) that can be setted in the Properties View and not on the input Link.

2) In this example all input parameters are mandatory in fact you can see the true value in the declaration section in the class. The "parameter" item is not required.

    host = DescriptorHelper.getChildValue(descr, "Host", true, this);
    port = DescriptorHelper.getChildValue(descr, "Port", true, this);
    method = DescriptorHelper.getChildValue(descr, "Method", true, this);
    responseType = DescriptorHelper.getChildValue(descr, "ResponseType", true, this);
    Element parametersElement = DescriptorHelper.getChild(descr, "Parameters", true, this);
    parameters = DescriptorHelper.getChildValues(parametersElement, "Parameter", false, this);

3) As reported in the 1# point the Host, Port and Method Parameters are defined as Properties so you can't see them as Parameters on the input Link.

4) In order to manage the response you can refer to the dom4j API and consider the Node interface and the asXML method.

Moreover you can follow the "Create the hello world custom unit" Tutorial (Help -> Web Modeling Tutorials)

   
x 0
Forum Starter - Level 2

Hi Ralf,

I'm going down the same road as you so this is not so much an answer as a corroboration. I haven't succeeded yet, but I have made some progress I will share. So for your questions:
1) - I think it needs to be a selector unit or maybe a script unit that queries the HttpServlet context to get those values. Unless they are returned using Ajax from the client site?
2) - You would then have each of the parameters that you can couple to each of these input.template parameters.
3) - Sadly the input.template example on has the URI parameter declared. My example is different but you need to declare each of the input parameters there. Eg:

<InputParameter name="<%= unitId%>.uri" type="" label="URI"/>
<InputParameter name="<%= unitId%>.host" type="" label="Host"/>
<InputParameter name="<%= unitId%>.port" type="" label="Port"/>
<InputParameter name="<%= unitId%>.method" type="" label="Method"/>

4) - Yep, I'm stumped too

The example in the Guide is difficult because it uses attributes and variables that don't help much for the input.template example.

The example in the input.template is:

<inputparameter name="&lt;%= unitId%&gt;.name" type="ent6.attr26.single" label="Name" &gt;<="" p="">

I hate when variables are "Name" or "value" because you can't tell if it's a reserved word (a.k.a attribute or property) or user defined variable. I used the example below.

(Missing the first "<")
InputParameter name="<%= unitId%>.SignOid" type="ent6.attr26.single" label="Select Sign"/>

I suspect your seeing the URI meant you saw the same? My version exposed a Coupling link of "Select Sign" and was accessible in the logic.template using "SignOid" as per the code below.

(Missing the first "<")
% setXMLOutput() def unitId = unit["id"] def params = unit.selectNodes("SignOid") %>

I write the "params" out to <parameters> nodes as per the example, but still have problems accessing them in the (moduleName)Service.java class. I used the same code as the Guide and my SignOid parameters List has a single entry. The value is:

params:com.webratio.commons.dom.FastElement@2a5219c3 [Element: <parameters attributes:="" []=""/>] userData: null

That's where I'm stuck. Did you get any further with your example?

 
x 0
Forum Starter - Level 2

Hi I just thought I'd add this (same as my question on "Custom Unit") because it can help stop some frustration.

If you start by building the Hello World Unit tutorial you need to be careful. The Custom Unit Guide page has different parameter names for the HttpClientUnitService.java file. The BeanHelper method above must go in the execute() method (not the constructor) but the Map parameter name for the first parameter is different to the Guide. I had to use:


String theHost = BeanHelper.asString(pageContext.get(getId() + ".Host"));
instead of:
String theHost = BeanHelper.asString(operationContext.get(getId() + ".Host"));

 
x 0
Answer at this question and get points!

Related questions

Ayuda Simple List Component Layout personalizado Button to go on another page Criptare dati sensibili nel database CSV Component with utf8 encoding Custom components Custom descriptors Custom Plug-in Custom Time Unit Custom Unit and AJAX / SOAP Custom Unit: Difficult example in Guide ... any suggestions? Data flow from a page which is not visible anymore Dynamic link labelling for Custom Unit Encoding Confirm Dialog file analysis then update MySQL database Google Map Unit Guardar Saltos de LINEA How can I add a credit card payment gateway or integrate paypal in my web app logic? how can i open a pdf file using download dialog How complex can Custom Unit output be? Is there any custom unit store or repository? Do you create/sell custom units? java.lang.NullPointerException More Custom Unit questions: example of Content and Operation Unit? Need help with Landmark Overlays for Google Map Unit. Personalizzazione del login component Problema Invocation Unit Problems with Custom components: Can't get values from output parameters on ok flow. "Run Now" on a job scheduled to run later Selezione sul giorno "Events Planning" Status ProcessInstance and activityInstance in spanish Stored procedure component Twitter Unit - Get Geo location of twitt Usage of the Gantt Unit ¿Visor de imágenes y reproductor de video para la versión 7.2? Image viewer and video player for version 7.2? Web project without initial login form - how to create custom logins? Webratio Add-ons no permite login Webratio don't recognize JSON library WebRatio Platform 7.2 Community Cloud Edition