Skip to Content
author's profile photo Former Member
Former Member

Problem downloading file from EP6

I have implemented a very simple Java iView which basically retrieves and downloads a file to a client's browser. When I test this iView using the PDK with Tomcat 3.3.1a it works well. As soon as it is moved to the actual EP6 Portal installation on a Unix machine the Open/Save dialogue that the browser displays is popped up between 2 and 4 times before the file is downloaded.

In order to implement the iView I started from an AbstractPortalComponent. After I have retrieved the file requested, I get the actual HttpServletResponse object from the PortalComponentRequest object setting the flag to true.

I then set the content type and add an http header and stream the file back to the client. The http header I am adding is content-disposition.

Doe anyone have any ideas as to what may be causing the multiple pop-ups?

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2003 at 10:40 AM

    Below is the source. Thanks.

    package com.portal.ted.tdw.iview.filedownload;

    import java.io.PrintWriter;

    import javax.servlet.http.HttpServletResponse;

    import com.sap.mw.jco.IFunctionTemplate;

    import com.sap.mw.jco.IRepository;

    import com.sap.mw.jco.JCO;

    import com.sapportals.portal.prt.component.AbstractPortalComponent;

    import com.sapportals.portal.prt.component.IPortalComponentContext;

    import com.sapportals.portal.prt.component.IPortalComponentProfile;

    import com.sapportals.portal.prt.component.IPortalComponentRequest;

    import com.sapportals.portal.prt.component.IPortalComponentResponse;

    import com.sapportals.portal.prt.logger.ILogger;

    import com.sapportals.portal.prt.runtime.IPortalConstants;

    import com.sapportals.portal.prt.service.jco.IJCOClientPoolEntry;

    import com.sapportals.portal.prt.service.jco.IJCOClientService;

    import com.sapportals.portal.prt.session.IUserContext;

    public class FileDownload extends AbstractPortalComponent

    {

    public void doContent(

    IPortalComponentRequest request,

    IPortalComponentResponse response)

    {

    String lErrorMessage;

    //get the request, context, profile

    IPortalComponentContext lContext = request.getComponentContext();

    IPortalComponentProfile lProfile = lContext.getProfile();

    //get the parameters from the request

    String lDOKAR = request.getParameter("DOKAR");

    String lDOKNR = request.getParameter("DOKNR");

    String lDOKVR = request.getParameter("DOKVR");

    String lDOKTL = request.getParameter("DOKTL");

    String lAPPNR = request.getParameter("APPNR");

    String lInline = request.getParameter("INL");

    //print out parameters for debug

    System.out.println("DOKAR = " + lDOKAR);

    System.out.println("DOKNR = " + lDOKNR);

    System.out.println("DOKVR = " + lDOKVR);

    System.out.println("DOKTL = " + lDOKTL);

    System.out.println("APPNR = " + lAPPNR);

    System.out.println("INL = " + lInline);

    //set the http header content disposition type to either inline or attachment

    String lDispositionType = "inline";

    if (lInline != null)

    {

    if (lInline.equalsIgnoreCase("N"))

    {

    lDispositionType = "attachment";

    }

    }

    //get the user from the request

    IUserContext lUserContext = request.getUser();

    String lUserID = lUserContext.getUserId();

    System.out.println("USERID = " + lUserID);

    String lR3Dest = lProfile.getProperty("R3DEST");

    lProfile.store();

    ILogger log = request.getLogger(IPortalConstants.IVIEW_LOGGER);

    JCO.Client lJCOClient = null;

    try

    {

    IJCOClientService lJCOClientService =

    (IJCOClientService) request.getService(IJCOClientService.KEY);

    IJCOClientPoolEntry lJCOPoolEntry =

    lJCOClientService.getJCOClientPoolEntry(lR3Dest, request);

    lJCOClient = lJCOPoolEntry.getJCOClient();

    lJCOClient.connect();

    IRepository lRepository1 = JCO.createRepository("repository", lJCOClient);

    IFunctionTemplate lFuncTemplate =

    lRepository1.getFunctionTemplate("Z_SCC_IVIEW_GET_FILE_CONT");

    JCO.Function lJCOFunction = new JCO.Function(lFuncTemplate);

    JCO.ParameterList importList =

    lJCOFunction.getImportParameterList();

    importList.setValue(lDOKAR, "PF_DOKAR");

    importList.setValue(lDOKNR, "PF_DOKNR");

    importList.setValue(lDOKVR, "PF_DOKVR");

    importList.setValue(lDOKTL, "PF_DOKTL");

    importList.setValue(lAPPNR, "PF_APPNR");

    lJCOClient.execute(lJCOFunction);

    // Print return message

    JCO.Structure lJCOReturn =

    lJCOFunction.getExportParameterList().getStructure(

    "PSX_MESSAGE");

    String lMimeType =

    lJCOFunction.getExportParameterList().getString("PF_MIMETYPE");

    System.out.println(

    "MIME TYPE "

    + lJCOFunction.getExportParameterList().getString(

    "PF_MIMETYPE"));

    String lFilename =

    lJCOFunction.getExportParameterList().getString("PF_FILENAME");

    System.out.println("File Name = " + lFilename);

    JCO.Table lTable =

    lJCOFunction.getTableParameterList().getTable("PT_CONTENT");

    StringBuffer lHexData = new StringBuffer();

    lTable.firstRow();

    int lFileLength = Integer.parseInt(lTable.getString("ORLN"));

    System.out.println("orln = " + lTable.getString("ORLN"));

    lHexData.append(lTable.getString("ORBLK"));

    while (lTable.nextRow())

    {

    lHexData.append(lTable.getString("ORBLK"));

    }

    //System.out.println("orln1 = " + lHexData.toString());

    //Convert to byte array

    byte[] lFileData = fromHexString(lHexData.toString());

    byte[] lFileData2 = new byte[lFileLength];

    for (int i = 0; i < lFileLength; i++)
    {
    lFileData2 = lFileData;

    //System.out.println(lFileData);
    }

    System.out.println(
    "BAPI RETURN: " + lJCOReturn.getString("MSG_TXT"));
    System.out.println("Msg ID: " + lJCOReturn.getString("MSG_ID"));
    System.out.println("Msg Number: " + lJCOReturn.getString("MSG_NO"));

    //set the status of the return
    if (lJCOReturn.getString("MSG_TYPE").equalsIgnoreCase("A")
    || lJCOReturn.getString("MSG_TYPE").equalsIgnoreCase("E"))
    {
    HttpServletResponse lResponse = request.getServletResponse(true);


    lResponse.setContentType("text/html");

    PrintWriter out = lResponse.getWriter();
    out.println("
    "+
    "Download Error: " + lJCOReturn.getString("MSG_TXT") + "");

    out.close();

    }

    else

    {

    //the upload was successful

    //FCBean1.setPassed(true);

    }

    //Close the connection

    lJCOPoolEntry.release();

    System.out.println("End of Process: ");

    //lMimeType = "text/plain ";

    //lFilename = "";

    HttpServletResponse lResponse = request.getServletResponse(true);

    lResponse.addHeader(

    "Content-Disposition: ",

    lDispositionType + "; filename=" + lFilename);

    lResponse.setContentType(lMimeType);

    lResponse.getOutputStream().write(lFileData2);

    lResponse.getOutputStream().close();

    // catch any exception

    }

    catch (NullPointerException ex)

    {

    log.severe("NullPointerException - did you authenticate?");

    lErrorMessage = ex.getLocalizedMessage();

    System.out.println("Error 1: " + lErrorMessage);

    System.out.println(ex);

    }

    catch (JCO.Exception ex)

    {

    log.severe(

    "JCO.Exception (" + ex.getGroup() + "): " + ex.getMessage());

    lErrorMessage = ex.getLocalizedMessage();

    System.out.println("Error 2 " + lErrorMessage);

    }

    catch (Exception ex)

    {

    log.severe("Exception caught: " + ex.getMessage());

    lErrorMessage = ex.getLocalizedMessage();

    System.out.println("Error 3: " + lErrorMessage);

    }

    }

    /**

    • Convert a hex string to a byte array.

    • Permits upper or lower case hex.

    • @param s String must have even number of characters.

    • and be formed only of digits 0-9 A-F or

    • a-f. No spaces, minus or plus signs.

    • @return corresponding byte array.

    */

    public static byte[] fromHexString(String s)

    {

    int stringLength = s.length();

    if ((stringLength & 0x1) != 0)

    {

    throw new IllegalArgumentException("fromHexString requires an even number of hex characters");

    }

    byte[] b = new byte[stringLength / 2];

    for (int i = 0, j = 0; i < stringLength; i = 2, j+)

    {

    int high = charToNibble(s.charAt(i));

    int low = charToNibble(s.charAt(i + 1));

    b[j] = (byte) ((high << 4) | low);

    }

    return b;

    }

    /**

    • convert a single char to corresponding nibble.

    • @param c char to convert. must be 0-9 a-f A-F, no

    • spaces, plus or minus signs.

    • @return corresponding integer

    */

    private static int charToNibble(char c)

    {

    if ('0' <= c && c <= '9')

    {

    return c - '0';

    }

    else if ('a' <= c && c <= 'f')

    {

    return c - 'a' + 0xa;

    }

    else if ('A' <= c && c <= 'F')

    {

    return c - 'A' + 0xa;

    }

    else

    {

    throw new IllegalArgumentException("Invalid hex character: " + c);

    }

    }

    }

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2003 at 07:35 PM

    Could you paste some source code here, pls?

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 07, 2004 at 06:59 AM

    Hi,

    I have a requirement of upload and download a file from EP6 to R/3 4.6C.

    Infact I want to attach a file from EP6 to purchase order.

    This has to be done from EP6.

    I am also doing R & D on GOS and BDN. Can u please let me understand the functioality of the FM 'Z_SCC_IVIEW_GET_FILE_CONT', How are u taking the file name. How do u read the content of this. R u working on 4.6C or 4.7

    Thanks in advace

    Bhavani

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jun 07, 2004 at 07:00 AM

    Hi,

    I have a requirement of upload and download a file from EP6 to R/3 4.6C.

    Infact I want to attach a file from EP6 to purchase order.

    This has to be done from EP6.

    I am also doing R & D on GOS and BDN. Can u please let me understand the functioality of the FM 'Z_SCC_IVIEW_GET_FILE_CONT', How are u taking the file name. How do u read the content of this. R u working on 4.6C or 4.7

    Thanks in advace

    Bhavani

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.