Carbon Component (WSO2)

5 minute read

Published:

I compose this post based on results of google searches as well as related articles from the company. The reference I shared at the end can be reliable, but It may be outdated.

In this post, I mainly discuss the issues I faced while exploring the Carbon Component.

Maven (Some of my contents are specific to IntelliJ IDEA)

A maven is a build tool like Ant and Gradle; it is IDE independent. In maven projects, we will generally have a file POM.xml inside each maven project and sub-projects. It will contain details about projects, parent projects, dependencies, plugins, repositories, and plugin repositories.

  • The project contains mainly groupId, artifactId, ModelVersion, packaging (pom – for a generally parental project, bundle, jar – for child type project), and Modules (components inside the main project. this was expected to be in order it build.

  • Dependencies (these are jar files) contain groupId,artifactId, and version (this can be hardcoded or added by defining the version). This will only give the classpath of the jar file.

  • Plugins are like Dependencies; it will compile and run. unlike dependencies which only give jar files to the classpath.

  • Repositories are associated with the dependencies means the location where we can fetch the dependencies. it contains id, name, layout, URL, snapshots → Enabled

  • PluginRepositories also the same as repositories, but these are associated with plugins]

Carbon Component

The carbon component is based on the OSGi; It will develop using proper methods to achieve its call. In my case, I have referred it contains three subcategories backend, service-stub, and front-end.

The backend will determine the data access layer services, and the front end will choose user interface service and service-stub deal with interconnecting. In my case, which I referred. First I need to develop and build maven project for backend and using its jar from /target/ folder towards the preferred Server (You can use any WSO2 Server, but this need to be verified) /repository/components/dropins/ then we need to modify the carbon.xml file in /conf/ folder by changing <HideAdminServiceWSDLs> value from true to false. Finally, restart the browser and click the link, URL https://localhost:9443/services/ordermanager?wsdl. Download this file and save it under services-stubs resources as a wsdl file. Then based on tutorials, continue other kinds of stuff.

Issue I faced

I faced the issue when building a maven project (based on sample code) for the back-end part of the project. The POM for org.wso2.carbon:org.wso2.carbon.registry.core:jar:4.2.0 is missing, no dependency information available This was due because unlike normal dependencies some dependencies especially related to carbon are required to be added that can be done by adding the following lines to POM.xml of back-end. These were specific repositories that need to locate the dependencies related to carbon.

BUT,

This may have some other choices in general.

  1. When declaring the repository it is better to check in google whether those dependencies are available, even though maven by default download dependencies, due to some version error also above error occurs. So its best advice to have researched before including dependencies.

  2. As in the previous case for some products maven can’t find the repository location we need to specify it using <repository> </repository>, This because of order which maven lookup for dependencies.

Order Maven Look Up Dependencies

  • Local - (It was a local computer where user create the project when building a maven project it will copy all dependency jar files to the preferred location by user)

  • Central - (It was maven repository where mostly most of the dependencies are available)

  • Remote- (This was something which is not reached by any, one or two, it was some sort of specifications for this we need to specify the repository which will direct to dependency to download dependencies / this was same for plugin also where that is plugin repository)

GENERAL NOTE

Include the newer version of dependencies and Plugins, especially for remote sites, because they will remove it from time to time due to unwanted spaces. So for in our case of using the repository of carbon of WSO2, it is advisable to use later version of carbon means 4.4.7, 4.4.9 other than using the old version likes 4.2.0.


<pluginRepositories>
    <pluginRepository>
        <id>wso2.releases</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
    </pluginRepository>
    <pluginRepository>
        <id>wso2.snapshots</id>
        <name>Apache Snapshot Repository</name>
        <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
        <snapshots>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
        </snapshots>
        <releases>
            <enabled>false</enabled>
        </releases>
    </pluginRepository>
    <pluginRepository>
        <id>wso2-nexus</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
    </pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
    <groupId>org.wso2.carbon</groupId>
    <artifactId>org.wso2.carbon.registry.core</artifactId>
    <version>4.4.9</version>
</dependency>
<dependency>
    <groupId>org.wso2.carbon</groupId>
    <artifactId>org.wso2.carbon.registry.api</artifactId>
    <version>4.4.9</version>
</dependency>
</dependencies>
<build>
<plugins>
    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
            <instructions>
                <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                <Bundle-Name>${pom.artifactId}</Bundle-Name>
                <Export-Package>org.wso2.sample.carbon.order.manager.*</Export-Package>
            </instructions>
        </configuration>
    </plugin>
</plugins>
</build>
<repositories>
<repository>
    <id>wso2-nexus</id>
    <name>WSO2 internal Repository</name>
    <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
    <releases>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
</repository>
<repository>
    <id>wso2.releases</id>
    <name>WSO2 internal Repository</name>
    <url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
    <releases>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
</repository>
<repository>
    <id>wso2.snapshots</id>
    <name>Apache Snapshot Repository</name>
    <url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
    <snapshots>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
    </snapshots>
    <releases>
        <enabled>false</enabled>
    </releases>
</repository>
<!--for kafka-->
<repository>
    <id>MarketceteraRepo</id>
    <name>MarketceteraRepoy</name>
    <url>http://repo.marketcetera.org/maven/</url>
</repository>
<repository>
    <id>smslib.releases</id>
    <name>smslib Repository</name>
    <url>http://smslib.org/maven2/v3/</url>
    <releases>
        <enabled>true</enabled>
        <updatePolicy>daily</updatePolicy>
        <checksumPolicy>ignore</checksumPolicy>
    </releases>
</repository>
</repositories>
        <!-- plugin repositories are for to execute, but for this we can use only repositories
        because here giving path to jar file is just enough -->
        <!-- org.apache.felix is required for setting up the components related to
        OSGi bundle so, don't forget to add this -->

References

  1. http://wso2.com/library/tutorials/2014/03/how-to-write-a-wso2-carbon-component/
  2. http://alokayasoya.blogspot.com/2015/02/writing-first-carbon-component.html
  3. https://maven.apache.org/guides/introduction/introduction-to-repositories.html
  4. https://maven.apache.org/guides/introduction/introduction-to-the-pom.html
  5. http://stackoverflow.com/questions/11881663/what-is-the-difference-in-maven-between-dependency-and-plugin-tags-in-pom-xml
  6. http://www.tutorialspoint.com/maven/maven_repositories.htm