Thursday, September 28, 2017

Invoke Secure site as WSO2 API Manager backend url with Modify headers

I though of listing down challenges I faced when I tried to invoke secure site as back end with WSO2 API Manager. (If your ackend url is https)


  1. WSO2 Api Manager is changing the "javax.net.ssl.trustStore" and password to their custom location,  reference: /deployment/repository/conf/TrustStore/Location/carbon.xml
  2. First you need to merge the backend site certificate key with wso2 trust store. referecne: "InstallCert.java"
Command used to merge jssecacerts content to client-truststore.jks,

keytool -importkeystore -noprompt -srckeystore client-truststore.jks -destkeystore jssecacerts


Destination file pw:*******
Source file pw: changeit
  1. Still if you are getting error like "host is unknown" or similar kind of, change the confiuration to "Allow All" in "/deployment/repository/conf/axis2/axis2.xml"
  2. Then you can add your modify headers inside APIAuthenticationHandler.java
 org.apache.axis2.context.MessageContext axis2MC = ((Axis2MessageContext) messageContext).
                getAxis2MessageContext();
        Map<String, String> headers =
                (Map) axis2MC.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
        headers.put("customHeader1", "customHeader1Val");
        headers.put("customHeader2", "customHeader2Val");
        axis2MC.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headers);
        messageContext.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS, headers);


Note: WSO2Api manager is appending part of front-end-url to the back-end-url as "REST_URL_POSTFIX". So need to careful on that.

Thursday, August 13, 2015

About Hazelcast Idempotent Repository and Stuff


  • Karaf is one of OSGi run time environment

About hazelcast

http://www.captaindebug.com/2013/10/getting-started-with-hazelcast.html#.Vc1hCfmqqPs
  • Hazelcast nodes are 'masterless', which means that it isn't a client-server system
  • There is a cluster leader, which is by default the oldest member of the cluster, which manages how data is spread across the system; however, if that node went down, then the next oldest will take over



Wednesday, November 5, 2014

When Configuring GZIP Interceptors

GZIPInInterceptor,

simple as creating instance and adding as in-Interceptor to service endpoint

GZIPOutInterceptor,

 simple as creating instance and adding as out-Interceptor to service endpoint, make sure to define threshold value when creating insance


        GZIPInInterceptor gzipInInterceptor = new GZIPInInterceptor();
        GZIPOutInterceptor gzipOutInterceptor = new GZIPOutInterceptor(0);
        server.getEndpoint().getInInterceptors().add(gzipInInterceptor);
        server.getEndpoint().getOutInterceptors().add(gzipOutInterceptor);

Monday, November 3, 2014

How to configure custom check style plugin

Mainly there are 3 files to configure

  1. checks.xml
  2. checkstyle-suppressions
  3. pom.xml
sample pom file to correctly define maven check-style plug in,

            <plugin>
                <artifactId>maven-checkstyle-plugin</artifactId>
                <groupId>org.apache.maven.plugins</groupId>
                <version>2.10</version>
                <dependencies>
                    <dependency>
                        <groupId>com.intel.ase.osg</groupId>
                        <artifactId>com.intel.ase.osg.governance</artifactId>
                        <version>${ase.osg.version}</version>
                    </dependency>
                </dependencies>
                <executions>
                    <execution>
                        <phase>verify</phase>
                        <goals>
                            <goal>check</goal>
                        </goals>
                        <configuration>
                            <configLocation>../com.intel.ase.osg.governance/src/main/resources/governance/osg_checks.xml</configLocation>
                            <suppressionsLocation>../com.intel.ase.osg.governance/src/main/resources/governance/checkstyle-suppressions.xml</suppressionsLocation>
                            <!--<headerLocation>governance/header.txt</headerLocation>-->
                            <propertyExpansion>config_loc=../com.intel.ase.osg.governance/src/main/resources/governance</propertyExpansion>
                            <consoleOutput>true</consoleOutput>
                            <failOnViolation>true</failOnViolation>
                            <includeTestSourceDirectory>false</includeTestSourceDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>


  • How to suppress check-style validation for particular class
  1. Using SuppressionCommentFilter
we have to use "SuppressionCommentFilter"  see reference http://checkstyle.sourceforge.net/config.html#Modules


Sample java code usage after configuration,

public class IdentityServiceException extends Exception {

    // CHECKSTYLE:OFF
    private IdentityError error;
    // CHECKSTYLE:ON

..................................
 

2. Using suppress expression

include below line to checkstyle-suppressions.xml
   
<suppress files="TheClassToIgnore\.java" checks="[a-zA-Z0-9]*"/>


Wednesday, September 10, 2014

How to generate javaDoc through mvn plugin

How to generate javaDoc through mvn plugin

  • Add below snip to generate source jar

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-source-plugin</artifactId>
  <version>2.1.2</version>
  <executions>
   <execution>
    <id>bundle-sources</id>
    <phase>package</phase>
    <goals>
     <goal>jar</goal>
    </goals>
   </execution>
  </executions>
</plugin>

  • Add below snip to parent pom to unzip generated source

          <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>unpack-artifact-sources</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>unpack</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>com.intel.ase.osg</groupId>
                                    <artifactId>com.intel.ase.osg.core</artifactId>
                                    <version>${ase.osg.version}</version>
                                    <classifier>sources</classifier>
                                    <overWrite>true</overWrite>
                                </artifactItem>
                            </artifactItems>
                            <outputDirectory>${project.build.directory}/unpack_sources</outputDirectory>
                        </configuration>
                    </execution>
                    <!-- add more unpack-executions here -->
                </executions>
            </plugin>

  • Add below snip to generate javaDoc from unzip source files
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-javadoc-plugin</artifactId>
            <version>2.7</version>
            <configuration>
                <sourcepath>${project.build.directory}/unpack_sources</sourcepath>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>javadoc</goal>
                    </goals>
                    <phase>process-resources</phase>
                </execution>
            </executions>
        </plugin> 


When you call mvn clean install at this point you will end up with a site folder inside your target folder. In this site folder you'll find your apidocs.