Saturday, September 30, 2017

Read ATOM feeds using Apache Abdera

NewsFeedRead.java
import org.apache.abdera.Abdera;
import org.apache.abdera.model.*;
import org.apache.abdera.parser.Parser;

import java.net.URL;
import java.util.List;

public class NewsFeedRead {
    public static void main(String[] args) {
        Abdera abdera = new Abdera();
        Parser parser = abdera.getParser();

        try {
            URL url = new URL("https://news.google.com/news?output=atom");
            Document<Feed> doc = parser.parse(url.openStream(), url.toString());
            Feed feed = doc.getRoot();
            // Get the feed title
            System.out.println("Feed Title: " + feed.getTitle());

            // Get the entry items...
            for (Entry entry : feed.getEntries()) {
                System.out.println("Title: " + entry.getTitle());
                System.out.println("Unique Identifier: " + entry.getId().toString());
                System.out.println("Updated Date: " + entry.getUpdated().toString());
                System.out.println("Published Date: " + entry.getPublished());
                System.out.println("Content: " + entry.getContent());

                // Get the links
                for (Link link : (List<Link>) entry.getLinks()) {
                    System.out.println("Link: " + link.getHref());
                }

                // Get the categories
                for (Category category : (List<Category>) entry.getCategories()) {
                    System.out.println("Category: " + category.getTerm());
                }
            }
        } catch (Exception ex) {
            System.out.println("Error: " + ex.getMessage());
        }
    }
}


pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>CreateNewFeed</groupId>
    <artifactId>CreateNewFeed</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.apache.abdera</groupId>
            <artifactId>abdera-parser</artifactId>
            <version>1.1.1</version>
        </dependency>
    </dependencies>
</project>

Friday, September 15, 2017

WSO2 ESB Filter Mediator

Filter mediator is used to match or filter the message of a given xpath.

If we give only the xpath then it will return true or false. If we give regular expression, the string returned from evaluating the XPath will be matched against the regular expression.

There are two ways of operation

  • Specify the XPath (boolean expression), return true or false
  • XPath will be matched against the regular expression, return true or false

Examples :

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="test"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <property name="statusCode" value="200"/>
         <filter xpath="get-property('statusCode')!='204'">
            <then>
               <log level="custom">
                  <property name="----------Status Code--------------------------"
                            value="status code is not equals to 204"/>
               </log>
            </then>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
</proxy>

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="test"
       transports="http https"
       startOnLoad="true">
   <description/>
   <target>
      <inSequence>
         <property name="statusCode" value="200"/>
         <filter source="get-property('statusCode')" regex="200">
            <then>
               <log level="custom">
                  <property name="----------Status Code--------------------------"
                            value="status code is equals to 200"/>
               </log>
            </then>
         </filter>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
</proxy>

Thursday, August 17, 2017

How to share folders between Ubuntu and Windows running in Virtualbox

Step 1 : Create a directory called “vmsharedfiles”  in Ubuntu.

Step 2: Open up virtualbox instance.

Go to top menu and Click on Devices → Shared Folders → Shared Folders Settings.

If you are getting any error like “The VirtualBox Guest Additions do not appear to be available on this virtual machine, and shared folders cannot be used without them. To use shared folders inside the virtual machine, please install the Guest Additions if they are not installed, or re-install them if they are not working correctly, by selecting Insert Guest Additions CD image from the Devices menu. If they are installed but the machine is not yet fully started then shared folders will be available once it is.”, select the Devices option from VirtualBox's menu bar, and click on the Install Guest Additions CD Image option. Guest Additions installer will start automatically.
Follow the instructions to install.

Step 3 : Click on the green folder icon to Add new shared folder option in the right hand side.

Step 4 : You will prompt to the screen to select the folder you created in step 1. Select that folder and click open. And check “Make Permanent” option.

Step 5 : Go to My computer → computer → Map network drive → Map network drive.
You will see the screen below:

Step 6 : Click on Browse to select the shared folder that is created on step 1. Click OK and Finish.




Step 7 : Then this shared folder will be added to the My computer section.


Step 8 : Now you can access “vmsharedfiles” folder  in Ubuntu from Windows 10 in virtualBox.