Sabtu, 28 Januari 2017

Cron Job in linux

Cron allows linux or unix users to run scripts at a given time and date. We can schedule any script be executed periodically.

Linux/Unix provide the crontab inbuilt utility to schedule any script.

Let's go through an example and see how crontab would be setup with the help of an example.

Considering we have a java file, and this is wrapped up in a jar file. We are gonna to schedule that jar using crontab.

Create a shell script file(test.sh) with the entry

java -cp .:test.jar Scheduler

Where

test.jar: jar file name
Scheduler: Main class

crontab command is used to edit/list crontab:

How to edit the crontab

To edit a crontab entries, use crontab -e as shown below. By default this will edit the current logged-in users crontab.


Crontab in linux


How to view the crontab

To view your crontab entries type crontab -l from your linux  account as shown below.



Crontab in linux


Syntax of Crontab:

1 2 3 4 5 /root/test.sh

Where,

1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (1-12)
5: Day of the week(0-6)


 /root/test.sh – Script or command name to schedule


Let's create a crontab. We are gonna to schedule test.sh file that will run daily midnight. Hit the crontab -e to install the crontab and add the entry 1 0 * * * /root/test.sh and save the file.

Crontab in linux

Now test.sh file will run daily midnight at 00:01AM..

That't it !!

Kamis, 26 Januari 2017

Create a WSDL from XSD

Sometimes it is required to create service interface(WSDL) from the schema(XSD) file.

This post shows you how to create interface- WSDL from the given XSD using Jdeveloper 12c.

Let's go step by step.

1) Suppose you have a Application and a project in the JDeveloper.

2) Right click on the project and create a schema file


 3) Create the XSD structure like below


<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org"
            targetNamespace="http://www.example.org" elementFormDefault="qualified">
  <xsd:element name="request">
    <xsd:annotation>
      <xsd:documentation>A sample element</xsd:documentation>
    </xsd:annotation>
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="id" type="xsd:integer"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="response">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="name" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
  <xsd:element name="fault">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="error" type="xsd:string"/>
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

4) Let's create a WSDL document. Right click on the project-> New -> WSDL Document


5) Arrange the schema and WSDL editor windows in a vertical split arrangement like as shown below. This can be achieved by dragging the test.xsd tab below


6) Let's create the WSDL document. Drag and Drop the request element from the XSD to the Port Types window. A popup will get open. Rename the Port Type Name as shown below


7) WSDL will look like


8) Here we can see, input and ouput refer to both request element. To correct this, select the output node from the Port Types window and drag and drop response element from the schema onto the output element


9) Add a fault node in the Port Types. To do so, first add the Message part, Drag and Drop the fault element from the schema on the Message window and rename Message name as EmpFault





10) Right click on the output node, Insert After Output -> fault. 


11) Enter name as EmpFault and select tns:EmpFault from the message drop down



12) After the above steps, your WSDL document look like this


13) Now Drag and Drop EmpDemo node from Port Types window to Binding / Partner Links Type window and click OK



Your WSDL look like this



14) Now drag and drop the EmpDempSOAP1Binding node to the Services Wndow. After this step WSDL document look like this.


WSDL has been completed. Now validate the WSDL to see the WSDL we have created is valid or not. Right Click on the test.wsdl and click Validate WSDL





You can use this WSDL to create the services.

It's done.

Jumat, 20 Januari 2017

Caching in OSB 12c

OSB allows us to cache Business Service Response for a given request.

OSB uses the Coherence to support caching. Caching increases the application performance if we configure it in the correct way.

When cache is enabled and any request come to the Business Service then it will first check the cache and returns the result from cache to the consumer else it will call the target service and get the output, return to the consumer and save the output in the cache itself.

This Result Caching mechanism the OSB uses is Oracle Coherence which is included in the Oracle Weblogic server.

Let's see the example how we can enable caching for the Business Service.

Considering we have a Service bus project having one REST service that invokes the database using Business Service. If you don't have a project you can follow the blog. I'm gonna to extend this blog only.

1) Open the Business Service, Move to the Performance tab


2) Check the Enable Result Caching checkbox and select the expression as $body/dbr:DBReferenceSelect_deptIdInputParameters/dbr:deptId corresponding to the Cache Token Expression. That will be the unique token in the cache for each department id we pass in the request.


3) Now, select the Duration radio button from the Expiration Time section and configure 2 minutes. That's means cache will be refreshed every two minutes.



The first request would be served from the database and respective request would be served from cache till the cache expires(in 2 minutes). After that Business Service will hit the database again and refreshes the cache with the updated result.

Let's run the example and see how it works.

Request-1



Response-1

See the firsname and lastname

Let's change the firstName and lastName values in the DB so quickly



Hit the request before cache expires

Request-2

Response-2


See the response has been served from cache it self.

Let hit the request after 2 minutes and see the response

Request-3

Response-3

Now you can see the updated result. That time data has been fetched from database.

That's it !!

Disable OSB services(Proxy or Business)

Sometime it is required to disable OSB services(Proxy or Business).

This can be done using enterprise manager(em) console.

Just follow the simple steps to disable the services.

1) Login into the em console(http://localhost:7001/em)

2) Navigate to the SOA -> service-bus and click the project whose service you want to disable


3) Move to the Operations tab, Uncheck the checkbox corresponding to the service that you want to disable(in our case we our disabling the Business Service) under the state column and click Apply button




4) Service has been disabled. Let's run the Business Service and see the output


Service has been disabled.

Same way you can enable the service. Just check the state column checkbox corresponding to the disabled service and click Apply button.

That't it !!


Selasa, 17 Januari 2017

Convert binary(Non XML) data to XML data in OSB using MFL

In OSB, we can use Message Format Language(MFL) to transform binary data to XML and vice versa.

We use format builder to create mfl files and can't create mfl files from sbconsole. We would be required Jdevloper to create MFLs.

Let's take a use case. We have a binary data in the below format

Ankur|Jain
Rishab|Jain

and want to convert into XML

<?xml version="1.0" encoding="UTF-8"?>
<Employees>
  <Employee>
    <FirstName>Ankur</FirstName>
    <LastName>Jain</LastName>
  </Employee>
  <Employee>
    <FirstName>Rishab</FirstName>
    <LastName>Jain</LastName>
  </Employee>
</Employees>

Let's start with an example, and see how it works.

Assuming we do have a Service Bus application with Service Bus project.

1) Right Click on Service Bus project -> New -> MFL



2) Give MFL name and click Finish


3) MFL Format Builder will get open automatically, if not you can write click on the MFL and click Open with Format Builder


4) Click on EmployeeMFL element from the left navigation and you can rename it and click Apply


5) Click on Insert -> Group -> As Child



6) Enter Name as Employees, Select Unlimited(means we can have multiple Employees element) from the Group occurrence section, Click Apply


7) Click on Employee element, Select Insert -> Filed -> As Child



8) Enter Name as FirstName, select Delimiter from the Field Attributes section, enter Value(s) as | symbol, select Code page as UTF-8 and click Apply button



9) Click on Employees element again and,  Select Insert -> Filed -> As Child

10) Enter Name as LastName, select Delimiter from the Field Attributes section, enter Value(s) as
\symbol, select Code page as UTF-8 and click Apply button



MFL is done. Now it's time to test the MFL. Jdevloper provides the inbuilt tool to test the MFL.

10) Click on Tools -> Test from the MFL Format Builder wizard


11) Select Text from the down Tab, Enter the Non-XML data in the left panel, Click on Transform-> Non-XML To XML


And see the result


Note: You can generate the sample file by clicking on the Generate -> Non-XML

That's it !!

Java callout in OSB

Sometimes Oracle Service Bus is not sufficient to meet our requirements. To do so OSB provides Java Callout activity that is used to call java code from OSB.

In this blog, I will explain a very basic example to use Java Callout Activity.

There are some restrictions to use Java Callout activity:

  • Java code must be packaged as jar
  • The java method that will be called from OSB, must be static
Let's proceed with an example

1) Create a simple java class:

JAVA callout in OSB

2) Create jar that will contain the .class file.

3) Copy the jar file in the OSB project

4) Drag the Java Callout activity in the pipeline and configure the properties

JAVA callout in OSB


Method: Browser the jar and select the method that you want to call and click OK
Arguments: Set the value of arguments
Return: Assign the variable in which you want to get the output of the method

5) Drag the log activity and print the greeting variable

6) Run the pipeline and see the output


That's it !!

Hostname verification failed: HostnameVerifier=weblogic.security.utils.SSLWLSHostnameVerifier

Sometimes we may struggle with the  Hostname verification failed: HostnameVerifier=weblogic.security.utils.SSLWLSHostnameVerifier exception when we deal with the host that is not verified by our network.

If the application is deployed on Weblogic, we can resolve this issue using simple steps:

Let's follow the steps:

1) Login into the WebLogic console(http://localhost:7001/console)

2) Click on Lock & Edit button

3) Select Servers from the left navigation

4) Click on the Server Name


5) Go to the Configuration  -> SSL  -> Advanced and select None from the Hostname Verification drop down.


6) Click Save button and Activate Changes