Friday, 2 December 2016

Textual Representation of logo

Multipart Jersey Request Does not work with mule 3.5.0

We can create file upload functionality in mule which is described in this blog post. But this solution does not work with mule version 3.5.0 and throws errors like this.
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
 at java.lang.String.substring(String.java:1915)
 at org.mule.transport.http.multipart.MultiPartInputStream.parse(MultiPartInputStream.java:349)
 at org.mule.transport.http.multipart.MultiPartInputStream.getParts(MultiPartInputStream.java:304)
 at org.mule.transport.http.HttpMultipartMuleMessageFactory.extractPayloadFromHttpRequest(HttpMultipartMuleMessageFactory.java:35)
 at org.mule.transport.http.HttpMuleMessageFactory.extractPayload(HttpMuleMessageFactory.java:75)
 at org.mule.transport.AbstractMuleMessageFactory.doCreate(AbstractMuleMessageFactory.java:79)
 at org.mule.transport.AbstractMuleMessageFactory.create(AbstractMuleMessageFactory.java:63)
 at org.mule.transport.AbstractTransportMessageHandler.createMuleMessage(AbstractTransportMessageHandler.java:458)
 at org.mule.transport.AbstractTransportMessageProcessTemplate.createMessageFromSource(AbstractTransportMessageProcessTemplate.java:147)
 at org.mule.transport.http.HttpMessageProcessTemplate.createMessageFromSource(HttpMessageProcessTemplate.java:286)
 at org.mule.transport.AbstractTransportMessageProcessTemplate.getMuleEvent(AbstractTransportMessageProcessTemplate.java:48)
 at org.mule.execution.FlowProcessingPhase$1$1.process(FlowProcessingPhase.java:74)
 at org.mule.execution.FlowProcessingPhase$1$1.process(FlowProcessingPhase.java:63)
 at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
 at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
 at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
 at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
 at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
 at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
 at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
 at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
 at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
 at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
 at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
 at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:109)
 at org.mule.execution.FlowProcessingPhase$1.run(FlowProcessingPhase.java:62)
 at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
 at org.mule.work.WorkerContext.run(WorkerContext.java:286)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)


This is a known issue in mule and it is rectified in further version of mule , but not in 3.5.0 .
Now to resolve this , you need to remove mule-transport-http-3.5.0.jar file from mule_home/lib/mule folder and add mule-transport-http-3.3.1.jar and restart mule . It should work fine after that .

Wednesday, 30 November 2016

Textual Representation of logo

Access Denied Error When Sending Mail From Java

Sending Email from Java Class is very simple.Here is a simple java program to send emails .

import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * Created by abhishek.somani on 30/11/16.
 */
public class MailSender {

    public static void main(String[] args) throws MessagingException {
        new MailSender().sendMail();
    }

    public void sendMail() throws MessagingException {
        System.setProperty("mail.smtp.localhost","localhost");
        Properties props = new Properties();
        props.put("mail.smtp.localhost","javaroots.com");
        props.put("mail.smtp.host","javaroots.host");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", 587);
        
        Session session = Session.getInstance(props,
                new javax.mail.Authenticator() {
                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication("test@test", "abcd");
                    }
                });
        session.setDebug(true);

        InternetAddress[] toAddress = new InternetAddress[1];
        toAddress = InternetAddress.parse("gmail@rajnikant.com",false);

        Transport t = session.getTransport("smtp");
        t.connect("host",
                587,"abcd","abcd");
        MimeMessage message = new MimeMessage(session);

        message.setFrom(new InternetAddress("gmail@amitabh.com"));
        message.setRecipients(Message.RecipientType.TO,
                toAddress);
        message.setSubject("Testing Subject");

        String body = "DSADSADAASDD";
        message.setText(body,"utf-8");
        t.send(message,message.getAllRecipients());
    }

}


Now this program gives you following error , even transport.isConnected() returns true . So it means that password and username and other details are correct , and it is able to make a connection to smtp server , but still it is not able to send mail .

javax.mail.SendFailedException: Invalid Addresses;
  nested exception is:
 com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 : Client host rejected: Access denied

 at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1607)
 at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:887)
 at javax.mail.Transport.send0(Transport.java:191)
 at javax.mail.Transport.send(Transport.java:120)
 at com.services.RestServices.cancelManagerPicking(RestServices.java:2348)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke(Method.java:497)
 at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:187)
 at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:71)
 at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:280)
 at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
 at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
 at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
 at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
 at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1341)
 at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1273)
 at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1223)
 at org.mule.module.jersey.JerseyResourcesComponent.doInvoke(JerseyResourcesComponent.java:159)
 at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:122)
 at org.mule.component.AbstractComponent.access$000(AbstractComponent.java:57)
 at org.mule.component.AbstractComponent$1$1.process(AbstractComponent.java:238)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102)
 at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:51)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:94)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:50)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:22)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:66)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:61)
 at org.mule.component.AbstractComponent.process(AbstractComponent.java:156)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:94)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102)
 at org.mule.processor.AsyncInterceptingMessageProcessor.process(AsyncInterceptingMessageProcessor.java:97)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102)
 at org.mule.construct.DynamicPipelineMessageProcessor.process(DynamicPipelineMessageProcessor.java:54)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:94)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102)
 at org.mule.interceptor.AbstractEnvelopeInterceptor.process(AbstractEnvelopeInterceptor.java:51)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102)
 at org.mule.processor.AbstractFilteringMessageProcessor.process(AbstractFilteringMessageProcessor.java:40)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.AbstractInterceptingMessageProcessorBase.processNext(AbstractInterceptingMessageProcessorBase.java:102)
 at org.mule.construct.AbstractPipeline$1.process(AbstractPipeline.java:109)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.DefaultMessageProcessorChain.doProcess(DefaultMessageProcessorChain.java:94)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:50)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:22)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:66)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:61)
 at org.mule.construct.AbstractPipeline$3.process(AbstractPipeline.java:207)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.SimpleMessageProcessorChain.doProcess(SimpleMessageProcessorChain.java:43)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:50)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:22)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:66)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:61)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.SimpleMessageProcessorChain.doProcess(SimpleMessageProcessorChain.java:43)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.doProcess(InterceptingChainLifecycleWrapper.java:50)
 at org.mule.processor.chain.AbstractMessageProcessorChain.process(AbstractMessageProcessorChain.java:67)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.access$001(InterceptingChainLifecycleWrapper.java:22)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper$1.process(InterceptingChainLifecycleWrapper.java:66)
 at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
 at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
 at org.mule.execution.MessageProcessorExecutionTemplate.execute(MessageProcessorExecutionTemplate.java:44)
 at org.mule.processor.chain.InterceptingChainLifecycleWrapper.process(InterceptingChainLifecycleWrapper.java:61)
 at org.mule.transport.AbstractMessageReceiver.routeEvent(AbstractMessageReceiver.java:511)
 at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:226)
 at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:208)
 at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:200)
 at org.mule.transport.AbstractMessageReceiver.routeMessage(AbstractMessageReceiver.java:187)
 at org.mule.transport.http.HttpMessageReceiver$HttpWorker$1.process(HttpMessageReceiver.java:311)
 at org.mule.transport.http.HttpMessageReceiver$HttpWorker$1.process(HttpMessageReceiver.java:306)
 at org.mule.execution.ExecuteCallbackInterceptor.execute(ExecuteCallbackInterceptor.java:16)
 at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:30)
 at org.mule.execution.HandleExceptionInterceptor.execute(HandleExceptionInterceptor.java:14)
 at org.mule.execution.BeginAndResolveTransactionInterceptor.execute(BeginAndResolveTransactionInterceptor.java:54)
 at org.mule.execution.ResolvePreviousTransactionInterceptor.execute(ResolvePreviousTransactionInterceptor.java:44)
 at org.mule.execution.SuspendXaTransactionInterceptor.execute(SuspendXaTransactionInterceptor.java:50)
 at org.mule.execution.ValidateTransactionalStateInterceptor.execute(ValidateTransactionalStateInterceptor.java:40)
 at org.mule.execution.IsolateCurrentTransactionInterceptor.execute(IsolateCurrentTransactionInterceptor.java:41)
 at org.mule.execution.ExternalTransactionInterceptor.execute(ExternalTransactionInterceptor.java:48)
 at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:28)
 at org.mule.execution.RethrowExceptionInterceptor.execute(RethrowExceptionInterceptor.java:13)
 at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:109)
 at org.mule.execution.TransactionalErrorHandlingExecutionTemplate.execute(TransactionalErrorHandlingExecutionTemplate.java:30)
 at org.mule.transport.http.HttpMessageReceiver$HttpWorker.doRequest(HttpMessageReceiver.java:305)
 at org.mule.transport.http.HttpMessageReceiver$HttpWorker.processRequest(HttpMessageReceiver.java:251)
 at org.mule.transport.http.HttpMessageReceiver$HttpWorker.run(HttpMessageReceiver.java:163)
 at org.mule.transport.TrackingWorkManager$TrackeableWork.run(TrackingWorkManager.java:267)
 at org.mule.work.WorkerContext.run(WorkerContext.java:286)
 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
 at java.lang.Thread.run(Thread.java:745)
Caused by: com.sun.mail.smtp.SMTPAddressFailedException: 554 5.7.1 : Client host rejected: Access denied
The reason for this error was that you did not starttls in your program .Adding the following line fix the error .
props.put("mail.smtp.starttls.enable", "true");

Saturday, 10 September 2016

Textual description of firstImageUrl

How to Create Documentation of JAX-RS Web Services

In this post i will describe how to create a html document from you rest jersey class , which can be used by web sevices consumers easily .

First you need to install raml-for-jax-rs plugin in your eclipse or anypoint studio .

Once you start it properly , and go to your rest service JAX-RS class , and right click on it , you should be able to see "Generate raml for class" option . You click on it and provide name and location of your generated raml file .

Now you have your generated automatically by this awesome plugin , you need to convert it to html document . For that , you have to install raml to html plugin which is written in node.js . install this plugin and go to the location where you have generated the raml file .Now you have to just use following command :
raml2html RestServices.raml -o doc.html
Now your rest class is converted in good looking one page html document which you can expose on your web server .

Friday, 12 August 2016

Textual description of firstImageUrl

Download WebMaster Tool Data using Casper JS

This is a simple casper js script to automate your process of downloading webmaster tools reports .


Google Webmaster does not provide any api to download the data .

This simple casperjs script will allow you to download the data and automate the process .

please change the google account credentials and also the time period for which you want to download the report .
var page = require('webpage').create();
var xpath = require('casper').selectXPath;
var casper = require('casper').create({   
    verbose: true, 
    logLevel: 'debug',
    pageSettings: {
         loadImages:  false,         // The WebPage instance used by Casper will
         loadPlugins: false,         // use these settings
         userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537.4'
    }
});

// print out all the messages in the headless browser context
casper.on('remote.message', function(msg) {
    this.echo('remote message caught: ' + msg);
});

// print out all the messages in the headless browser context
casper.on("page.error", function(msg, trace) {
    this.echo("Page Error: " + msg, "ERROR");
});

var url = 'https://accounts.google.com/ServiceLogin';

casper.start(url, function() {
   // search for 'casperjs' from google form
   console.log("page loaded");
   this.fill('form#gaia_loginform', { 
        Email:'test', 
        Passwd:'test'
    }, true);
});

casper.thenEvaluate(function(){
   console.log("Page Title " + document.title);
});
var url = 'https://www.google.com/webmasters/tools/top-search-queries?hl=en&siteUrl=http://www.javaroots.com/&de=20150315&db=20150314&more=true&type=queries';
casper.thenOpen(url ,function (status) {
    /*var js = page.evaluate(function () {
        return document;
    });
    console.log(JSON.stringify(js)); */
 console.log(" trrsadsadsssssss");
});

casper.then(function() {
 console.log(" clickingggg first time ");
 this.click('#tsq-table-download > div:nth-child(1)');
 //this.click(xpath('//*[@class="goog-inline-block jfk-button jfk-button-standard"]'));
});


//casper.waitForSelector(xpath('/html/body/div[11]/div[3]/button[1]'), function() {
 casper.waitForSelector('.goog-buttonset-default', function() {

casper.then(function(){
  this.capture('abc.png', undefined, {
             format: 'png',
            quality: 100
     });
});
});

casper.then(function() {
 console.log(" clickingggg");
 //this.click(xpath('/html/body/div[11]/div[3]'));
 this.click('.goog-buttonset-default');
});

casper.on('resource.received', function(resource) {
 if(resource.url)
 {
  if(resource.url.indexOf("/top-search-queries-dl") > -1)
  {
   console.log(" resource url is " + resource.url);
   console.log("Downloading csv file");
   this.download(resource.url, 'ExportData.csv');
  }
 }
 
});
casper.run();
Post Comments and suggestions !!!!

Thursday, 4 August 2016

Textual description of firstImageUrl

How to migrate from SVN to GIT repository

This post describes step by step guide to migrate your svn repository to git repository.
First , lets have a look as why git is better than svn .

1) GIT is distributed, SVN is not.
 2) GIT stores content as metadata, SVN stores just files.
3) GIT branches are not the same as SVN branches.
4) GIT does not have a global revision no. like SVN do.
5) GIT’s content integrity is better than SVN.

Now we see the different structures of both these .
SVN :


->Trunk
->Branches
->Tags
->Extra DIR


GIT:


->Single Working Directory
.git directory stores binary format of branches , tags and other details.

Steps:

1. Download Subgit from above link
2. Make Sure you have java version >= 1.7
3. Note Down the SVN URL & Git Remotes
4. Extract the Downloaded archive.
5. Execute the below Commands
6. ~/Softwares/subgit-3.2.0/bin/subgit configure --layout auto https://svn.xysys.net/svn/dynamic-feed-server/projects/dsc dsc.git
7. The above command will detect the latest revision , history , branches, tags and configure authors.
8.  Once Done execute
9.  ~/Softwares/subgit-3.2.0/bin/subgit install dsc.git/  This would take some time depending on the revisions and the no of time file got modified to convert revision to git commits. Have Patience.
10. git clone dsc.git
11. This Would create your dsc git project with all tags , branches etc…
12. cd dsc && git branch –ar would list all the branches. You can also use git log to see the revisions converted to GIT Commits.
13. IMP:  git remote –v would saw you locat path which need to be changed to GIT Remote.
14. In mycase : In file .git/config , url = /Users/mohantysan/workspace/GitMigration/dsc.git 
We need to Change it to Git URL else if you make any commits and push it will push to SVN REPO.
Change the url to something like this :
url = git@github.com/ae/dsc.git
Now Your SVN Repo is Converted and ready to be published.
 git push origin –all # will push your code with all svn converted revision to GIT and you can use it as usual.
For Publishing Branches and Tags checkout branches and tags locally and push 
Happy Migration , Thank You

This post is created by Santosh Mohanty . You can contact him for any questions at santa.jyp@gmail.com or message him on his linkedIn profile .


Friday, 8 July 2016

Textual description of firstImageUrl

Jav 8 FlatMap Explained Stream API

In this short example , i will explain where we can use flatMap function of java stream api .

Suppose you have a multi level list where many objects are stored , and you want to convert it to a single list of objects . We can use flatmap which will flatten the list easily .

FlatMap basically first applies the transformation , and then then flatten the result in a single collection .

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by abhishek.somani on 8/7/16.
 */
public class JavarootsFlatMapExample {

    public static void main(String[] args) {
        String[] arr = {"abhishekl","somani"};
        String[] arr2 = {"java","example","1.8","stream"};
        List<List<String>> list = new ArrayList<>();
        list.add(Arrays.asList(arr));
        list.add(Arrays.asList(arr2));
        final List<String> strings = list.stream().flatMap(l -> l.stream()).collect(Collectors.toList());
        System.out.println(strings);
    }

}
Post Comments And Suggestions !!!

Tuesday, 5 April 2016

Textual description of firstImageUrl

Mule HttpListener Example

Mule Runtime 3.6 and later version have deprecated old Http Connector with , new Http Listener Config . Let's take an example to see how we can use it .This example also demonstrates how to get a particular xml element without using JAXB .

This example app will listen to a particular host and port , for post method , and parses the request xml using xpath . Based on the xml , we return the response based on the input xml received in request .

This is our mule config xml :
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
 xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.6.1"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd">

<http:listener-config port="8081" host="0.0.0.0" name="myRequestConfig" >
 <http:worker-threading-profile maxThreadsActive="15"/>
</http:listener-config>

<flow name="SimpleTest" >
<http:listener path="/abc" config-ref="myRequestConfig" allowedMethods="PATCH"/>
<logger category="d" level="ERROR" message="xpath: #[xpath3('/isCancelled')]"/>

<choice >
<when expression="#[xpath3('/isCancelled') == 'true']">
 <set-payload value="SUCCESSS"></set-payload>
</when>
<otherwise>
 <set-payload value="FAIL"></set-payload>
</otherwise>
</choice>
</flow>

</mule>
Now we can see that traditional http inbound endpoint and http connector is replaced with Http Listener and Http Listener Config respectively . The major difference is that we can not use service overrides in Http listener config like we used to do in http connector , also http listener does not return MULE_SESSION in response headers .If we use http listener , all outbound property will automatically be converted in http response headers . You can use allowedMethods attribute to configure different Http methods . We can have multiple http listener , referencing to same listener config . Multiple flows with same path but different methods is also allowed .

Post Comments And Suggestions .!!!