<subsystem xmlns="urn:jboss:domain:resource-adapters:1.0"> [...] <resource-adapters> <resource-adapter> <archive>teiid-connector-ws.rar</archive> <transaction-support>NoTransaction</transaction-support> <connection-definitions> <connection-definition class-name="org.teiid.resource.adapter.ws.WSManagedConnectionFactory" jndi-name="java:/habrDS" enabled="true" use-java-context="true" pool-name="habr-ds"><!-- [1] --> <config-property name="EndPoint">http://habrahabr.ru/api/profile/</config-property><!-- [2] --> </connection-definition> </connection-definitions> </resource-adapter> </resource-adapters> [...]
There are 2 important points: in the line marked [1] we set the JNDI name of our data source (we will use this name later), and in the line marked [2] - end point - the URL of our service. <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <vdb name="habr" version="1"> <model name="habr"> <source name="habr" translator-name="rest" connection-jndi-name="java:/habrDS"/> </model> <model name="habrview" type="VIRTUAL"> <metadata type="DDL"><![CDATA[ CREATE VIRTUAL PROCEDURE getHabr(name varchar) RETURNS (login varchar(128), karma float, rating float, ratingposition long) AS select ha.* from (call habr.invokeHTTP(action => 'GET', endpoint =>querystring(name))) w, XMLTABLE('habrauser' passing XMLPARSE(document w.result) columns login varchar(128) PATH 'login', karma float PATH 'karma', rating float PATH 'rating', ratingposition long PATH 'ratingPosition') ha; CREATE VIEW Habr AS select * FROM habrview.getHabr; ]]> </metadata> </model> <translator name="rest" type="ws"> <property name="DefaultBinding" value="HTTP"/> <property name="DefaultServiceMode" value="MESSAGE"/> </translator> </vdb>
/>
- a way to describe a new translator through inheritance (type is the name of the parent translator, name is the name of the newly created translator). This method is intended so that you can set the value of properties (properties) that are different from the default values. Because the default property is DefaultBinding = SOAP12
, then we cannot directly use the ws translator./>
serves to connect our habrDS data source (we described it above in standalone.xml ) and the newly created ' rest ' translator. Thus, when calling habr.invokeHTTP()
we call the translator with specific parameters and the given URL of the web service./>
: the fact is that we can only describe database entities through DDL in models with type="VIRTUAL"
, on the other hand, we can only specify data sources and translators in non -virtual models, and we need both that, and another.getHabr
, for which we describe the input parameter and results, and which is implemented via a SELECT query, which, in turn, calls habr.invokeHTTP()
to execute a GET request to the web service (with assignment of the result). alias w
). Here the name
parameter is passed from the virtual procedure to the real one. habr.invokeHTTP()
returns the received data in the result parameter, which is then passed to the XMLPARSE(document w.result)
built-in function XMLPARSE(document w.result)
, where document
means that it is well-formed XML, and not a fragment. This function parses the received data and already in the form of an XML tree passes on to the XMLTABLE
function, for which we, like for the virtual procedure, specify a list of columns indicating types, and in addition to types we also indicate the ways in which the values will be get from the XML document. 'habrauser'
means base path. select * from habrview.habr where name='elfuegobiz'
Source: https://habr.com/ru/post/150765/
All Articles