Example of using a TraceSource with Common.Logging - common.logging

I've read this question and I know its possible:
Common.Logging for TraceSource
Can someone please post an example.
Also it could be helpfull if it can be configured to use the TraceSource in code instead of using the .config file.
Thanks

If your goal is to have Common.Logging forward messages to a TraceSource, then your logger name and tracesource name have to match.
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.TraceLoggerFactoryAdapter, Common.Logging">
<arg key="level" value="ALL" />
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="dateTimeFormat" value="yyyy/MM/dd HH:mm:ss:fff" />
<arg key="useTraceSource" value="true" />
</factoryAdapter>
</logging>
</common>
<system.diagnostics>
<sources>
<source name="SomeSourceName" switchName="YourSwitch">
<listeners>
<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="Application"/>
</listeners>
</source>
</sources>
<switches>
<add name="YourSwitch" value="Information"/>
</switches>
</system.diagnostics>
</configuration>
And from code you write:
var logger = Common.Logging.LogManager.GetLogger("SomeSourceName");
Hope this helps even though the post is 2 months old and the tracesouce is setup via .config.

Related

Dynamically add new element to json payload in WSO2 EI by using enrich mediator

I need to enrich existing json payload with new elements which is dynamically passed to existing payload instead of static value. Can anyone please help me?
Existing payload:
{
"Type":"CAR",
"Identifier":"2db23c39-9d3f-4e61-b3c5-e8725a2f1b90",
"ListingType":"New",
"SaleStatus":"For Sale"
}
Expected :
{
"Type":"CAR",
"Identifier":"2db23c39-9d3f-4e61-b3c5-e8725a2f1b90",
"ListingType":"New",
"SaleStatus":"For Sale",
"messageId":"urn:uuid:ccdafb72-c4"
}
Here messageId is ESB generated MessageID automatically.
<!-- ************API Request set to incomingRequest property************ -->
<property description="incomingRequest" expression="json-eval($.)" name="incomingRequest"
scope="default" type="STRING"/>
<payloadFactory media-type="json">
<format>$1</format>
<args>
<arg evaluator="xml" expression="get-property('incomingRequest')"/>
</args>
</payloadFactory>
<enrich description="">
<source type="inline" clone="true">
<messageId xmlns="">evaluate(get-property('operation','messageId'))
</messageId>
</source>
<target action="child" xpath="//jsonObject" />
</enrich>
<enrich>
<source clone="true" xpath="//jsonObject" />
<target type="body" />
</enrich>
<log level="full"/>
**Getting Wrong output**
{
"Type":"CAR",
"Identifier":"2db23c39-9d3f-4e61-b3c5-e8725a2f1b90",
"ListingType":"New",
"SaleStatus":"For Sale",
"messageId": "evaluate(get-property('operation','messageId'))"
}
Note:
I have followed this
Inline content on the enrich mediator is not evaluated. (considered as string)
So, we can use the property mediator to evaluate the expression.
<property name="prop1" expression="get-property('operation','messageId')"/>
Then we can use the above property in enrich mediator.
<enrich description="">
<source type="property" property="prop1"></source>
<target action="child" xpath="//jsonObject" />
</enrich>
BTW, In latest product versions, the Enrich mediator has the native JSON support.
More details in Here
I had similar scenario where i wanted to append some elements to a received json response:
First i got the response received into a property:
property expression="json-eval($)" name="RESPONSE" scope="default"
type="STRING"
Then i created a payload and added the new properties:
<payloadFactory media-type="json">
<format>
{"details": $1,
"timestamp":"$2",
"value":"$3"}
</format>
<args>
<arg evaluator="xml"
expression="get-property('RESPONSE')" />
<arg evaluator="xml"
expression="get-property('REQUEST_TIMESTAMP')" />
<arg evaluator="xml"
expression="get-property('VALUE')" />
</args>
</payloadFactory>
Then I returned the response using loopback. Note that REQUEST_TIMESTAMP and VALUE are defined as properties.

Trouble using two different databases in Mule JDBC flow

I have two JDBC flows in Mule 3.2.0, one using MySQL database and other using SQLServer database.
<mule ...
<spring:bean id="MySQL-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName"
value="com.mysql.jdbc.Driver" />
<spring:property name="url"
value="jdbc:mysql://host:port/schema" />
</spring:bean>
<jdbc:connector name="MySQL-jdbcConnector"
dataSource-ref="MySQL-jdbcDataSource" pollingFrequency="${MySQL.db.poll}"
transactionPerMessage="false">
<jdbc:query key="read" value="${MySQL.db.jdbc_query}" />
</jdbc:connector>
<flow name="MySQL-flow">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="MySQL-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN"/>
<property key="receiveMessageInTransaction" value="true"/>
</jdbc:inbound-endpoint>
<vm:outbound-endpoint path="path" connector-ref="first-level">
<message-properties-transformer scope="outbound">
<add-message-property key="identifier" value="MySQL"/>
</message-properties-transformer>
<vm:transaction action="NONE"/>
</vm:outbound-endpoint>
</flow>
</mule>
And
<mule ...
<spring:bean id="SQLServer-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<spring:property name="url"
value="jdbc:sqlserver://host:port;databaseName=schema" />
</spring:bean>
<jdbc:connector name="SQLServer-jdbcConnector"
dataSource-ref="SQLServer-jdbcDataSource" pollingFrequency="${SQLServer.db.poll}"
transactionPerMessage="false">
<jdbc:query key="read" value="${SQLServer.db.jdbc_query}" />
</jdbc:connector>
<flow name="SQLServer-flow">
<jdbc:inbound-endpoint queryKey="read"
connector-ref="SQLServer-jdbcConnector">
<jdbc:transaction action="ALWAYS_BEGIN"/>
<property key="receiveMessageInTransaction" value="true"/>
</jdbc:inbound-endpoint>
<vm:outbound-endpoint path="${sv.vm.queue.name}" connector-ref="first-level-xform">
<message-properties-transformer scope="outbound">
<add-message-property key="${sv.vm.msg.identifier}" value="SQLServer"/>
</message-properties-transformer>
<vm:transaction action="NONE"/>
</vm:outbound-endpoint>
</flow>
</mule>
When I deploy any one of these floes in mule-deploy.properties, it runs ok. But when I deploy both of these flows at the same time, none of them works. I do not get any error or exception, but it seems like none of these flows run.
Any ideas what might be wrong? Probably something related to JDBC transactions?
if you have 2 different flows in same application .. then remove :-
<spring:bean id="SQLServer-jdbcDataSource"
class="org.enhydra.jdbc.standard.StandardDataSource" destroy-method="shutdown">
<spring:property name="driverName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<spring:property name="url"
value="jdbc:sqlserver://host:port;databaseName=schema" />
</spring:bean>
<jdbc:connector name="SQLServer-jdbcConnector"
dataSource-ref="SQLServer-jdbcDataSource" pollingFrequency="${SQLServer.db.poll}"
transactionPerMessage="false">
<jdbc:query key="read" value="${SQLServer.db.jdbc_query}" />
</jdbc:connector>
from any of the flow ... Since it is declared as global ... it can be used from any of the flow in the application .. what I mean is .. just remove the above line of code from one of the flow ... since you have declared in both the flow I guess it's a duplicate and not required to place in each and every flow ... and yes just mention the reference connector-ref="SQLServer-jdbcConnector" in both the mule flow ... ex:-
<jdbc:inbound-endpoint queryKey="read"
connector-ref="SQLServer-jdbcConnector">

How to build a SWC with documentation

UPDATE
solved: embed doc with swc
solved: weird param names: param0, param1, etc.
I created a swc lib using compc.
Then I created the lib doc with asdoc.
But I dont know how to bind them together, since when I use the .swc in another project params names are weird (like myMethod(param0:Number)) and there is no doc description.
I'm using Ant, this is my config file:
<?xml version="1.0" encoding="utf-8" ?>
<project name="uil" default="compile" basedir=".">
<property name="flexsdk" location="C:/sdks/flex_sdk_4.6/bin"/>
<property name="compc" location="${flexsdk}/compc.exe"/>
<property name="asdoc" location="${flexsdk}/asdoc.exe"/>
<property name="src" location="../src"/>
<property name="bin" location="../bin"/>
<target name="compile" depends="doc">
<exec executable="${compc}" failonerror="true">
<arg line="-debug=false" />
<arg line="-optimize=true" />
<arg line="-strict=true" />
<arg line="-locale=en_US" />
<arg line="-include-sources=${src}" />
<arg line="-output=${bin}/uil.swc" />
</exec>
</target>
<target name="doc">
<exec executable="${asdoc}" failonerror="true">
<arg line="-main-title 'UIL API Documentation'" />
<arg line="-window-title 'UIL API Documentation'" />
<arg line="-source-path ${src} -doc-sources ${src}" />
<arg line="-output ${bin}/uil-asdoc" />
</exec>
</target>
</project>
Edit: How it was solved
The line that make all the magic is this:
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
Then I replaced all my <exec> tags to <compc> and <asdoc> and everything worked. You can see the entire code here.
Try to use zip ant target as in the build.xml of the Starling framework:
<!-- call asdoc to generate dita xml files -->
<asdoc output="${temp.dir}" lenient="true" failonerror="true" keep-xml="true" skip-xsl="true" fork="true">
<compiler.source-path path-element="${basedir}/src" />
<doc-sources path-element="${basedir}/src" />
</asdoc>
<!-- update swc with asdoc xml -->
<zip destfile="${deploy.dir}/${ant.project.name}.swc" update="true">
<zipfileset dir="${temp.dir}/tempdita" prefix="docs">
<include name="*.*"/>
<exclude name="ASDoc_Config.xml" />
<exclude name="overviews.xml" />
</zipfileset>
</zip>

Update app.config from WIX setup?

I am trying Wix 3.6 and this is how it looks right now :
<?xml version="1.0" encoding="UTF-8"?>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="myappINSTALLDIR" Name="myapp5Service">
<Component Id="SampleServiceComponent" DiskId="1" Guid="6f51c0f3-776c-4aec-a200-1f199352c6c3" Win64="yes">
<File Id="myapp5.WindowsService.exe" Name="myapp5.WindowsService.exe" Source="$(var.myapp.WindowsService.TargetDir)\myapp5.WindowsService.exe" KeyPath='yes'/>
...
<ServiceInstall Id="InstallmyappService" DisplayName="myappService" Name="myapp5.WindowsService.exe" Description="myapp 5 Service - För effektivare och enklare operationsplanering" Account="LocalSystem" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
<ServiceControl Id="ControlmyappService" Name="myapp5.WindowsService.exe" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
</Component>
</Directory>
</Directory>
<WixVariable Id="WixUIBannerBmp" Value="$(var.ProjectDir)\Image\myappTopBanner.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="$(var.ProjectDir)\Image\myappDialogBackground.bmp" />
<Property Id="WIXUI_INSTALLDIR" Value="myappINSTALLDIR" />
<UIRef Id="WixUI_InstallDir" />
<Feature Id="ProductFeature" Title="Wix_myapp.WindowsService" Level="1">
<ComponentRef Id="SampleServiceComponent" />
</Feature>
<Media Id="1" Cabinet="SampleServiceComponent.cab" EmbedCab="yes" />
</Product>
Now I need to add a dialog to the Wix setup where one appSetting and one baseadress(WCF) is set to the app.config. This most be done before the installation becouse it will decide the name of the Windows Service that the Wix is installning.
And exampel would be great!
Edit 1:
<WixVariable Id="WixUIBannerBmp" Value="$(var.ProjectDir)\Image\myappTopBanner.bmp" />
<WixVariable Id="WixUIDialogBmp" Value="$(var.ProjectDir)\Image\myappDialogBackground.bmp" />
<Property Id="SERVICEADDRESS" Value="http://serviceaddress"/>
<Property Id="WIXUI_INSTALLDIR" Value="myappINSTALLDIR" />
<UIRef Id="WixUI_InstallDir" />
<util:XmlFile Id="UpdateBaseAddress"
Action="setValue"
File="$(var.myapp.WindowsService.TargetDir)\myapp5.WindowsService.exe.config"
SelectionLanguage="XPath"
Permanent="yes"
ElementPath="/configuration/applicationSettings/ServiceName"
Name="baseAddress" Value="[SERVICEADDRESS]" />
<Feature Id="ProductFeature" Title="Wix_myapp.WindowsService" Level="1">
<ComponentRef Id="SampleServiceComponent" />
</Feature>
<Media Id="1" Cabinet="SampleServiceComponent.cab" EmbedCab="yes" />
</Product>
You could add in a reference to the WixUtilExtension.dll to the installer project, then use XmlFile to update the app.config like:
<Property Id="SERVICEADDRESS" Value="http://serviceaddress"/>
<util:XmlFile Id="UpdateBaseAddress"
Action="setValue"
File="[DirApplication]$(var.app.config)"
SelectionLanguage="XPath"
Permanent="yes"
ElementPath="/configuration/applicationSettings/...."
Name="baseAddress" Value="[SERVICEADDRESS]" />
Note that you'll need to set the directory and the name of the .config file (you could just use $(var.ProjectName.TargetFileName).config which should work it out for you automatically

How to reduce development cycles when building BlackBerry WebWorks or PhoneGap applications?

I'm interested in hearing how WebWorks developers are saving time during their development cycles by using any clever build processes / testing techniques.
What tips & tricks would you recommend to help reduce the amount of time it takes to build & test a WebWorks (or PhoneGap) application?
For example, here's a great suggestion (http://dborba.com/?p=274) from Demian Borba:
Build your app once, but configure it to load its start page from your dev web server
Make changes in that content, and they will be reflected when you re-launch your app (no need to recompile / redeploy the app)
Can even use Livereloader to make it even faster
If you use ant, here some target you will find useful:
<target name="zip" depends="init" description="Archive your files before building the bar" >
<zip
destfile="${build.dir}/${type.name}.zip"
basedir="${basedir}"
excludes="*.project,*.settings/,.*properties,*.svn,*.svn/*, builder/, .gitignore, .git/*"
includes="*,WebContent/"
/>
</target>
<target name="bar" depends="zip" description="create the bar file" >
<exec executable="${bbwp}">
<env key="JAVA_HOME" path="${sdk.JAVA_HOME}" />
<arg value="${build.dir}/${type.name}.zip"/>
<arg line="-o '${build.dir}'" />
<arg line="-v" />
<!-- Allows debugging on port 1337 -->
<arg line="-d" />
<!-- Sign to Appworld -->
<!-- <arg line="-g ${keyPass} - -buildId 10" /> -->
</exec>
</target>
<target name="install" depends="bar" description="Deploy the the .bar file to your simulator. The old application is automatically uninstalled." >
<java jar="${BarDeploy.dir}/BarDeploy.jar"
fork="true"
maxmemory="512M"
>
<env key="JAVA_HOME" path="${sdk.JAVA_HOME}" />
<arg value="-installApp" />
<arg value="-launchApp" />
<arg value="-password" />
<arg value="${password}" />
<arg value="-device" />
<arg value="${simIP}" />
<arg value="-package" />
<arg value="${bar.file}" />
</java>
</target>
<target name="uninstall" description="Uninstall an application from the Simulator. " >
<java jar="${BarDeploy.dir}/BarDeploy.jar"
fork="true"
maxmemory="512M"
>
<env key="JAVA_HOME" path="${sdk.JAVA_HOME}" />
<arg value="-uninstallApp" />
<arg value="-password" />
<arg value="${password}" />
<arg value="-device" />
<arg value="${simIP}" />
<arg value="-package" />
<arg value="${bar.file}" />
</java>
</target>
Here an exemple of the variable for a windows environment:
<property name="password" value=""/>
<property name="simIP" value="169.254.0.1" />
<property name="keyPass" value="" />
<property name="sdk.HOME" location="C:\Program Files\Research In Motion\BlackBerry 10 WebWorks SDK 1.0.1.8" />
<property name="build.dir" location="${basedir}\build" />
<property name="bar.file" location="${build.dir}\device\${type.name}.bar" />
<property name="sdk.JAVA_HOME" location="C:\Program Files\Java\jre6" />
<property name="bbwp" location="${sdk.HOME}\bbwp.bat" />
<property name="BarDeploy.dir" location="${sdk.HOME}\dependencies\tools\lib" />
Blackberry has just released the official Ant build script