Johannes; Thanks for your response.
I have attached: DownloadAction.java struts.xml tiles-def.xml web.xml If you need anything else, please let me know. John On Thu, 2012-02-23 at 23:13 -0800, Johannes Geppert wrote: > Hi John, > > can you share the Code of your Action and the configuration for this Action? > > Johannes > > ----- > web: http://www.jgeppert.com > twitter: http://twitter.com/jogep > -- > View this message in context: > http://struts.1045723.n5.nabble.com/Download-a-byteArray-jpg-image-to-browser-tp5509528p5511883.html > Sent from the Struts - User mailing list archive at Nabble.com. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] >
package com.edwardjones.photo.web.actions;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.edwardjones.framework.annotations.Lookup;
import com.edwardjones.framework.logging.EJLogger;
import com.edwardjones.framework.logging.EJLoggerFactory;
import com.edwardjones.framework.logging.TransactionInfo;
import com.edwardjones.framework.logging.TransactionInfoManager;
import com.edwardjones.photo.services.image.Image;
import com.edwardjones.photo.services.image.ImageApplicationException;
import com.edwardjones.photo.services.image.ImageStatsAware;
import com.opensymphony.xwork2.ActionSupport;
/**
* <p>
* Title: $RCSfile$
* </p>
* <p>
* Description: This action class ...
* </p>
* <p>
* Copyright: Copyright (c) 2012
* </p>
* <p>
* Company: Edward Jones
* </p>
*
* @author Name (j31316)
* @version $Revision$
*/
@Results
(
{
@Result(name = "success", location = "downloadPage", type = "tiles"),
@Result(name = "error", location = "error", type = "tiles"),
@Result(name = "download", type = "stream",
params = {
"contentType", "application/octet-stream",
"inputName", "fileInputStream",
"bufferSize", "1024"
}
)
}
)
public class DownloadAction extends ActionSupport {
// TODO Complete documentation in class Javadoc.
// TODO Replace "Name" with the author's name in the class Javadoc.
// TODO Update the title in tiles-def.xml.
// TODO Add content to the JSP.
// This class extends ActionSupport to enable validation and localization.
/**
* ID used for versioning.
*/
@SuppressWarnings("unused")
private static final String VERSION_ID = "$Id$";
/**
* Version number used during deserialization. This is required because the
* superclass, <tt>com.opensymphony.xwork2.ActionSupport</tt>, implements
* <tt>java.io.Serializable</tt>.
*/
private static final long serialVersionUID = 1L;
/**
* Standard logger.
*/
private static final EJLogger LOGGER = EJLoggerFactory
.getLogger(DownloadAction.class);
// TODO The @FrameworkInjected and @Lookup annotations are often used for dependency injection.
@Lookup("ImageSvc")
ImageStatsAware imageSvc;
TransactionInfoManager tiMgr;
TransactionInfo transactionInfo;
/* Default arguments */
private final String defaultColorFlag = "N";
private final String defaultContentCode = "A";
private final String defaultFormatCode = "JPG";
private final String defaultResolutionCode = "A";
private final String defaultSizeCode = "A";
private final String defaultSourceCode = "A";
// TODO Add instance variables and their corresponding getter and setter
// methods (use Source -> Generate Getters and Setters... in Eclipse) for
// all request parameters / attributes (attributes only require getter
// methods).
/**
* Creates a <tt>DownloadAction</tt> object.
*/
public DownloadAction() {
super();
}
/**
* TODO Add description
*
* @return The result, which will determine what action or JSP will be
* called after execution of the method.
*/
// TODO Add @Validations, as needed.
public String execute() {
// NOTE: The execute() method is the default one called by Struts 2 if
// the action name matches the class name, where camel-case names are
// converted to dashes. See
// http://struts.apache.org/2.1.6/docs/convention-plugin.html for more
// information.
// Initialize the forward name with the "success" value.
String forward = "success";
try {
// TODO Finish implementing this method (e.g., add a service call).
Image imagePhoto = fetchImageByEmployeeId(identifier);
ByteArrayInputStream fileInputStream = new ByteArrayInputStream(imagePhoto.getPhotoImage());
forward = "download";
}
catch (Exception e) {
LOGGER.error("Caught an error while executing the action.", e);
}
return forward;
}
private Image fetchImageByEmployeeId(String employeeId)
throws
ImageApplicationException
, IOException
{
Image imagePhoto = imageSvc.getImageByEmployeeId(employeeId, defaultSourceCode, defaultFormatCode, defaultResolutionCode, defaultColorFlag, defaultContentCode, defaultSizeCode, transactionInfo);
return imagePhoto;
}
/**
* colorFlag
*/
private String colorFlag;
/**
* contentCode
*/
private String contentCode;
/**
* formatCode
*/
private String formatCode;
/**
* identifier - An assortment of possible values
*/
private String identifier;
/**
* inputStream - Used to return the photo image
*/
private ByteArrayInputStream fileInputStream;
/**
* resolutionCode
*/
private String resolutionCode;
/**
* sizeCode
*/
private String sizeCode;
/**
* sourceCode
*/
private String sourceCode;
/**
* @return the colorFlag
*/
public String getColorFlag() {
return colorFlag;
}
/**
* @param colorFlag the colorFlag to set
*/
public void setColorFlag(String colorFlag) {
this.colorFlag = colorFlag;
}
/**
* @return the contentCode
*/
public String getContentCode() {
return contentCode;
}
/**
* @param contentCode the contentCode to set
*/
public void setContentCode(String contentCode) {
this.contentCode = contentCode;
}
/**
* @return the identifier
*/
public String getIdentifier() {
return identifier;
}
/**
* @param identifier the identifier to set
*/
public void setIdentifier(String identifier) {
this.identifier = identifier;
}
/**
* @return the fileInputStream
*/
public InputStream getFileInputStream() {
return fileInputStream;
}
/**
* @param inputStream the inputStream to set
*/
public void setFileInputStream(ByteArrayInputStream fileInputStream)
{
this.fileInputStream = fileInputStream;
}
/**
* @return the imageSvc
*/
public ImageStatsAware getImageSvc() {
return imageSvc;
}
/**
* @param imageSvc the imageSvc to set
*/
public void setImageSvc(ImageStatsAware imageSvc) {
this.imageSvc = imageSvc;
}
/**
* @return the formatCode
*/
public String getFormatCode() {
return formatCode;
}
/**
* @param formatCode the formatCode to set
*/
public void setFormatCode(String formatCode) {
this.formatCode = formatCode;
}
/**
* @return the resolutionCode
*/
public String getResolutionCode() {
return resolutionCode;
}
/**
* @param resolutionCode the resolutionCode to set
*/
public void setResolutionCode(String resolutionCode) {
this.resolutionCode = resolutionCode;
}
/**
* @return the sizeCode
*/
public String getSizeCode() {
return sizeCode;
}
/**
* @param sizeCode the sizeCode to set
*/
public void setSizeCode(String sizeCode) {
this.sizeCode = sizeCode;
}
/**
* @return the sourceCode
*/
public String getSourceCode() {
return sourceCode;
}
/**
* @param sourceCode the sourceCode to set
*/
public void setSourceCode(String sourceCode) {
this.sourceCode = sourceCode;
}
}
struts.xml
Description: XML document
tiles-def.xml
Description: XML document
web.xml
Description: XML document
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]

