Tuesday, October 20, 2015

How to modify tenant API store main page in WSO2 API Manager.

In this article we will discuss how we can modify tenant API Store to support lengthy tenant domain names. With API Manager 1.9.0 we cannot have very lengthy names. In this modification we will show part of tenant name in store and show full name when you place mouse courser on tenant store.

in template.jag(/store/site/themes/fancy/templates/api/tenant-stores-listing/template.jag) paste following before this line

"<li class="thumbnail span3 tenent-thumb">"
<a href="<%= encode.forHtmlAttribute(encode.forUri(jagg.getSiteContext() + 
"?tenant="+tenantDomains[i])) %>" title="<%=tenantDomains[i]%>">

in css(styles-layout,css) do following
#tenent_list{ width:900px }
.tenent-thumb{ margin: 0.79% 0.79% !important; /* re-declare thumb border styles since it is overidden by styles-layout */ border: 1px solid #DDDDDD; border-radius: 4px 4px 4px 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.055); display: block; line-height: 20px; padding: 8px 4px 4px 4px; transition: all 0.2s ease-in-out 0s; }
.tenent-thumb h3{ margin:0px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width:200px; }

Then you will see it as follows.

Monday, October 19, 2015

How to create custom error message when our message flow hit fault sequence

When we use WSO2 ESB fault sequence may hit due to different reasons. In such cases we normally send error message as defined in fault sequence. In this blog i will explain how we can modify fault sequence to send customized error to client.

To try this i created simple proxy which directly go to fault sequence. In your case it can happen due to some other reason

<proxy name="testp"
transports="https http"
startOnLoad="true"
trace="disable">
<target>
<inSequence>
<sequence key="fault"/>
</inSequence>
<outSequence>
<send/>
</outSequence>
</target>
</proxy>

Inside fault sequence log message and call my custom sequence named convert.

<sequence name="fault">
<log>
<property name="Inside fault sequence============" expression="get-property('test')"/>
</log>
<sequence key="convert"/>
<drop/>
</sequence>

My convert sequence will generate custom error message and send it to client application.

<sequence name="convert">
<payloadFactory media-type="xml">
<format>
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>$1</am:code>
<am:type>Status report</am:type>
<am:message>Runtime Error</am:message>
<am:description>$2</am:description>
</am:fault>
</format>
<args>
<arg evaluator="xml" expression="$ctx:ERROR_CODE"/>
<arg evaluator="xml" expression="$ctx:ERROR_MESSAGE"/>
</args>
</payloadFactory>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<property name="HTTP_SC" value="555" scope="axis2"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="ContentType" scope="axis2" action="remove"/>
<property name="Authorization" scope="transport" action="remove"/>
<property name="Access-Control-Allow-Origin" value="*" scope="transport"/>
<property name="Host" scope="transport" action="remove"/>
<property name="Accept" scope="transport" action="remove"/>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
</sequence>

Client will recieve following error message as we difined in fault sequence.

Status Code: 555
Accept-Encoding: gzip, deflate
Accept-Language: null
Connection: keep-alive
Content-Type: application/json
Date: Tue, 20 Oct 2015 06:19:51 GMT
Server: WSO2-PassThrough-HTTP
Transfer-Encoding: chunked
access-control-allow-origin: *