Thursday, April 12, 2012

How to send and receive SOAP headers in Oracle BPEL

You can receive, reply the SOAP headers in Oracle BPEL by using the following Oracle extension:

       bpelx:headerVariable="Header1 Header2..."

Sample:



<reply name="ReplyExecuteOrderResponse"
       partnerLink="ExecuteOrderClient"
       portType="ns2:OrderManagementPortType_v1"
       operation="ExecuteOrder"
       variable="ExecuteOrderResponse"
       bpelx:headerVariable="ResponseHeader"/>




<receive name="RecieveExecuteOrder"
         createInstance="yes"
         partnerLink="ExecuteOrderClient"
         portType="ns2:OrderManagementPortType_v1"
         operation="ExecuteOrder"
         variable="ExecuteOrderRequest"
         bpelx:headerVariable="RequetHeader"/>



You can send the SOAP headers in Oracle BPEL in invoke activity  by using the following Oracle extension:

      bpelx:inputHeaderVariable="Header1, Header2,..."

Sample:



<invoke name="InvokeAsynMobileActivation"
       partnerLink="MobileActivatuonBPEL.MobileActivationClient"
       portType="ns1:AsyncMobileProductManagementPortType_v1"
       operation="InitiateAsyncActivatePrepaidMobile"
       variable="ActivatePrepaidMobileRequest"
       bpelx:inputHeaderVariable="RequestHeader"/>





How to delete all svn folders in a folder

Sometimes when you copy some folders from SVN checkout directory to other place in Windows but you don't want to keep all svn folders contained by these folders and their subfolders it is very tedious to delete them manually.   There is is one easy way to use one command file to do so for you,   All you need to do is to create one command file under your root folder(The folder after copying from svn folders). For example you can name this file as: claensvn.cmd and put the below contents into this file:


for /f "tokens=* delims=" %%i in ('dir /s /b /a:d *svn') do (
rd /s /q "%%i"
)

After the file is created just run this command and it will delete all svn folders under this root folder for you.

Saturday, January 21, 2012

Spring AOP Tutorial


Spring AOP Tutorial

OOP vs. AOP
Just like OOP which is widely used to design application by modularizing core business functionalities of the application into objects AOP is used to modularize the cross-cutting concerns of the application into aspects. From OOP perspective one application system is consisted of many objects and each object encapsulates some core functionality of the system. But apart from these core business functionalities in the objects there are still non core functionalities in one system. These functionalities or requirements cannot easily be represented in objects because these such as logging, security or transaction management are scattered in various objects. If these functionalities are represented in objects there will be lots of duplicates of the codes spread in the objects. An elegant representation of these scattered or cross-cutting functionalities or concerns is needed and thus here comes AOP. AOP provides another perspective to the application system. In AOP these cross-cutting concerns are represented as aspects and then the aspects are applied to the objects or objects are advised with the aspects. OOP and AOP are complimented each other. 

Benefits of Using AOP
With AOP the cross-cutting concerns can be modularized into aspects. Now the codes that implement the cross-cutting concerns are in one place: aspect. And aspect can be applied to any place where these concerns are needed. The core business objects just need to have the codes for primary business logic. All the codes of one application are better organized. 


There are several ways to implement Spring AOP.

1.      One way is to create the aspect from a POJO by implementing some AOP advice interfaces.   These interfaces are:

org.springframework.aop.MethodBeforeAdvice
org.springframework.aop.AfterReturningAdvice
org.springframework.aop.ThrowsAdvice


public class LoggingAdvice implements MethodBeforeAdvice, AfterReturningAdvice, ThrowsAdvice {

    public void before(Method method, Object[] os, Object o) throws Throwable {
        System.out.println("LoggingAdvice before is invoked.");
    }

    public void afterReturning(Object o, Method method, Object[] os, Object o1) throws Throwable {
        System.out.println("LoggingAdvice afterReturning is invoked.");
    }

    public void afterThrowing(Exception ex) {
        System.out.println("LoggingAdvice afterThrowing is invoked.");
    }
}

Advice defines what (printing some message here) and when (before the method invocation, after method invocation and etc.) to do in an aspect.   Further we need to specify where this advice will be applied to.  That is: which method is the advice applied to.  These are the works of pointcut which defines a set of joint points where the advice is applied to.

<bean id="loggingAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor">
        <property name="advice" ref="loggingAdvice"/>
        <property name="pointcut" ref="loggingPointcut"/>
 </bean>

 <bean id="loggingPointcut" class="org.springframework.aop.aspectj.AspectJExpressionPointcut">
        <property name="expression" value="execution(* *.add*(..))"/>
 </bean>

<bean id="loggingAdvice" class="com.toic.spring3.cert.aop.LoggingAdvice"/>

<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>


2.      Another way of creation of aspect is to use @AspectJ annotation with POJO when using Java 5 or higher.

In this way a POJO can be defined as an aspect using some annotations such as @AspectJ, @Before, @After and etc.  

@Aspect
public class LoggingAspect {

    @Before("execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResource(..))")
    public void logBefore(JoinPoint joinPoint) {

        System.out.println("logBefore() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println();
    }

    @After("execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResource(..))")
    public void logAfter(JoinPoint joinPoint) {

        System.out.println("logAfter() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println();
    }

    @AfterReturning(
        pointcut = "execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResource(..))",
        returning= "result")
    public void logAfterReturning(JoinPoint joinPoint, Object result) {

        System.out.println("logAfterReturning() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println("Method returned value is : " + result);
        System.out.println();
    }
   
    @AfterThrowing(
        pointcut = "execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResourcceThrowException(..))",
        throwing= "error")
    public void logAfterThrowing(JoinPoint joinPoint, Throwable error) {

        System.out.println("logAfterThrowing() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println("Exception : " + error);
        System.out.println();
    }
   
    @Around("execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResource(..))")
    public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {

                System.out.println("logAround() is running!");
                System.out.println("hijacked method : " + joinPoint.getSignature().getName());
                System.out.println("hijacked arguments : " + Arrays.toString(joinPoint.getArgs()));

                System.out.println("Around before is running!");
        System.out.println();
       
                joinPoint.proceed(); //continue on the intercepted method
       
                System.out.println("Around after is running!");

                System.out.println();

   }

<aop:aspectj-autoproxy />

<bean id="customerBo" class="com.toic.spring3.aop.demo.ResourceServiceImpl" />

<!-- Aspect -->
<bean id="logAspect" class="com.toic.spring3.aop.demo.LoggingAspect" />


3.      There is another way to create aspect.  Spring provides schema-based AOP support so if you prefer to use XML configuration instead of annotations.   You can choose this way.  One of the greatest advantage of this ways is that you can turn any POJO into an aspect.  This POJO needs no special interfaces or annotations.

public class LoggingAspect {

    public void logBefore(JoinPoint joinPoint) {

        System.out.println("logBefore() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println();
    }

    public void logAfter(JoinPoint joinPoint) {

        System.out.println("logAfter() is running!");
        System.out.println("hijacked : " + joinPoint.getSignature().getName());
        System.out.println();
    }
}


In the XML configuration you can define an aspect from the POJO using Spring AOP configuration elements.   In the below example under <aop:config> there is one aspect whose id is aspectLogging defined.

<aop:aspectj-autoproxy />

 <bean id="resourceService" class="com.toic.spring3.aop.demo.ResourceServiceImpl" />

<!—POJO class -->
<bean id="logAspect" class="com.toic.spring3.aop.demo.LoggingAspect" />

<aop:config>

      <aop:aspect id="aspectLogging" ref="logAspect" >
            
             <aop:pointcut id="pointCutBefore"
                expression="execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResource(..))" />

             <aop:before method="logBefore" pointcut-ref="pointCutBefore" />
            
             <aop:pointcut id="pointCutAfter"
                expression="execution(* com.toic.spring3.aop.demo.ResourceServiceImpl.addResource(..))" />
               
             <aop:after method="logAfter"  pointcut-ref="pointCutAfter" />
       </aop:aspect>

 </aop:config>

Tuesday, January 10, 2012

Some useful RPM commands

Install an RPM package

rpm –ivh your_package_file_name

For example

rpm –ivh http://xyz.com:8085/ SOAMDS-MDSPREPAIDACT-7/artifact/JOB1/dist/MDS-PrepaidActivation-1.0-7.noarch.rpm

Query all installed packages

rpm -qa

This command will display all the installed package names. Not they are package names not package file names.


 

Query a particular installed package

rmp –q your_package_name


 

Display the information of a particular installed package

rpm –qi your_package_name


 

Unintall an RPM package

rpm –e your_package_name


 

This command will uninstall the package. Note here it is the package name not the package file name.

For example

rpm –e MDS-PrepaidActivation-1.0-5

Saturday, December 17, 2011

Schematron validation


Schematron is rule-based validation language.  It is different from XML schema validation and it is supplement to XML schema validation.  If required you can apply both of them to the validation of the XML document.

Schematron defines a set of assertions that are to be enforced. If all these assertions are met, the document is seen as valid.

The assertion is specified using XPath.

Schematron has 4 key elements: pattern, assert, rule and ns.

The assert element has an attribute of test whose value is defined as XPath expression. This expression should return a Boolean value. If the test expression evaluates to true, then assertion has been met.

The assert is defined within a rule element.

Multiple asserts may be defined in a rule element. Each rule has a context attribute, which also contains an XPath expression used to specify the nodes to which the asserts will be tested.

The context may return zero, one or more nodes from XML document instance. Each node will be tested against all asserts within this rule.


Here is one example:  We need to validate that the MSISDN should start with 04 and totally has 10 digits and CAC should be numeric.

What we do here is to define one patter in which there are two contexts defined.   The context is using XPath to get the right element in XML document.  One context is for MSISDN element and another for CAC element.  In each element there is one assertion.  The assertion contains the test statement which uses the Regular expression to validate the element value.

<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
                <!-- define the process namespace for finding the elements in the rule-->
                <sch:ns uri="http://toic.com/orderManagement/messages/v1" prefix="tns"/>
                <sch:ns uri="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" prefix="xp20"/>
 
                <sch:pattern name="Check the parameters in ExecuteOrdre request">
                                <!-- context is the super variable that can be queried for validation-->
      
                              <!-- Check MSISDN as Identification has validate value -->   
                                <sch:rule context="tns:ExecuteOrderRequest[ xp20:ends-with(@*[local-name()='type'], 'CustomerOrder') ]/tns:Party/tns:PartyRole/tns:Identification[xp20:ends-with(./*[local-name()='Type'], 'MSISDN')] ">
                                                <sch:assert test="xp20:matches( string(tns:Value), '\b04\d{8}\b')">MSISDN should be 10 digit numeric starting with 04</sch:assert>
                                </sch:rule>

                              <!-- Check CAC as Identification has validate value -->   
                                <sch:rule context="tns:ExecuteOrderRequest[ xp20:ends-with(@*[local-name()='type'], 'CustomerOrder') ]/tns:Party/tns:PartyRole/tns:Identification[xp20:ends-with(./*[local-name()='Type'], 'CAC')] ">
                                                <sch:assert test="xp20:matches( string(tns:Value), '\b\d{1,}$')">CAC should be numeric</sch:assert>
                                </sch:rule>

                </sch:pattern>
</sch:schema>



 

Thursday, December 1, 2011

Validate the variable in Oracle BPEL

You can validate one variable against the schema in Oracle BPEL.   

It is done through validate activity from Oracle Extensions.   The BPEL codes will look like the below:




        <validate name="ValidateRequest"
                  variables="RetrieveResourceDetailsRequest"/>


When validation fails the standard fault bpel:invalidVaraible is thrown.   So you need to catch this fault using the following codes:


        <catch faultName="bpel:invalidVariables"> 
                   .... Some activities here
        </catch>

Sunday, November 27, 2011

Deployment issue with Oracle SOA 11g


I found this issue recently when I deployed one SOA application to my local server.   It doesn’t seem to happen all the time but when it happens it causes the deployment error:  Unable to register service.   I don’t know the reason for this problem but I find one way to avoid this problem.
The below example shows when the problem will appear and how the problem can be fixed.   We have one BPEL application which will be exposed as the service: OrderService which is defined in OrderService.wsdl.   This WSDL is not abstract WSDL since it includes the binding and service part.
After creating the service using JDeveloper, JDevloper will create composite.xml and OrderServiceWrapper.wsdl. 
Composite.xml is like the below.   It just shows some key parts for the brevity.  Please note that there are two import statements: one for original OrderService.wsdl and another for OrderServiceWrapper.wsdl.

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SOA Modeler version 1.0 at [23/11/11 12:45 PM]. -->
<composite name="CreateOrderService" …>
  <import namespace="http://www.toic.com/esb/wsdl/orderservice"
          location="wsdl/OrderService.wsdl" importType="wsdl"/>
  <import namespace="http://www.toic.com/esb/wsdl/orderservice"
          location="OrderServiceWrapper.wsdl" importType="wsdl"/>
  <service name="CreateOrderService" ui:wsdlLocation="wsdl/OrderService.wsdl">
    <interface.wsdl interface="http://www.toic.com/esb/wsdl/orderservice#wsdl.interface(OrderServicePortType)"/>
    <binding.ws port="http://www.toic.com/esb/wsdl/orderservice#wsdl.endpoint(CreateOrderService/OrderServicePort)">
      <property name="weblogic.wsee.wsat.transaction.flowOption"
                type="xs:string" many="false">NEVER</property>
    </binding.ws>
  </service>
……
</composite>

When it is deployed one deployment error will occur as the following:

[01:16:20 PM] ----  Deployment started.  ----
[01:16:20 PM] Target platform is  (Weblogic 10.3).
[01:16:20 PM] Running dependency analysis...
[01:16:20 PM] Building...
[01:16:23 PM] Deploying profile...
[01:16:23 PM] Updating revision id for the SOA Project 'CreateOrderService.jpr' to '1.0'..
[01:16:23 PM] Wrote Archive Module to D:\JDeveloper\mywork\SOADemo\CreateOrderService\deploy\sca_CreateOrderService_rev1.0.jar
[01:16:23 PM] Deploying sca_CreateOrderService_rev1.0.jar to partition "default" on server AdminServer [http://A00000113011750.wg.dir.telstra.com:7001]
[01:16:23 PM] Processing sar=/D:/JDeveloper/mywork/SOADemo/CreateOrderService/deploy/sca_CreateOrderService_rev1.0.jar
[01:16:23 PM] Adding sar file - D:\JDeveloper\mywork\SOADemo\CreateOrderService\deploy\sca_CreateOrderService_rev1.0.jar
[01:16:23 PM] Preparing to send HTTP request for deployment
[01:16:23 PM] Creating HTTP connection to host:A00000113011750.wg.dir.telstra.com, port:7001
[01:16:23 PM] Sending internal deployment descriptor
[01:16:23 PM] Sending archive - sca_CreateOrderService_rev1.0.jar
[01:16:24 PM] Received HTTP response from the server, response code=500
[01:16:24 PM] Error deploying archive sca_CreateOrderService_rev1.0.jar to partition "default" on server AdminServer [http://A00000113011750.wg.dir.telstra.com:7001]
[01:16:24 PM] HTTP error code returned [500]
[01:16:24 PM] Error message from server:
There was an error deploying the composite on AdminServer: Update Failed: Unable to register service..
 [01:16:24 PM] Check server log for more details.
[01:16:24 PM] Error deploying archive sca_CreateOrderService_rev1.0.jar to partition "default" on server AdminServer [http://A00000113011750.wg.dir.telstra.com:7001]
[01:16:24 PM] ####  Deployment incomplete.  ####
[01:16:24 PM] Error deploying archive file:/D:/JDeveloper/mywork/SOADemo/CreateOrderService/deploy/sca_CreateOrderService_rev1.0.jar
 (oracle.tip.tools.ide.fabric.deploy.common.SOARemoteDeployer)

One way to fix this problem is to remove one import statement from composite.xml.  The import statement that imports the original WSDL will be deleted.   The new composite.xml will be shown as the below:

<?xml version="1.0" encoding="UTF-8" ?>
<!-- Generated by Oracle SOA Modeler version 1.0 at [23/11/11 12:45 PM]. -->
<composite name="CreateOrderService" …>
  <!--import namespace="http://www.toic.com/esb/wsdl/orderservice"
          location="wsdl/OrderService.wsdl" importType="wsdl"/-->
  <import namespace="http://www.toic.com/esb/wsdl/orderservice"
          location="OrderServiceWrapper.wsdl" importType="wsdl"/>
  <service name="CreateOrderService" ui:wsdlLocation="wsdl/OrderService.wsdl">
    <interface.wsdl interface="http://www.toic.com/esb/wsdl/orderservice#wsdl.interface(OrderServicePortType)"/>
    <binding.ws port="http://www.toic.com/esb/wsdl/orderservice#wsdl.endpoint(CreateOrderService/OrderServicePort)">
      <property name="weblogic.wsee.wsat.transaction.flowOption"
                type="xs:string" many="false">NEVER</property>
    </binding.ws>
  </service>
……
</composite>