Thursday, July 18, 2013

Why do we get "PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target" exception?

Most of the time we might get an issue which says the following while trying to subscribe to emails in carbon products,


 [2013-07-18 11:25:22,974] ERROR {org.apache.axis2.transport.mail.MailTransportSender} - Error creating mail message or sending it to the configured server
javax.mail.MessagingException: Can't send command to SMTP host;
  nested exception is:
        javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target


This issue is occurred when the server has got self verified certificates and client's trust store does not have it. But in gmail there is a certificate that is issued by a CA. So if you use JRE certificate store ($JREHOME/lib/security/cacerts) in the client side, this issue may not be occurred as it contains some CA's root certificates. But this certificates store can be changed by setting system property 'javax.net.ssl.trustStore'.
Sometimes this blog might help you to store this certificate.

Why do we get "Failed Sending Email org.apache.axis2.AxisFault: The system cannot infer the transport information from the mailto" issue?


Most of the time in WSO2 Carbon products, users may encounter exceptions as follow when subscribing for a particular mail response:


[2013-07-17 09:49:45,781] ERROR {org.apache.axis2.description.ClientUtils} - The system cannot infer the transport information from the mailto:<email> URL.
Failed Sending Email
org.apache.axis2.AxisFault: The system cannot infer the transport information from the mailto : <email>

 at org.apache.axis2.description.ClientUtils.inferOutTransport(ClientUtils.java:81)
        at org.apache.axis2.client.OperationClient.prepareMessageContext(OperationClient.java:288)
        at org.apache.axis2.description.OutOnlyAxisOperationClient.executeImpl(OutOnlyAxisOperation.java:249)
        at org.apache.axis2.client.OperationClient.execute(OperationClient.java:149)
        at org.apache.axis2.client.ServiceClient.fireAndForget(ServiceClient.java:511)
        at org.apache.axis2.client.ServiceClient.fireAndForget(ServiceClient.java:488)
        at org.wso2.carbon.email.verification.util.EmailSender.run(EmailSender.java:115)
[2013-07-17 09:49:46,079] DEBUG {org.wso2.carbon.user.core.authorization.JDBCAuthorizationManager} - Authorization cache entry is not found for username

The reason can be :

The reason for this issue is the AxisConfiguration which uses to send this message does not have the mail transport. In axis2.xml you have to define the transportSender as below.

<transportSender name="mailto" class="org.apache.axis2.transport.mail.MailTransportSender">
        <parameter name="mail.smtp.from">user@gmail.com</parameter>
        <parameter name="mail.smtp.user">user</parameter>
        <parameter name="mail.smtp.password">mailpassword</parameter>
        <parameter name="mail.smtp.host">smtp.gmail.com</parameter>
        <parameter name="mail.smtp.port">587</parameter>
        <parameter name="mail.smtp.starttls.enable">true</parameter>
        <parameter name="mail.smtp.auth">true</parameter>
</transportSender> 


Sometimes having an unnecessary space in between these values might also be a reason for this issue.

Friday, July 12, 2013

How to test the disable HTTP chunking for outgoing messaging via WSO2 ESB and a REST request



There are few HTTP transport-specific properties in ESB.

Properties use in ESB access various types of information regarding a message that passes through the ESB. Also properties can be used to control the behavior of the ESB on a given message.

WSO2 ESB support transfer-encoding – chunked by default. To make it disabled, there is a property that would help to perform it.
 
      <property name="DISABLE_CHUNKING" value="true" scope="axis2"/>  


Transfer-encoding - chunked is a feature came along with HTTP 1.1. Therefore no matter what HTTP 1.0 will support only content type. Therefore if the message is forced to send as HTTP1.0 you will be able to see only the content type. Refer the previous blog post for more reference. Outgoing message can be seen in here.

By the following steps I will be explaining how to test this behavior if WSO2 ESB.


To Setup :
----------------
  1. Go to <ESB_Home>/samples/axis2Server/src/SimpleStockQuoteService and build it, ant

  2. Start the Go to <ESB_Home>/samples/axis2Server and start the axis2Server by the following command, sh axis2server.sh.

  3. Start the ESB Server, <ESB_Home>/bin by providing, sh wso2server.sh.

  4. Run a tcpMon to view the outgoing messages.

  5. Start the tcpmon in the <ESB_Home>/bin - sh tcpmon.sh
    Create 2 listeners as below. 

    1. Listen Port 8281, Target host – localhost, Target port – 8280 – Before hits the ESB
    2. Listen Port 9001, Target host – localhost, target port – 9000 – After passing through ESB and Before hits the backend
  1. Log in to the ESB and provide the following synapse configuration.


     <?xml version="1.0" encoding="UTF-8"?>  
     <definitions xmlns="http://ws.apache.org/ns/synapse">  
       <sequence name="fault">  
        <log level="full">  
          <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>  
          <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>  
          <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>  
        </log>  
        <drop/>  
       </sequence>  
       <sequence name="main">  
        <header name="Action" value="urn:getQuote"/>  
        <filter source="get-property('To')" regex=".*/StockQuote.*">  
         <property name="DISABLE_CHUNKING" value="true" scope="axis2"/>  
          <send>  
           <endpoint>  
             <address uri="http://localhost:9001/services/SimpleStockQuoteService"  
                 format="soap11"/>  
           </endpoint>  
          </send>  
          <drop/>  
        </filter>  
        <send/>  
       </sequence>  
     </definitions>  
    

To Send the Rest request :
---------------------------------------------

  1. Go to axis2Client, <ESB_Home>/samples/axis2Client and send the following REST request.
 ant stockquote -Dtrpurl=http://localhost:8281/services/StockQuote -Drest=true  


Observations :
-------------------------
  1. On the server side, Standard :: Stock price = $70.54750695255485 will be generated.
  2. Observe the tcpMon.

Rest request sent to ESB can be seen in port 8281,

Transfer-Encoding: chunked


Outgoing message from ESB can be seen in port 9001,

Content-Length: 275

How to test the Force HTTP 1.0 outgoing messages via WSO2 ESB and a REST request



There are few HTTP transport-specific properties in ESB.

Properties use in ESB access various types of information regarding a message that passes through the ESB. Also properties can be used to control the behavior of the ESB on a given message.
WSO2 ESB support HTTP 1.1 outgoing messages by default. To make it HTTP 1.0, there is a property that would help to perform it.
 
      <property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>  



By the following steps I will be explaining how to test this behavior if WSO2 ESB.


To Setup :
----------------
  1. Go to <ESB_Home>/samples/axis2Server/src/SimpleStockQuoteService and build it, ant

  2. Start the Go to <ESB_Home>/samples/axis2Server and start the axis2Server by the following command, sh axis2server.sh.

  3. Start the ESB Server, <ESB_Home>/bin by providing, sh wso2server.sh.

  4. Run a tcpMon to view the outgoing messages.

  5. Start the tcpmon in the <ESB_Home>/bin - sh tcpmon.sh
    Create 2 listeners as below. 

    1. Listen Port 8281, Target host – localhost, Target port – 8280 – Before hits the ESB
    2. Listen Port 9001, Target host – localhost, target port – 9000 – After passing through ESB and Before hits the backend
  1. Log in to the ESB and provide the following synapse configuration.


     <?xml version="1.0" encoding="UTF-8"?>  
     <definitions xmlns="http://ws.apache.org/ns/synapse">  
       <sequence name="fault">  
        <log level="full">  
          <property name="MESSAGE" value="Executing default &#34;fault&#34; sequence"/>  
          <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>  
          <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>  
        </log>  
        <drop/>  
       </sequence>  
       <sequence name="main">  
        <header name="Action" value="urn:getQuote"/>  
        <filter source="get-property('To')" regex=".*/StockQuote.*">  
         <property name="FORCE_HTTP_1.0" value="true" scope="axis2"/>  
          <send>  
           <endpoint>  
             <address uri="http://localhost:9001/services/SimpleStockQuoteService"  
                 format="soap11"/>  
           </endpoint>  
          </send>  
          <drop/>  
        </filter>  
        <send/>  
       </sequence>  
     </definitions>  
    

To Send the Rest request :
---------------------------------------------

  1. Go to axis2Client, <ESB_Home>/samples/axis2Client and send the following REST request.
 ant stockquote -Dtrpurl=http://localhost:8281/services/StockQuote -Drest=true  


Observations :
-------------------------
  1. On the server side, Standard :: Stock price = $157.06490695255485 will be generated.
  2. Observe the tcpMon.

Rest request sent to ESB can be seen in port 8281,


POST /services/StockQuote HTTP/1.1



Outgoing message from ESB can be seen in port 9001,


POST /services/SimpleStockQuoteService HTTP/1.0