Meta

UI Scaffolder proxy

18 August, 2011 (17:08) | Technical | By Jérémie Guillemotte

Goal :

The goal of this test is to generate an html form from a wsdl service definition.

How it’s works :

First of all, the transformation will be done with a xslt file. This file describes how to make the transformation. In addition, we put in this file some javascript code to make the form usable. In this test the javascript code sends REST requests, so it doesn’t work directly because the web service works with the SOAP protocol. That’s why we use a REST/SOAP proxy to transform the REST request from the generated html form to a SOAP request for the web service.

The XSLT file (code) =>

Please see the file directly in Github, it is too long to be displayed here : wsdlToHtml.xslt

The main goal of the XSLT file is to find all the input and output fields for each operation declared in the WSDL file, then to display them in the form and add some customized javascript code to send a request, receive and display the response.

The Rest / Soap proxy works on FraSCAti. Here is the composite file (code) =>

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:frascati="http://frascati.ow2.org/xmlns/sca/1.1" xmlns:instance="http://www.w3.org/2004/08/wsdl-instance" name="RestSoapProxy">
  <component name="Proxy">
    <implementation.java class="com.openwide.sca.proxy.RestSoapProxyImpl"/>
    <service name="restInterface">
      <interface.java interface="com.openwide.sca.proxy.RestSoapProxy"/>
    </service>
    <reference name="ws">
      <interface.java interface="pureairflowers.clients.PureAirFlowersClients"/>
      <binding.ws name="webService" wsdlElement="http://clients.pureairflowers/#wsdl.port(PureAirFlowers/PureAirFlowersClientsImplPort)" instance:wsdlLocation="http://localhost:9010/PureAirFlowers?wsdl"/>
    </reference>
  </component>
  <service name="ProxyService" promote="Proxy/restInterface">
    <interface.java interface="com.openwide.sca.proxy.RestSoapProxy"/>
    <frascati:binding.rest uri="http://localhost:7001/"/>
  </service>
</composite>

In this composite, there is a component “proxy” with a reference to the web service to call and a service named “ProxyService”. This service is the link with the Generated HTML Form.

Proxy main class =>

package com.openwide.sca.proxy;

import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.osoa.sca.annotations.Reference;
import pureairflowers.clients.PureAirFlowersClients;

@Path("/")
@Produces("text/html")
public class RestSoapProxyImpl implements RestSoapProxy {

    /** Reference to the CXF PureAirFlowers web service */
    @Reference
    protected PureAirFlowersClients ws;

    /**
     * Default constructor
     */
    public RestSoapProxyImpl(){
        System.out.println("RestSoapProxy created ....");
    }

    @GET
    @Path("/")
    public Response redirectRequests(@Context UriInfo ui, @Context Request request) {
        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
        String webServiceResponse;
        if(ws == null){
            webServiceResponse = "Error : PureAirFlowers object is null !";
        } else {
            // method param
            List<String> operationParams = queryParams.get("operation");
            String operation = "";
            if(operationParams != null && operationParams.size() > 0){
                operation = operationParams.get(0);
                System.out.println("[SCA PROXY REST/SOAP TEST] operation : " + operation);
            }
            // text param
            List<String> textParams = queryParams.get("text");
            String text = "";
            if(textParams != null && textParams.size() > 0){
                text = textParams.get(0);
                System.out.println("[SCA PROXY REST/SOAP TEST] text : " + text);
            }
            // clientId param
            List<String> clientIdParams = queryParams.get("clientId");
            String clientId = "";
            if(clientIdParams != null && clientIdParams.size() > 0){
                text = textParams.get(0);
                System.out.println("[SCA PROXY REST/SOAP TEST] clientId : " + text);
            }
            // iteration param
            List<String> iterationsParams = queryParams.get("iterations");
            int iterations = 5;
            if(iterationsParams != null && iterationsParams.size() > 0){
                try{
                    iterations = Integer.parseInt(iterationsParams.get(0));
                    System.out.println("[SCA PROXY REST/SOAP TEST] iterations : " + iterations);
                }
                catch(Exception ex){
                    System.out.println("[SCA PROXY REST/SOAP TEST] iterations parameter is not valid (" + iterationsParams.get(0) + "), default value (5) used !");
                }
            }
            webServiceResponse = String.valueOf(ws.getOrdersNumber(clientId));
            System.out.println("[SCA PROXY TEST] serverResponse : " + webServiceResponse);
        }
        // Build the response to send back to the client
        return Response.ok(webServiceResponse, MediaType.TEXT_HTML).header("Access-Control-Allow-Origin", "*").build();
    }

}

In this class, the job is to get the parameters from the html form, send them in the web service and return the web service response to the form.

Conclusion :

This little test shows that it is possible to generate html forms from a WSDL definition. In EasySOA, WSDL files are registerd in Nuxeo. For each registered WSDL file in Nuxeo, there is a “call it” button. Here we are, the code produced in this test will be used with the “call it” button. Of course there is a lot of work to do to improve this code. You have probably noticed that in the test, some portions of code are hardcoded, especially in the proxy. Next step will be to change this code to obtains generic code that can works in all situations.

Complete project sources can be found on GitHub : Project sources

I find the following resources useful for the realization of this test project :

Write a comment





Couldn't connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0)