Skip to content

Messaging API and templating engine

JGuillemotte edited this page Feb 2, 2012 · 12 revisions
  • Messaging API :

This API contains classes to store HTTP messages and exchange records (See https://github.com/easysoa/EasySOA/tree/master/easysoa-registry/easysoa-registry-api/easysoa-registry-api-messaging).

HTTP Message is used to build a java reprensentation of an HTTP message so it contains all the informations concerning the request and the response. The HTTP Discovery proxy is the main user of the HTTP Messages. Exchange record objects are used to store the HTTP messages, they are completed with an id and can be regrouped in a store.

There is a persistence layer in this API to store and retrieve Exchange record stores. The ExchangeRecordFileStore is an implementation of the ExchangeRecordStoreManagerItf to store Exchanges records on the file system. (See https://github.com/easysoa/EasySOA/blob/master/easysoa-registry/easysoa-registry-api/easysoa-registry-api-messaging/src/main/java/org/easysoa/records/persistence/filesystem/ExchangeRecordFileStore.java)

  • Templating engine

The goal is to templatize requests (and/or responses) from stored exchange records and to replay them, for instance for test purposes or to detect modifications. The engine is composed of several components.

Correlation service : This service make an analysis of the exchange request to define the most interessant fields. It is working with a correlation mechanism, comparing the request with the response. When a common field is found, it is tagged as suggested field. These suggested fields are used in the template to allow the user to provide custom values. (see https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/records/correlation/CorrelationService.java)

TemplateBuilder : Builds a template from the field suggested by the correlation service and the exchange record. This template is mad with Velocity. Each suggested field is replaced in the request by a velocity expression (eg : $arg2.get("key"). Then, this 'custom' exchange is stored and can be used by the TemplateRenderer. (see https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/template/TemplateBuilder.java)

TemplateRenderer : Render a template by replacing the template expressions by the provided values. Then the result can be used by the tamplate executor. (see https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/template/TemplateRenderer.java)

TemplateExecutor : Execute the rendered template (send the request, using the utility class RequestForwarder) and returns the response. (see https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/java/org/easysoa/template/TemplateExecutor.java)

  • Custom ProxyImplementationVelocity class (TODO : this is a hack, these work has to be included in Frascati distribution).

The proxyImplementationVelocity is modified to work with the TemplateRenderer. The velocity engine is configurated to work with an interface and a class instead of a servlet. See the HTTP Discovery proxy composite file, especially the code concerning the ProxyWSTemplate component (https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy/src/main/resources/httpDiscoveryProxy.composite)

  • Custom ServletImplementationVelocity class (TODO : this is a hack, these work has to be included in Frascati distribution).

This class has been modified to provide Easysoa custom features :

  • Returns the list of exchange stores when a request ending by "/target" is received. The list is returned as an HTML page.
  • Returns a WDSL corresponding to the records contained in an exchange store. The WSDL file is generated by loading and processing a pre-defined template.
  • Test to show how the classes work together :

It is available in the proxy-core-tests project (See https://github.com/easysoa/EasySOA/blob/master/easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-tests/src/test/java/org/openwide/easysoa/tests/ScenarioTest.java) and works with the HTTP Discovery proxy and the UI Scaffolding proxy. This test start a run, execute some REST requests, stop and store the run. Then a replay test is performed with the recorded exchanges, followed by the generation of requests/responses template for the test exchange store. When the template generation is done, the WSDL generation for the store is called and passed to the UI Scaffolding proxy to get an HTML form.

If the test method 'testWaitUntilRead' is enabled, the list of exchange record store is avaible at "http://localhost:8090/runManager/target/". The page show a list of links on WSDL files corresponding to each exchange record stores.

To get the HTML form generated from a WSDL, browse at "http://localhost:8090/scaffoldingProxy/?wsdlUrl=". The wsdlUrl parameter must be completed with the url of the WSDL file to transform. (eg : "http://localhost:8090/scaffoldingProxy/?wsdlUrl=http://localhost:8090/runManager/target/Twitter_test_run?wsdl").

Clone this wiki locally