Not being able to fetch the result to log in POST API - sql

I am trying to do post api request and trying to fetch the data through SQL Query, however, I am unable to understand how to log the results. Any help would mean a lot, the code I have written is below:
<statement>
<sql><![CDATA[SELECT * FROM TEST2 t WHERE t.CORRELATION_ID = 1]]></sql>
<result column="CORRELATION_ID" name="CORRELATION_ID"/>
<result column="MSISDN" name="MSISDN"/>
<result column="FL" name="FLAG"/>
</statement>
<log level="full">
<property name="After Query" value="Below Query"/>
<property expression="get-property(FLAG)" name="FLAGG"/>
</log>
I am not getting any value in logs instead it is printing nothing as the value is given as "FLAGG = ".
Thank You

If you get data from the Database the returned values should be assigned to properties. Your Log seems to be a bit off. Can you try the following?
<log level="full">
<property name="After Query" value="Below Query"/>
<property expression="$ctx:FLAG" name="FLAGG"/>
<property expression="$ctx:CORRELATION_ID" name="CORRELATION_ID"/>
</log>

Related

WSO2 get request body using property expression

I want extract request body of a API call returning as a text.
Response from log mediator.
<?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><text xmlns="http://ws.apache.org/commons/ns/payload">**1**</text></soapenv:Body></soapenv:Envelope>
I want to extract 1 which is coming in the body. Please see the screenshot.
I have tried following it didn't work
<property expression="$body" name="api_response_status" scope="default" type="STRING"/>
Following Property Expression worked for me.
<property expression="json-eval($.text)" name="api_response_status" scope="default" type="STRING"/>

How to use apostrophe character in the fn:concat-property expression WSO2 ESB

I'm having a problem with using apostrophe character in the property expression.
I tried &apos;, \', but they were failed. So, currently I'm managing myself with defining it as another property as mentioned below.
<property value="'" name="apos" scope="default" type="STRING"/>
<property description="xpathexpr" expression="fn:concat('$ctx:hotel-static-data-rs//jsonObject/rows[id=',$ctx:apos,'hotelbeds_v3-',$ctx:hotelcode,$ctx:apos,']/value')" name="xpathexpr" scope="default" type="STRING"/>
<property description="hotel-static-data-element" expression="evaluate($ctx:xpathexpr)" name="hotel-static-data-element" scope="default" type="OM"/>
I'm sure there must be a better way to handle this. So, if anyone have a clue please update.
WSO2 ESB version : 5.0.0
Try replace apostrophe character as this example.
<property name="hotelContentExpr"
expression="fn:concat('//content[hotelcode=','"',get-property('htlCode'),'"',']')"
scope="default"
type="STRING"/>

Wrong value while using property mediator in WSO2 ESB

I have made a proxy service where the value of "Request1" property showing properly as in incoming request
<s1:PALMUpdateCatalogueRequest xmlns:s1="http://www.example.org/prodcatItemWSO2/">
<s1:updateproductCatalogueList>
<s1:catalogueinternalid>1</s1:catalogueinternalid>
ABC
<s1:itemList>
<s1:Item>
<s1:custitem_prod_cat_item>390</s1:custitem_prod_cat_item>
<s1:item_price_level>7</s1:item_price_level>
<s1:typeofitem>PQR</s1:typeofitem>
</s1:Item>
</s1:itemList>
</s1:updateproductCatalogueList>
<s1:transactionid />
</s1:PALMUpdateCatalogueRequest>
But,after calling a sequence when I am using this below expression to fetch the value of Request1,it's not showing.
What will I do to solve this issue?
<property name="REQUEST" expression="get-property('Request1')" scope="default" type="STRING"/>
You should use correct scopes to read properties. If your property is in the synapse scope, you can read it like this.
<property name="REQUEST" expression="$ctx:Request1" scope="default" type="STRING"/>

How does one access analytical views using odata?

I have an analytical view and an .xsodata to expose it to web. The question is how is the access url formed? HANA documentation is insufficient here, and the same for the moderated SCN.
Here is my func_x_cview.xsodata:
service namespace "CTag" {
"MyPackage::FUNC_X_CALC_VIEW" as "CView" keys generate local "ID"
parameters via entity "InputParams" ;
}
http://awshana:8000/package/path/to/xsodata/file/$metadata shows:
<EntityType Name="InputParamsType">
<Key>
<PropertyRef Name="ATTRIBUTE"/>
<PropertyRef Name="ATTRIBUTE_VALUE"/>
<PropertyRef Name="category"/>
<PropertyRef Name="from_date"/>
<PropertyRef Name="process"/>
<PropertyRef Name="to_date"/>
</Key>
<Property Name="ATTRIBUTE" Type="Edm.String" Nullable="false" MaxLength="50"/>
<Property Name="ATTRIBUTE_VALUE" Type="Edm.String" Nullable="false" MaxLength="100"/>
<Property Name="category" Type="Edm.String" Nullable="false" MaxLength="50"/>
<Property Name="from_date" Type="Edm.DateTime" Nullable="false"/>
<Property Name="process" Type="Edm.String" Nullable="false" MaxLength="50"/>
<Property Name="to_date" Type="Edm.DateTime" Nullable="false"/>
<NavigationProperty Name="Results" Relationship="CTag.InputParams_CViewType"
FromRole="InputParamsPrincipal"
ToRole="CViewDependent"/>
</EntityType>
What should be the access url? Does the xsodata need any tweaking?
Thanks
--EDIT--
When trying url like suggested by ongis-nade to http://awshana:8000/Pkg/Proj_X/services/tagA.xsodata/InputParams%28%27category%27=%27abcd%27%29/Results?$select=exception_name then I get an error like the following:
<error>
<code/>
<message xml:lang="en-US">
No property ''category'' exists in type 'CTag.InputParamsType'.
</message>
</error>
This is confusing as we can see a property named category in the entity named InputParamsType in the $metadata query.
Removing the single quotes around category (also tried double-quoting) gives
http://awshana:8000/Pkg/Proj_X/services/tagA.xsodata/InputParams%28category=%27abcd%27%29/Results?$select=exception_name
<error>
<code/>
<message xml:lang="en-US">
The number of keys specified in the URI at position 27 does not match number of key properties for the resource 'CTag.InputParamsType'.
</message>
</error>
So a single quote is needed.
A step closer but still the same question. Do I need to qualify each parameter name somehow?
Thanks.
I believe the URL will be formed as:
http://awshana:8000/Pkg/Proj_X/services/tagA.xsodata/InputParams(category='abcd')/Results?
The "InputParams" name is of course reflected in your service definition
I also found a good example here: http://scn.sap.com/community/developer-center/hana/blog/2013/01/22/rest-your-models-on-sap-hana-xs
May be a bit late: But you have to specify a value for each key parameter.
Note also, that timestamps must be specified in ODatas Edm.DateTime format.
Example for your service:
http://server:8080/pathToService/tagA.xsodata/InputParams(ATTRIBUTE='?',ATTRIBUTE_VALUE='?',category='?',from_date=datetime'2014-01-01T00:00:00',process='?',to_date=datetime'2014-09-01T00:00:00')/Results

How can I print SQL query result log with log4j?

I'm using Spring 3.1.1, MyBatis 3.1.1, MySQL 5.0.67. My Spring configuration is below:
<bean id="dataSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="validationQuery" value="select 1"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="14400000"/>
<property name="testOnBorrow" value="false"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/myBatisConfig.xml"/>
</bean>
<bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg ref="sqlSessionFactory"/>
</bean>
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager"
p:dataSource-ref="dataSource"/>
<tx:annotation-driven transaction-manager="transactionManager"/>
And log4.properties is below:
log4j.logger.org.springframework=DEBUG
log4j.logger.org.apache=DEBUG
log4j.logger.org.mybatis=DEBUG
log4j.logger.java.sql=DEBUG
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
log4j.logger.java.sql.ResultSet=DEBUG
With these configuration, I can see SQL query statement which is executed and parameters to that query but I can't see query result log. My log is like this:
[org.mybatis.spring.SqlSessionUtils] - Creating a new SqlSession
[org.mybatis.spring.SqlSessionUtils] - SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#4ccdd1f] was not registered for synchronization because synchronization is not active
[org.springframework.jdbc.datasource.DataSourceUtils] - Fetching JDBC Connection from DataSource
[org.mybatis.spring.transaction.SpringManagedTransaction] - JDBC Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection#3cfde82]]] will not be managed by Spring
[java.sql.Connection] - ooo Using Connection [ProxyConnection[PooledConnection[com.mysql.jdbc.JDBC4Connection#3cfde82]]]
[java.sql.Connection] - ==> Preparing: SELECT col FROM table WHERE col1=? AND col2=?
[java.sql.PreparedStatement] - ==> Parameters: 93(Integer), 4(Integer)
[org.mybatis.spring.SqlSessionUtils] - Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession#4ccdd1f]
[org.springframework.jdbc.datasource.DataSourceUtils] - Returning JDBC Connection to DataSource
Is there any way to print log including query result?
Two ways:
log4j.logger.java.sql.ResultSet=TRACE
Or use the namespaces to set logging. This is the only logging method in mybatis 3.2
http://mybatis.github.io/mybatis-3/logging.html
What works for me is:
log4j.logger.org.springframework.jdbc.core.StatementCreatorUtils=TRACE
This prints entries like these:
...
TRACE SimpleAsyncTaskExecutor-1 org.springframework.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 1, parameter value [12345], value class [java.math.BigDecimal], SQL type 3
TRACE SimpleAsyncTaskExecutor-1 org.springframework.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 2, parameter value [ADDRESS], value class [java.lang.String], SQL type 12
TRACE SimpleAsyncTaskExecutor-1 org.springframework.jdbc.core.StatementCreatorUtils - Setting SQL statement parameter value: column index 3, parameter value [20130916], value class [java.math.BigDecimal], SQL type 3
...
In my case I am using running a query inside a JdbcBatchItemWriter in a Spring Batch application, which uses named params so it may not be a general solution.