Posts

Read pubsub message publish time using Apache beam with Google dataflow

This is a simple message to read publishTime of a message when reading using PubSub IO. @ProcessElement     public void processElement(DoFn<String, MessageDTO>.ProcessContext c) throws Exception {                 MessageDTO dataPacket = c.element();                 Instant time = c.timestamp();                dto.setPubsubTimestamp(time.toDateTime());         c.output(dto);        }

Handle CORS problem using java (Servlet/Filter)

Handle CORS problem using java (Servlet/Filter) 1. Make a Filter to handle all CORS request import java.io.IOException; import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /**  * Servlet Filter implementation class CORSFilter  */ public class CORSFilter implements Filter {         public CORSFilter() {         // TODO Auto-generated constructor stub     }         public void destroy() {         // TODO Auto-generated method stub     }             public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {         HttpServletRequest request = (HttpServletRequest) servletRequest;              HttpServletResponse resp = (HttpServletResponse) servletResp

Read Images from a xlsx file using Apache POI

This article is all about how to read and download images inside a file in xlsx format. We will use Apache POI using java. 1. Maven dependencies commons-logging-1.2.jar  commons-collections4-4.1.jar openxml4j-1.0-betapoi-3.16.jar poi-ooxml-3.16.jar poi-ooxml-schemas-3.16.jar xmlbeans-2.6.0.jar servlet-api 2. Sharing java code import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.poi.ss.usermodel.PictureData; import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFDrawing; import org.apache.poi.xssf.usermodel.XSSFPicture; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFShape; import org.apache.poi.xssf.usermodel.XSSFSheet; import

Read Excel using Apache POI - Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException:

Read Excel using Apache POI - Challenges ------------------------------------------------ 1) E xception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF) Add following maven dependency -- Use poi-ooxml from xlsx files while poi for xls <!-- POI : Excel library -->   <dependency>   <groupId>org.apache.poi</groupId>   <artifactId>poi</artifactId>   <version>${poi.version}</version>   </dependency>   <dependency>        < groupId>org.apache.poi</groupId>           <artifactId>poi-ooxml</artifactId>         <version>${poi.version}</version>   </dependency 2)Caused by: java.la

Create and write Excel file using Google App Engine

This article explains how you can export data in excel using Google App Engine. 1. Apache POI library -- Here is maven dependency         <dependency>         <groupId>org.apache.poi</groupId>         <artifactId>poi</artifactId>     <version>3.16</version> 2. Download Servlet import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; public class ExcelServlet extends HttpServlet {     private static final long serialVersionUID = 1L;     

Git Commands : How to remove all files deleted from index

Remove all deleted files from git index git ls-files --deleted -z | xargs -0 git rm

Create java client from WSDL for Google App engine

This post will explain how to consume SOAP based web services on Google App Engine platform. Keep your wsdl files in resources/wsdl folder Make these files entry in appengine-web.xml like   <static-files>        <include path="/**.wsdl"/>      <include path="/**.WSDL"/>  </static-files>  Now update POM file for wsdl to java plugin  <plugin>     <groupId>org.apache.cxf</groupId>     <artifactId>cxf-codegen-plugin</artifactId>     <version>3.0.1</version>     <executions>         <execution>             <id>generate-sources</id>             <phase>generate-sources</phase>             <configuration>                              <sourceRoot>${basedir}/src/main/java</sourceRoot>                 <wsdlOptions>                     <wsdlOption>                           <wsdl>src/main/resources/wsdl/ReadData.wsdl</wsdl>