Thursday, December 18, 2014

Not able to create Application in Store, UI hangs!

This  is the know issue in API-1.7.0.

Issue: Application can’t be created once the application count reaches 20.

 

Solution: Add the given line in the given file.

File name: repository/deployment/server/jaggeryapps/store/site/themes/fancy/templates/application/application-list/template.jag

Line: var urlPrefix = “”;





 

Wednesday, November 26, 2014

How to enable CORS in apache tomcat

This is the simplest way to enable CORS in apache tomcat.

 

Have to add the below configuration to your application’s web.xml and restart the tomcat if required.

 

<filter>

  <filter-name>CorsFilter</filter-name>

  <filter-class>org.apache.catalina.filters.CorsFilter</filter-class>

  <init-param>

    <param-name>cors.allowed.origins</param-name>

    <param-value>*</param-value>

  </init-param>

  <init-param>

    <param-name>cors.allowed.methods</param-name>

    <param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>

  </init-param>

  <init-param>

    <param-name>cors.allowed.headers</param-name>

    <param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>

  </init-param>

  <init-param>

    <param-name>cors.exposed.headers</param-name>

    <param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>

  </init-param>

  <init-param>

    <param-name>cors.support.credentials</param-name>

    <param-value>true</param-value>

  </init-param>

  <init-param>

    <param-name>cors.preflight.maxage</param-name>

    <param-value>10</param-value>

  </init-param>

</filter>

<filter-mapping>

  <filter-name>CorsFilter</filter-name>

  <url-pattern>/*</url-pattern>

</filter-mapping>



Thanks & Regards,

Rajakrishna Reddy

MySQL error java.sql.SQLException: Can't call commit when autocommit=true

When you see the error like below, please use the provided solution to get rid of this.

 

Caused by: java.sql.SQLException: Can't call commit when autocommit=true

        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:927)

        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:924)

        at com.mysql.jdbc.ConnectionImpl.commit(ConnectionImpl.java:1740)

        at sun.reflect.GeneratedMethodAccessor29.invoke(Unknown Source)

        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

        at java.lang.reflect.Method.invoke(Method.java:606)

        at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.wso2.carbon.ndatasource.rdbms.ConnectionRollbackOnReturnInterceptor.invoke(ConnectionRollbackOnReturnInterceptor.java:51)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor.invoke(AbstractCreateStatementInterceptor.java:71)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.interceptor.ConnectionState.invoke(ConnectionState.java:153)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.TrapException.invoke(TrapException.java:41)

        at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109)

        at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80)

        at com.sun.proxy.$Proxy14.commit(Unknown Source)

        at org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO.addAPI(ApiMgtDAO.java:4871)

        ... 65 more

 

 

Solution:

Use the url as shown here: <url>jdbc:mysql://varra:3306/DB_CARBON_IDENTITY?autoReconnect=true&amp;relaxAutoCommit=true</url>



Thanks & Regards,

Rajakrishna Reddy,

 

Tuesday, November 25, 2014

What is the best way to create an API in wso2 API-Manager 1.7.0

There was an issue with API improvements from 1.6.0 to 1.7.0 in multiple resource creation. Please apply attached PATCH-0580 to fix the issue.

 

Follow below mentioned guide to create multiple resources

 

1. To create multiple resources for a single uri-template (for multiple resource methods) refer below sample

 

ADD API:

 

curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=Twitter&visibility=public&version=1.0.0&description=API for twitter&endpointType=nonsecured&http_checked=http&https_checked=https&tags=tweet,test&tier=Bronze&thumbUrl=https://g.twimg.com/Twitter_logo_blue.png&context=/tweet&tiersCollection=Bronze,Gold,Unlimited&resourceCount=0&resourceMethod-0=GET,PUT,POST,DELETE&resourceMethodAuthType-0=Application,Application,Application,Application&uriTemplate-0=/test/*&resourceMethodThrottlingTier-0=Bronze, Bronze,Unlimited,Gold" -d 'endpoint_config={"production_endpoints":{"url":"http://search.twitter.com","config":null},"endpoint_type":"http"}'

 

UPDATE API:

 

curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag -d "action=updateAPI&name=Twitter&provider=provider&visibility=public&version=1.0.0&description=API for twitter changed&endpointType=nonsecured&http_checked=http&https_checked=https&tags=tweet,test&tier=Bronze&thumbUrl=https://g.twimg.com/Twitter_logo_blue.png&context=/tweet&tiersCollection=Bronze,Gold,Unlimited&resourceCount=0&resourceMethod-0=GET,PUT,POST&resourceMethodAuthType-0=Application,Application,Application&uriTemplate-0=/test/*&resourceMethodThrottlingTier-0=Gold,Gold,Gold" -d 'endpoint_config={"production_endpoints":{"url":"http://search.twitter.com","config":null},"endpoint_type":"http"}'

 

 

2. To create multiple resources with multiple uri-templates refer below sample

 

curl -X POST -b cookies http://localhost:9763/publisher/site/blocks/item-add/ajax/add.jag -d "action=addAPI&name=Twitter&visibility=public&version=1.0.0&description=API for twitter&endpointType=nonsecured&http_checked=http&https_checked=https&tags=tweet,test&tier=Bronze&thumbUrl=https://g.twimg.com/Twitter_logo_blue.png&context=/tweet&tiersCollection=Bronze,Gold,Unlimited&resourceCount=2&resourceMethod-0=GET,PUT,POST,DELETE&resourceMethodAuthType-0=Application,Application,Application,Application&uriTemplate-0=/test/*&resourceMethodThrottlingTier-0=Bronze,Bronze,Unlimited,Gold&resourceMethod-1=GET,PUT&resourceMethodAuthType-1=Application User,Application User&uriTemplate-1=/test2/*&resourceMethodThrottlingTier-1=Unlimited,Unlimited" -d 'endpoint_config={"production_endpoints":{"url":"http://search.twitter.com","config":null},"endpoint_type":"http"}'

 

*NOTE : in this case follow following convention

resourceCount=[number of resources]

 

and for each resource parameters

[resource parameter]-[resource number 0,1,...]=[value]

example:

resourceMethod-1=GET

esourceMethodAuthType-1=Application .... etc.

 

Following configurations are also provided to manage api

default_version_checked, wsdl, wadl, inSequence, outSequence, faultSequence, responseCache, cacheTimeout, subscriptions, tenants,.. etc.


Thanks & Regards,

Rajakrishna Reddy,

 

Sunday, November 23, 2014

How to forward OAuth headers (Authorization) to backend Service using wso2 API-Manager

Needs a configuration change in api-manager.xml file under ${PRODUCT_HOME}/repository/conf/api-manager.xml

Eg:

 

<APIConsumerAuthentication>

        <!--

            Name of the security context header to be added to the validated requests.

        -->

        <SecurityContextHeader>X-JWT-Assertion</SecurityContextHeader>

 

        <!--

                Fully qualified name of the class that will retrieve additional user claims

                to be appended to the JWT. If not specified no claims will be appended.

                The DefaultClaimsRetriever class adds user claims from the default carbon user store.

        -->

 

 

        <!--

                Remove OAuth headers from outgoing message or keep with it.

        -->

 

        <RemoveOAuthHeadersFromOutMessage>false</RemoveOAuthHeadersFromOutMessage>

 

    </APIConsumerAuthentication>



Thanks & Regards,

Rajakrishna Reddy,

 

Sunday, November 16, 2014

Refresh token is missing in the token request with grant type is 'password'

This could be the possible scenario happens with wso2 AM.

1. If the token is generated thru UI for the first time, Refresh token may miss in the next token request with grant type as ‘password’.

2. Once that token is revoke with the curl request we were able to get the refresh token.
Sample curl request we used:
curl -k -d "token=<ACCESS_TOKEN_TO_BE_REVOKED>" -H "Authorization: Basic Base64Encoded(Consumer key:consumer secret)" http://localhost:8280/revoke

3. Even the "RefreshTokenValidityPeriod" expires server didn't generate the refresh token.We found that we need to investigate further on this point.

Following the configuration we found in the "identity.xml"

<AccessTokenDefaultValidityPeriod>3600</AccessTokenDefaultValidityPeriod>
<RefreshTokenValidityPeriod>84600</RefreshTokenValidityPeriod>
<RenewRefreshTokenForRefreshGrant>true</RenewRefreshTokenForRefreshGrant>

Enabling SSL in Tomcat 8

Keep the below entry in Tomcat 8 server under server.xml in conf dir.
eg: {$TOMCAT_HOME}/conf/server.xml

<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol" SSLEnabled="true" maxThreads="150" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
               keystoreFile="{your_cert(jks)_path}" keystorePass="{password}" />


Thursday, November 6, 2014

Error while executing API in wso2: ServiceContext in OperationContext does not match !

This error occurs when you try to execute an api with POST method rather GET, where this api accepts only GET method.

TID: [0] [AM] [2014-11-07 06:46:28,274] ERROR {org.apache.synapse.transport.passthru.TargetHandler} -  Unexpected error. {org.apache.synapse.transport.passthru.TargetHandler}
TID: [0] [AM] [2014-11-07 06:46:28,277] ERROR {org.apache.axis2.transport.base.threads.NativeWorkerPool} -  Uncaught exception {org.apache.axis2.transport.base.threads.NativeWorkerPool}
org.apache.axis2.engine.AxisError: ServiceContext in OperationContext does not match !
        at org.apache.axis2.context.MessageContext.setOperationContext(MessageContext.java:1404)
        at org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver.processResponse(MultitenantMessageReceiver.java:129)
        at org.wso2.carbon.core.multitenancy.MultitenantMessageReceiver.receive(MultitenantMessageReceiver.java:81)
        at org.apache.synapse.transport.passthru.TargetErrorHandler$1.run(TargetErrorHandler.java:134)
        at org.apache.axis2.transport.base.threads.NativeWorkerPool$1.run(NativeWorkerPool.java:172)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
        at java.lang.Thread.run(Thread.java:662)

Monday, October 6, 2014

Public wsdl for testing

We do need public available wsdls sometime over internet with out writing our own, the below site helps exactly what you want...

Please check: http://www.service-repository.com/


Thursday, October 2, 2014

Resetting mysql root password in Unix or Linux systems!

These are the quick steps you can proceed to reset the mysql password in Linux or Unix.
  1. Stop the mysql server
  2. Create a file in /tmp with filename:mysql-init with the content as below:
  3. UPDATE mysql.user SET Password=PASSWORD('80odP@s5') WHERE User='root';
    FLUSH PRIVILEGES;
  4. Execute the below command to start the MySQL with the new paasword
    mysqld_safe --init-file=/tmp/mysql-init &
  5. After the server has started successfully, delete /tmp/mysql-init. 
  6. Now try to log-in to MySQL with the new password.

 Happy coding!

Thursday, September 18, 2014

Maven source plugin

The best way to generate the source jar along with the classes using maven is using the below plugin.

Just keep this plugin in the build tag as shown below:

    <build>
         <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.1.2</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


Have fun!

Wednesday, September 17, 2014

Building the wso2 products

I was wondering how to build the wso2 products mainly IS and AM, I found them as very easy after talking to a friend Thanuja, one of the developers of IS in wso2.

There are 3 steps to follow to build:
  1. Build and install Kernal.
  2. Build and install Orbit.
  3. Build and install Chunk-11.
Do all those in order from the given below svn repo:
https://svn.wso2.org/repos/wso2/carbon

Most important thing is you have to do this with java: 1.6 and maven: 3.0.5.release versions only.


The 3rd step builds all the products by default, if you don't want all the products, then comment the unnecessary products in given files:
  1. components/pom.xml
  2. dependencies//pom.xml 
  3. features/pom.xml 
  4. products//pom.xml

Have fun :)

What is "final" keyword in java


The "final" is reserved keyword in java, hence can't be used it as a variable name or class name or any method name.
final is used at different places in different contexts. I illustrate the usage and essential meaning of this keyword in different contexts.

 There would be 4 different contexts, they are:

  1. Applying final keyword for a class, in class definition.
  2. Applying in a method definition.
  3. Using final keyword in a variable definition.
  4. It is used to access the variable inside an anonymous class.

Advantages of final keyword:
  • The "final" keyword is used for high performance.
  • Using final for caching the values of variables and objects.
  • It is used for static class binding.
  • It is used to variables which will be involving in multi-threading, since final resources can be accessed safely without any synchronization.
  • It helps the JVM in optimizing the classes, methods and variables.

Thursday, March 27, 2014

Free online education websites

There are many websites available for free education and learning. Really hats off to all of them..

When I searched the google for online free websites.. found alot... but I got a good link from Dunith D which has a good collection of websites.. Here is the list..


This is taken from Dunith.D .

Thanks to Dunith.

Sunday, March 23, 2014

Ant - downloading a file in ant.


<!-- To display the complete path of the files -->
<dirset id="dirs" dir="${maven_app_dir}" includes="*"/>
<pathconvert dirsep="/" pathsep="," property="dirs" refid="dirs"/>
<echo message="${dirs}"/>

<!-- <target name="bootstrap">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ant-contrib.jar" src="http://search.maven.org/remotecontent?filepath=ant-contrib/ant-contrib/1.0b3/ant-contrib-1.0b3.jar"/>
<echo message="ha ha " />
    </target> -->

Thursday, March 20, 2014

How to add custom html signature to the microsoft office outlook in 2007


If you are getting frustrated in adding a custom html message as a signature, then we both are same group... :)

This is the quickest and very powerful way of adding the signature.

Open C:\Users\{username}\AppData\Roaming\Microsoft\Signatures\{fileName} and select {fileName} and add the signature. Restart Office ... and enjoy.


Have fun.