Generate PDFS using Managed Bean with custom HTTP headers

Background
Generate a report in various formats (PDF, delimited, Excel, HTML, etc.) using JDeveloper 11 g Release 2 (11.1.2.3.0) when you click on an af:commandButton. See also the version StackOverflow about this issue:

http://StackOverflow.com/q/13654625/59087

Problem
The HTTP headers are sent twice: once by the framework and once by a bean.

Source code
The source code includes:

-Action button
-Managed Bean
-Task flow

Action button
The action of the button:

< af:commandButton text = 'Report' id = 'submitReport' action = "Execute" / >

Managed bean
The managed Bean is relatively complex. The code "responseComplete" get called, however, it does not seem to be called early enough to avoid the framework application writes the HTTP headers.

Substitution of HTTP response header

/**
* Defines the HTTP headers must indicate to the browser that the
* the report must be downloaded (not displayed in the current
* window).
*/
protected void setDownloadHeaders() {}
HttpServletResponse response = getServletResponse();
response.setHeader ("Content-Description", getContentDescription());
response.setHeader ("Content-Disposition", 'attachment filename ='
(+ getFilename());
response.setHeader ("Content-Type", getContentType());
response.setHeader ("Content-Transfer-Encoding',
getContentTransferEncoding());
}

Question answer full
The bean indirectly says infrastructure that the answer is managed (by the bean):

getFacesContext () .responseComplete ();

Bean, run and configure

public void run() {}
try {}
Report = getReport();
Configures (Report.GetParameters ());
Report.Run ();
} catch (Exception e) {}
e.printStackTrace ();
}
}

private void configuration (parameters p) {}
p.put (ReportImpl.SYSTEM_REPORT_PROTOCOL, "http");
p.put (ReportImpl.SYSTEM_REPORT_HOST, "localhost");
p.put (ReportImpl.SYSTEM_REPORT_PORT, "7002");
p.put (ReportImpl.SYSTEM_REPORT_PATH, "/ reports/rwservlet" "");
p.put (Parameters.PARAM_REPORT_FORMAT, 'pdf');

p.put ("report_cmdkey", getReportName());
p.put ("report_ORACLE_1", getReportDestinationType());
p.put ("report_ORACLE_2", getReportDestinationFormat());
}

Workflow
The workflow calls Execute, which refers to the 'run()' of the bean method:

entry-> Home-> run-> ReportBeanRun

Where:

<-l' call the method id = "ReportBeanRun" >
< description > running a report < / description >
Report to run < display name > < / display-name >
< method > #{reportBean.run} < / method >
< result >
success of < fixed-result > < / fixed-results >
< / results >
< / method >

The bean is assigned to the scope of the "demand", with a few managed properties:

< rule of flow control = "__3" id >
hand < of-activity-id > < /-activity-id >
< control-flow-case id = "ExecuteReport" >
run < from outcome > < / de-results >
ReportBeanRun < to-activity-id > < / to-activity-id >
< / control-flow-case >
< / control-flow-rule >

< managed-bean id = "ReportBean" >
< description > running a report < / description >
< display name > ReportBean < / display-name >
application of < managed-bean-scope > < / managed-bean-scope >
...
< / managed-bean >

The "success < fixed-result > < / fixed-result > ' strikes me as wrong - I don't want to not the method call to return to another task."

Restrictions
The report server receives requests from the web server only. The URL of the report server cannot use browsers to download directly, for security reasons.

Error messages
The error message is generated:
Duplicate received headers from the server

349 (net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION) error: multiple headers received separate Content-Disposition. It is not allowed to protect themselves against HTTP response splitting attacks. Nevertheless, the report is generated. Prevents the framework to write headers HTTP would solve this problem.

Question
How can define you HTTP headers in ADF using a workflow to generate a PDF file by calling a managed bean?

Ideas

Some additional ideas:

-Substitute the listener of the Phase of the lifecycle of Page ("ADFPhaseListener" + "PageLifecycle")
-Develop a customized web server Servlet

Related links
-http://www.oracle.com/technetwork/middleware/bi-publisher/adf-bip-ucm-integration-179699.pdf
-http://www.slideshare.net/lucbors/reports-no-notes#btnNext
-http://www.techartifact.com/blogs/2012/03/calling-oracle-report-from-adf-applications.html?goback=%2Egde_4212375_member_102062735
-http://docs.oracle.com/cd/E29049_01/web.1112/e16182/adf_lifecycle.htm#CIABEJFB

Thank you!

The problem was that the HTTP headers have been actually written twice:

1. the report server returns the HTTP response headers.
2. the bean was his own (as mentioned in the question) HTTP response headers.
3. the bean was copy all the contents of the report server response, including headers, to the output stream.

Firefox has ignored the header in double, but not Google Chrome errors.

Tags: Java

Similar Questions

  • Workflow managed bean with dynamic class

    Hello

    I am trying to create an Adaptive workflow, which is generic and can be reused.  The problem I have is trying to define the bean managed support.  Ideally I'd like a different class of bean to be used in various circumstances, but with the same name.  I don't know what class to use until the output of the task is called.

    I can't use for EL do know

    <managed-bean id="__1">
      <managed-bean-name>RegionBacking</managed-bean-name>
      <managed-bean-class>${pageFlowScope.regionBackingClass}</managed-bean-class>
      <managed-bean-scope>pageFlow</managed-bean-scope>
    </managed-bean>
    

    (regionBackingClass is a java.lang.String parameter passed in the taskflow with the class path).

    At this point, I need to use different classes have the same method names in their breast, just different code in methods, but that could change in the future.

    Thank you.

    Hello

    use a model approach. The managed bean configured as managed bean is simply a wrapper and instantiated dynamically the class that you want to manage the logic. Thus, you can for example pass the class name as input argument for the workflow in the managed bean and admire you the name then create the instance of the class to send all requests to.

    Frank

  • What is ORA-29049: unknown record when using UTL_HTTP.begin_request with the HTTPS protocol?

    Hi, here is my question:

    The application context:
    Oracle 10.2.0.4.0
    Operating system: AIX Version 5.3

    A stored procedure executes queries on the web in order to call a Webmodele.
    The used protocol is httpS.
    A certificate has been defined with the Oracle Wallet (orapki) utility

    Problem:
    For several days, making the procedure call webservice no longer works.
    The package has been changed on the database, no patch has been applied on the machine.

    The call to the procedure of utl_http.begin_request with the HTTPS url returns the following error:
    ORA-29049: unknown record
    ORA-06512: at "SYS." UTL_HTTP", line 1027
    ORA-06512: at line 16 level

    A small piece of code/oog is attached, see photo log_sql_ws_call.jpg

    Question

    Can you explain to me the meaning of the error ORA-29049, what may be the cause of this unexpected error and most importantly, how to fix?


    Thank you for your help.

    Finally, it happends only a few days before the described error (ORA-29049), SSL v2 has been disabled on the target domain (SSL v3 has been disbled 1 year ago already).

    The reactivation of SSL v2 solved the ORA-29049.

    Now, I'm dealing with the ORA-12537: TNS:connection closed.

  • TestStand fails to use the application with custom user settings

    Hello

    For a project of teststand, I use a .net application that uses a custom settings provider. The problem is that whenever he tries to use one of the teststand user settings, the application returns an exception:

    "Unable to load the provider type.

    I tried to illustrate the small demo project that I have attached.

    The .net application I call of test bench is AppWithUserSetting, and is one of the steps in the q.seq file in sequence to get a value from a user setting. That's where it crashes for me.

    On the other hand, if I instantiate the same objects and read the same setting from another application .net (DoLikeTestStandApp), everything is fine.

    Note that in the AppWithUserSetting settings.designer.cs file, a custom line has been added ([total:ystem.]) Configuration.SettingsProvider (typeof (AppWithUserSettings.UserAppSettingsProvider))]) to force the program to use the custom SettingProvider. And that's where it fails when loading teststand.

    No idea why? Right now, I'd rather not remove the use of this settingProvider custom because it will keep the settings of the user even when the upgrade to a different version of AppWithUserSettings.

    Thank you and best regards,

    Loïc

    PS: I use studio VS 2008 SP1 and Teststand 4.1.1

    Loïc-

    Like Doug mentioned, you are running in an issue similar to that of the other forum thread, he did. I went ahead and implemented workaround for this problem in your example and attached it below.

    I hope this helps. Let me know if you have any questions.

  • Popup on page load using managed bean using jdev-11, 4

    Hello

    My requirement is on page 1 click button, the control should get passed to the new window (2nd page), and the popup must be open on the charge.
    And after clicking the pop-up control should get transferred to page 3.

    Please let me know how to proceed.

    Thank you
    Nitin

    Here is an example based on the mentioned use cases.

    (1) create three pages FirstPage, SecondPage & ThirdPage

    (2) create the following navigation rules
    Of FirstPage to SecondPage ==> gotoSecond
    Of SecondPage to ThirdPage ==> gotoThird

    (3) the following code snippets show the flow.

    FirstPage.jspx:




    action = "gotoSecond" / >

    SecondPage.jspx:

    **





    *
    action = "gotoThird" / >




    SecondPageBean.java:

    Import javax.faces.event.PhaseEvent;

    Import oracle.adf.view.rich.component.rich.RichPopup;

    public class SecondPageBean {}
    private RichPopup popup.

    public SecondPageBean() {}
    }

    * public Sub phaseListener (PhaseEvent phaseEvent) {*}
    * if (phaseEvent.getPhaseId () .equals (phaseEvent.getPhaseId (). RENDER_RESPONSE)) {*}
    Tips RichPopup.PopupHints = new RichPopup.PopupHints ();
    Popup.Show (Hints);
    *}*
    *}*

    {} public void setPopup (RichPopup popup)
    This.Popup = popup;
    }

    public RichPopup getPopup() {}
    back to popup;
    }
    }

    ThirdPage.jspx:





    Thank you
    Nini

  • Automatically expose the interface components existing user using a managed Bean

    "I try to use him"automatically expose UI components using an existing managed Bean"in the implementation of the Page" section when creating of my jspx page but cannot find out how to get the enabled radio button to use.

    See this article on the use of Backing Beans with JDeveloper:
    http://blogs.Oracle.com/Shay/2010/03/working_with_backing_beans_in.html

    To pass information between pages, you might want to watch using the pageFlowScope and a component of setPropertyListener:
    http://download.Oracle.com/docs/CD/E14571_01/Web.1111/b31973/af_lifecycle.htm#BABIHDAA

  • How to generate PDF based w / drop-down menu

    If anyone can offer some guidance on how to generate a PDF based on the selection of the menu drop down.

    Click on registration to the coast and continue, press menu save and create pdf below to see what I mean in the link below.

    https://www.Teaforte.com/tea-menu/

    Thank you very much.

    Does your server support PHP scripts?

    PHP to format PDF - a simple solution for generating PDF using PHP

    Nancy O.

  • Adding text to PDF using iText instead of CFPDF

    Hello

    I know this may seem a bit off-topic is posted here, but I ask this Council because I am a complete JAVA noob and I guess some of you folk CF could do that before.

    In any case, on my question... I'm already add a watermark image to a PDF using iText (CF8) with the help of colleagues poster (= cfSearching =).  I'm looking for is the best way to go about adding text to the same pdf.  I have to add 4 lines of text (with specific font and size) and Center it under the image being added.   Someone at - it a site they could tell me how to add text in the form and how do I get the width of this text to align properly?  I have search Google and watched a lot of JAVA code but be a noob JAVA, it's hard to know exactly what libs and methods you can use to do this.

    Any help would be greatly appreciated!

    -Michael

    The classes you need are PdfTable and PdfCell

    http://cfsearching.blogspot.com/2008/09/getting-started-with-iText-tables.html

    I was curious, I threw together a rough example. It adds the table in a pdfTemplate, then the model adds watermark to each page. The positioning and table dimensions are based on my sample data, so you'll need to tweak the.  Make sure that the dimensions of the model are large enough to accommodate your image and your text. If the dimensions are not large enough, the watermark is perhaps not visible.


    Err = "";
    TEST VALUES
    maxlinechars = 40;
    dCompany = "Google Inc.";
    dnom = "1600 Amphitheatre Parkway";
    dPhone = '+ 1 650-253-0000';
    dEmail = "[email protected]";
       
    simplify the code by putting the watermark text values in a table
    TextElement = [dCompany, dName, dPhone, dEmail];
    inputFile = ExpandPath ("ChapterSection.pdf");
    outputFile = ExpandPath ("ChapterSection_Watermark_ImageWithText.pdf");
    imgPath = ExpandPath("/dev/beveled_purpleblue.png");

    try {}
    initialize objects to read and write the pdf file
    pdfReader is createObject ("java", "com.lowagie.text.pdf.PdfReader") .init (inputFile);.
    outStream is createObject ("java", "java.io.FileOutputStream") .init (outputFile);.
    pdfStamper is createObject ("java", "com.lowagie.text.pdf.PdfStamper") .init (pdfReader, outStream);.

    get the size of the watermark image
    Note: table width and height are examples of values for demo only...
    Watch to your dimensions are large enough to accomdate your text and image
    otherwise the watermark is perhaps not entirely visible
    IMG is createObject ("java", "com.lowagie.text.Image") .getInstance (imgPath);.
    tableWidth = img.width () + 100;
    tableHeight = img.height () + 75;
           
    create a template for the table storage
    CB = pdfStamper.getOverContent (1);
    model = cb.createTemplate (tableHeight, tableWidth);

    create a single-column table
    table = createObject ("java", "com.lowagie.text.pdf.PdfPTable") .init (1);
    table.setTotalWidth (tableWidth);

    reusable objects for adding rows in the table
    PdfCell = createObject ("java", "com.lowagie.text.pdf.PdfPCell");
    Expression = createObject ("java", "com.lowagie.text.Phrase");

    Add the watermark image to the first line
    imageCell = PdfCell.init (img, false);
    imageCell.setBorder (PdfCell.NO_BORDER);
    imageCell.setHorizontalAlignment (PdfCell.ALIGN_CENTER);
    table.addCell (imageCell);

    Add each piece of text in the table of a new line
    for (x = 1; x<= arraylen(textelements);="" x++)="">
    textCell = PdfCell.init (Phrase.init (TextElement [x]));
    textCell.setBorder (PdfCell.NO_BORDER);
    textCell.setHorizontalAlignment (PdfCell.ALIGN_CENTER);
    table.addCell (textCell);
    }
           
    get the calculated height of table
    table.calculateHeightsFast ();
    tableHeight = table.getTotalHeight ();
    table.writeSelectedRows (0, - 1, 0, tableHeight, model);
    WriteOutput ("calculated tableWidth =" tableWidth & ", tableHeight =" "& tableHeight &")
    ");

    Add model watermark to each page
    Note: x / yPos values are for demo only (in upper right)...
    i = 0;
    totalPages = pdfReader.getNumberOfPages ();
    so that {(i LT totalPages)
    i = i + 1;
    content = pdfStamper.getOverContent (javacast ("int", i));
    positioning of arbitrary code
    pageSize = pdfReader.getPageSize (i);
    yPos = pageSize.height () - tableHeight - 15;
    PosX = (pageSize.width () - tableWidth)-25;
    content.addTemplate (template, xPos, yPos);
    WriteOutput ("watermarked page" & I & "xPos =" & xPos & ", yPos =" "& yPos &")
    ");
    }
    }
    catch (Exception e) {}
    ERR = e;
    }
    If (IsDefined ("pdfStamper")) {}
    pdfStamper.close ();
    }

    If (IsDefined ("outStream"))
    {
    outStream.close ();
    }

  • Using @Interceptors with ADF managed beans

    Hi Experts,

    I am using the annotation javax.interceptor.Interceptors on my methods of ADF managed beans, but my methods of interception are not get called.

    Is it possible to use it with controlled beans? Has anyone tried this before?

    JDev: 11.1.1.7

    Java: 1.7

    MyInterceptor.java

    =========

    public class MyInterceptor {}

    public MyInterceptor() {}

    Super();

    }

    @AroundInvoke

    public object intercept (InvocationContext context) throws Exception {}

    System.out.println ("MyInterceptor - logging BEFORE calling method:"+ context.getMethod () .getName () ");

    Object result = context.proceed ();

    System.out.println ("MyInterceptor - logging AFTER calling method:"+ context.getMethod () .getName () ");

    return the result;

    }

    }

    =========

    SomeBean.java

    =============

    public class SomeBean {}

    @Interceptors (MyInterceptor.class)

    {} public void doReset (ActionEvent actionEvent)

    do something

    System.out.println ("In reset");

    }

    }

    =============

    Thank you

    Soham

    As far as I KNOW, JSF(and ADF) can't stand the interceptors.

    Maybe you can try this in 12.2.1 jdev because with this version is packaged 2.2 JSF (which should support the CDI)

    Dario

  • Using Acrobat XI with IE11 and Win7; I can't the acrobat toolbar. Watch modules Manager he's here and activated, but the toolbar is not there. And when I use right click and click on convert to Adobe pdf format, nothing happens.

    Using Acrobat XI with IE11 and Win7; I can't the acrobat toolbar. Watch modules Manager he's here and activated, but the toolbar is not there. And when I use right click and click on convert to Adobe pdf format, nothing happens.

    Can anyone help?

    Hi Richard,

    1. start Internet Explorer.

    2. Select Tools > Internet Options, and then click the Advanced tab.

    3. check if "enable third-party browser extensions (requires restart)" and click OK.

    4. close all Internet Explorer Windows.

    5 restart Internet Explorer.

    Let us know how it goes.

    You can also check out the following link and see.

    Quick fix | See a PDF on the Web

    Concerning

    Sukrit diallo

  • Display pdf in a bean managed using ADF

    I need to set up a pdf file when the user clicks a button. The pdf file is located on a different machine to the web server.

    Here is my code. My problem is that the inputStream is null.

    Can the classLoader get a resource from another machine. If not, is it possible to obtain or accomplish what I need here?

    InputStream inputStream = null;
    Buffer buffer = null;

    inputStream = MyMB.class.getResourceAsStream("\\\machine2\\pdf\\myFile.pdf");
    bis = new buffer (in);
    int len = 0;
    Byte [] buf = new byte [8 * 1024];
    While ((len = bis.read (buf))! = - 1).
    {
    out. Write (buf, 0, len);
    }

    Thank you.

    http://thepeninsulasedge.com/frank_nimphius/2007/08/18/ADF-faces-direct-file-download-through-managed-bean/
    http://thepeninsulasedge.com/frank_nimphius/2007/09/11/ADF-faces-showing-reports/

  • Question about the use of JavaScript in Managed Bean

    Hello

    I have two questions... The reason for these questions is: we have a requirement that we have executed successfully using jsp and javascript. Now, we are unable to be implemented using the framework of the ADF. It is why would have a jsp with javascript page to reach the requirement.

    The condition is:
    1. to print a page. This page should be displayed with a customer bills. If the customer has 3 invoices (html content), these 3 bills needs displayed on the screen with a page break.
    2. because the page has a lot of data, certainly there will be a right of the page scroll bar to scroll down to see the data.
    3. now, the user clicks on the file--> print available on the browser / provided a "print" button with < af:showPrintablePageBehavior / >. When this happens, it is able to print the data that is displayed on the screen, not all 3 bills.

    This kind of requirement we already implemented using legs force Framework(jsp,java script).

    Now my question to you is:
    how we can open a new window bowser using java from a managed bean script.
    Let me know if you need more information about it.

    Thank you and best regards,
    Kiran kristelle

    the PDF version of the documentation:
    http://download.Oracle.com/docs/CD/E14571_01/Web.1111/b31973.PDF

    Kind regards
    Branislav

  • With custom auto-generated primary key value

    How to implement the the custom generated automatically Coordinated as 'ISSUE00001', 'ISSUE00002' ADF entity object.

    Hello
    your PK should be varchar2 if you use oracle DB or what?
    While you use to generate the PK value you expect, you can use the database for him.
    http://www.exploreoracle.com/2010/10/11/sequence-number-for-primary-key-in-Oracle-ADF-JDeveloper/
    in this site, call your function in the dodml method. without using the sequence.
    If (operation == DML_INSERT) {}
    inside to call your function that allows to generate number with the string value. (u concat/join 'FROM' value for your build number max)

    }

    Thks.

  • How to call a function with parameters in jsf managed Bean

    Hello

    1. I created a Bean managed to manage chains of jsf to 11.1.1.7 WebCenter spaces:

    public class ManageStrings {}

    / * Converts all characters in a string to uppercase. */

    public String getToUpperCase (String str) {}

    Dim retVal = str.toUpperCase ();

    Return retVal;

    }

    }

    2. I registered managed Bean:

    " < managed-bean id ="swc_3"xmlns =" http://xmlns.Oracle.com/ADF/controller "> "

    < id managed-bean-name = "swc_2" > tools < / managed-bean-name >

    < managed-bean-class id = "swc_1" > cat.badalona.webcenter.utilities.ManageStrings < / managed-bean-class >

    < managed-bean-scope id = "swc_4" > backingBean < / managed-bean-scope >

    < / managed-bean >

    3 to code jsf, I tried different options, but they do not work

    " < = xmlns:af af:outputText ' http://xmlns.Oracle.com/ADF/faces/rich "value="#{backingBeanScope.utilities.getToUpperCase['hello']}"/ > "

    ...

    " < = xmlns:af af:outputText ' http://xmlns.Oracle.com/ADF/faces/rich "value="#{backingBeanScope.utilities.toUpperCase['hello']}"/ > "

    ..

    " < = xmlns:af af:outputText ' http://xmlns.Oracle.com/ADF/faces/rich "value =" #{backingBeanScope.utilities.getToUpperCase ('hello')} "" / >


    What I am doing wrong?


    Thaks in advance


    Hello Carles,

    I did it with the content presenter where I need to pass the ID of the component selected in backing bean. Please try below option

    Now add following code in your binding

    Private RichOutputText outputText1;

    then the getter for this outputtext set.

    and in your action method to read the value of the output text.

    Hope this helps with your problem.

    Thank you

    Amey

  • How to return an * optional * custom http header with a resource model?

    Is it possible to return a http header custom optional with a resource of Apex (v1.1.4) earphone model?

    Reading the documentation does not indicate how this works:
    http://docs.Oracle.com/CD/E21611_01/ doc.11 /e21058/rest_api.htm#BGBDFBJF

    A test, I set up a model of resource to try it. I use the handler method is POST, type is 'PLSQL Block', and my custom settings are:

    Name: personnalisee01
    Aliasing: x-personnalisee01
    Source: header
    Access: EXIT
    Type: String

    PL/SQL block:
    BEGIN
      :custom01 := 'my string';
    END;
    And of course, I get a custom header in the response http like this:
    x-custom01 : my string
    Then, taking a hypothesis that the NULL value for the parameter may cause the listener to Apex do not send the custom header, I changed the PL/SQL this:
    BEGIN
      :custom01 := NULL;
    END;
    This time, however, the url announcement causes Apex listener to return a 500 status and in the log file, I get:
    INFO: null: Invalid column index
    java.sql.SQLException: Invalid column index
    In any case is to make my custom http header exist as an option? The most intuitive way to just return null to the variable binding, but of course, this does not work!

    Thank you
    Jack

    Yes, to be clear, the issue is that binds through comments (- or / * /) are not handled correctly, I have not yet verified, but I think that the problem will occur in 2.0.x so.

Maybe you are looking for