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.