Time remaining:
IO stream exception

label Programming
account_circle Unassigned
schedule 0 Hours
account_balance_wallet $5

How to resolve this exception

org.mortbay.jetty.EofException

org.mortbay.jetty.EofException

org.mortbay.jetty.HttpConnection$Output@f09f9a

at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:760)

at org.mortbay.jetty.AbstractGenerator$Output.flush(AbstractGenerator.java:566)

at org.mortbay.jetty.HttpConnection$Output.flush(HttpConnection.java:911)

at sun.nio.cs.StreamEncoder.implFlush(StreamEncoder.java:297)

at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:141)

at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:229)

at java.io.BufferedWriter.flush(BufferedWriter.java:254)

at com.fedex.forecast.datamart.server.util.CSVFileDownloadServlet.writeCsv(CSVFileDownloadServlet.java:180)

at com.fedex.forecast.datamart.server.util.CSVFileDownloadServlet.doPost(CSVFileDownloadServlet.java:75)

at com.fedex.forecast.datamart.server.util.CSVFileDownloadServlet.doGet(CSVFileDownloadServlet.java:38)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)

at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)

at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)

at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)

at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)

at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)

at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)

at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)

at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)

at org.mortbay.jetty.Server.handle(Server.java:324)

at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)

at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:829)

at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)

at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)

at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)

at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)

at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)

Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host

at sun.nio.ch.SocketDispatcher.write0(Native Method)

at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)

at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:94)

at sun.nio.ch.IOUtil.write(IOUtil.java:51)

at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:450)

at org.mortbay.io.nio.ChannelEndPoint.flush(ChannelEndPoint.java:160)

at org.mortbay.io.nio.SelectChannelEndPoint.flush(SelectChannelEndPoint.java:207)

at org.mortbay.jetty.HttpGenerator.flush(HttpGenerator.java:693)

... 28 more


Nov 30th, -0001
show it to me, i will do it for you.
Jun 26th, 2013

this is my csv servlet class. let me know how to remove that iostream error n how can i improve my current writer to put more data into csv file

package com.fedex.forecast.datamart.server.util;

import java.io.BufferedWriter;

import java.io.IOException;

import java.io.OutputStream;

import java.io.OutputStreamWriter;

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.util.Date;

import java.util.List;

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.log4j.Logger;

import com.fedex.forecast.datamart.client.ui.bean.DomesticDMAHistBean;

import com.fedex.forecast.datamart.server.DomesticServiceImpl;

public class CSVFileDownloadServlet extends HttpServlet {

DomesticServiceImpl domesticServiceImpl = new DomesticServiceImpl();

List<DomesticDMAHistBean> exportToExcelList = null;

private static final double MEG = (Math.pow(8192, 4));

private static final long serialVersionUID = 1L;

private Logger log = Logger.getLogger(CSVFileDownloadServlet.class);

String EMPTYDATA = "No data found for this query";

static DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");

static Date today = Calendar.getInstance().getTime();

static String reportDate = df.format(today);

public void doGet(HttpServletRequest req, HttpServletResponse response)

throws ServletException, IOException {

doPost(req, response);

}

public void doPost(HttpServletRequest req, HttpServletResponse response)

throws ServletException, IOException {

ServletOutputStream output = null;

char seperator = ',';

output = response.getOutputStream();

try {

String Productlist = req.getParameter("Productlist");

String DMAlist = req.getParameter("DMAlist");

String Metriclist = req.getParameter("Metriclist");

String Distlist = req.getParameter("Distlist");

String Yearmonthlist = req.getParameter("Yearmonthlist");

String Tablename = req.getParameter("Tablename");

response.setContentType("text/csv");

response.setHeader("Content-Disposition",

"attachment; filename=data.csv");

if ((Productlist != null) && (DMAlist != null)

&& (Metriclist != null) && (Distlist != null)

&& (Yearmonthlist != null)) {

if (DMAlist.equalsIgnoreCase("Large")) {

exportToExcelList = domesticServiceImpl

.getDomesticDMAHistIncluAllRegion(Productlist,

Metriclist, Distlist, Yearmonthlist);

} else {

exportToExcelList = domesticServiceImpl.getDomesticDMAHist(

Productlist, DMAlist, Metriclist, Distlist,

Yearmonthlist);

}

} else {

exportToExcelList = domesticServiceImpl

.getCompleteDMAHistList();

}

if (exportToExcelList.size() > 0) {

writeCsv(exportToExcelList, seperator, Tablename, output);

} else {

createCSVWithoutData(EMPTYDATA, output);

}

} catch (Exception e) {

log.error("Exception while downloading offers excel sheet . ", e);

System.out.println(e);

e.printStackTrace();

throw new ServletException(e);

} finally {

if (output != null) {

System.out.println(output);

output.close();

// clearing the objects for reclaiming allocated memory

}

}

}

public static void writeCsv(List<DomesticDMAHistBean> exportToExcelList,

char seperator, String Tablename, OutputStream output)

throws IOException {

OutputStreamWriter outWriter = new OutputStreamWriter(output);

BufferedWriter writer = new BufferedWriter(outWriter, (int) MEG);

writer.append(Tablename);

writer.append(seperator);

writer.append(seperator);

writer.append(reportDate);

writer.newLine();

writer.newLine();

writer.append("YearMonth");

writer.append(seperator);

writer.append("Product");

writer.append(seperator);

writer.append("Region");

writer.append(seperator);

writer.append("DistanceCategory");

writer.append(seperator);

if (exportToExcelList.get(0).getPackages() != null

&& !exportToExcelList.get(0).getPackages().isEmpty()) {

writer.append("Packages");

writer.append(seperator);

}

if (exportToExcelList.get(0).getPounds() != null

&& !exportToExcelList.get(0).getPounds().isEmpty()) {

writer.append("Pounds");

writer.append(seperator);

}

if (exportToExcelList.get(0).getApound() != null

&& !exportToExcelList.get(0).getApound().isEmpty()) {

writer.append("Apounds");

writer.append(seperator);

}

if (exportToExcelList.get(0).getNetrev() != null

&& !exportToExcelList.get(0).getNetrev().isEmpty()) {

writer.append("Netrev");

writer.append(seperator);

}

if (exportToExcelList.get(0).getFuelsch() != null

&& !exportToExcelList.get(0).getFuelsch().isEmpty()) {

writer.append("Fuel SCH");

writer.append(seperator);

}

if (exportToExcelList.get(0).getTotalsch() != null

&& !exportToExcelList.get(0).getTotalsch().isEmpty()) {

writer.append("Total SCH");

writer.append(seperator);

}

writer.newLine();

for (DomesticDMAHistBean bean : exportToExcelList) {

writer.append(bean.getMonthyear());

writer.append(seperator);

writer.append(bean.getProductCode());

writer.append(seperator);

writer.append(bean.getDmaCode());

writer.append(seperator);

writer.append(bean.getDistanceCode());

writer.append(seperator);

if (bean.getPackages() != null) {

writer.append(bean.getPackages());

writer.append(seperator);

}

if (bean.getPounds() != null) {

writer.append(bean.getPounds());

writer.append(seperator);

}

if (bean.getApound() != null) {

writer.append(bean.getApound());

writer.append(seperator);

}

if (bean.getNetrev() != null) {

writer.append(bean.getNetrev());

writer.append(seperator);

}

if (bean.getFuelsch() != null) {

writer.append(bean.getFuelsch());

writer.append(seperator);

}

if (bean.getTotalsch() != null) {

writer.append(bean.getTotalsch());

writer.append(seperator);

}

writer.newLine();

writer.flush();

}

writer.close();

}

public static void createCSVWithoutData(String EMPTYDATA,

OutputStream output) throws IOException {

OutputStreamWriter outWriter = new OutputStreamWriter(output);

BufferedWriter writer = new BufferedWriter(outWriter, (int) MEG);

writer.append(EMPTYDATA);

writer.flush();

}

}


daoclass - which is getting table info from database

public List<DomesticDMAHistBean> getDomesticDMAHist(String Productlist,

String dMAlist, String metrics, String dist, String yrmnth) {

domesticDMAHistBeanlist.clear();

try {

Connection connection = PoolManager.getConnection();

Statement stmt = connection.createStatement();

String sqlpro = "select CODE from DOM_REFERENCE_TABLE WHERE NAME IN ("

+ Productlist + ")";

String sqldma = "select CODE from DOM_REFERENCE_TABLE WHERE NAME IN ("

+ dMAlist + ")";

String sqldis = "select CODE from DOM_REFERENCE_TABLE WHERE NAME IN ("

+ dist + ")";

String sql = "select SSHIPYM,PRODUCT,DMA,DISTCAT," + metrics

+ " from DOM_EXP_DMA_HIST WHERE SSHIPYM IN (" + yrmnth

+ ") AND PRODUCT IN (" + sqlpro + ") AND DMA IN (" + sqldma

+ ") AND DISTCAT IN (" + sqldis + ") AND ROWNUM< = 900000";

ResultSet set = stmt.executeQuery(sql);

List<String> list = new ArrayList<String>(Arrays.asList(metrics

.split("[,]")));

while (set.next()) {

String yr = set.getString("SSHIPYM");

String prod = set.getString("PRODUCT");

String dma = set.getString("DMA");

String dst = set.getString("DISTCAT");

if (list.contains("POUNDS")) {

pounds = set.getString("POUNDS");

}

if (list.contains("PACKAGES")) {

pckg = set.getString("PACKAGES");

}

if (list.contains("NETREV")) {

netrev = set.getString("NETREV");

}

if (list.contains("FUELSCH")) {

fuelsch = set.getString("FUELSCH");

}

if (list.contains("APOUNDS")) {

apounds = set.getString("APOUNDS");

}

if (list.contains("TOTALSCH")) {

totalsch = set.getString("TOTALSCH");

}

DomesticDMAHistBean domesticDMAHistBean = new DomesticDMAHistBean();

domesticDMAHistBean.setMonthyear(yr);

domesticDMAHistBean.setProductCode(prod);

domesticDMAHistBean.setDmaCode(dma);

domesticDMAHistBean.setDistanceCode(dst);

domesticDMAHistBean.setPackages(pckg);

domesticDMAHistBean.setPounds(pounds);

domesticDMAHistBean.setNetrev(netrev);

domesticDMAHistBean.setFuelsch(fuelsch);

domesticDMAHistBean.setApound(apounds);

domesticDMAHistBean.setTotalsch(totalsch);

domesticDMAHistBeanlist.add(domesticDMAHistBean);

}

} catch (Exception e) {

logger.error(e);

System.out.println(e);

}

System.out.println(domesticDMAHistBeanlist.size());

return domesticDMAHistBeanlist;

}


Jun 26th, 2013

sorry i forgot to include tools i am using for client & server side

1. client side i am using GWT tool

2. server side I am using csv servlet class

I haven't included any code of client side.

deploying this application onto the jetty server which is inbuilt for GWT tool

Jun 26th, 2013

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Nov 30th, -0001
...
Nov 30th, -0001
Jun 27th, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer