Adding PDF file as attachment to SOAP message

Hi,
I want to add a pdf file from the hard disk to a soap message as attachment. I have the following code:
// CREATE MESSAGE
SOAPMessage msg= fac.createMessage();
SOAPEnvelope nEnv= msg.getSOAPPart().getEnvelope();      
//READ FILE FROM THE HD
String pdfFileName = "somepdffile.pdf";      
FileReader fr = new FileReader(pdfFileName);
BufferedReader buffr = new BufferedReader(fr);
String sPdf="";
String line = testB.readLine();
while(line!=null)
sPdf += line;
line = testB.readLine();
//WRITE THE FILE TO BYTE ARRAY AND THEN TO STREAM
byte[] pdfData = sPdf.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(pdfData);
//CREATE ATTACHMENT ADD THE STREAM AS CONTENT
AttachmentPart attPDF = msg.createAttachmentPart();          
attPDF.setContent(stream, "application/pdf");
msg.addAttachmentPart(attPDF);          
return msg;
I GET THE NEXT EXCEPTION:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:851)
at javax.activation.DataHandler.writeTo(DataHandler.java:305)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1089)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:635)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:233)
at com.sun.xml.messaging.soap.MessageImpl.saveChanges(MessageImpl.java:356)
at javax.xml.messaging.JAXMServlet.doPost(JAXMServlet.java:192)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:536)
javax.xml.soap.SOAPException: java.security.PrivilegedActionException: javax.xml.messaging.JAXMException: Bad response: (500, Internal Server Error)
at com.sun.xml.messaging.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:93)
at mp.soap.SendingServlet.getPolisPrint(SendingServlet.java:320)
at mp.soap.SendingServlet.doPost(SendingServlet.java:234)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:536)
CAN ANYONE TELL ME WHAT THE SOLUTION IS ?
PLEASE HELP ME !!!
Birol

testB == buffr ! Sorry.
IT IS STILL NOT WORKING !!!!!
// CREATE MESSAGE
SOAPMessage msg= fac.createMessage();
SOAPEnvelope nEnv= msg.getSOAPPart().getEnvelope();
//READ FILE FROM THE HD
String pdfFileName = "somepdffile.pdf";
FileReader fr = new FileReader(pdfFileName);
BufferedReader buffr = new BufferedReader(fr);
String sPdf="";
String line = buffr.readLine();
while(line!=null)
sPdf += line;
line = buffr.readLine();
//WRITE THE FILE TO BYTE ARRAY AND THEN TO STREAM
byte[] pdfData = sPdf.getBytes();
ByteArrayInputStream stream = new ByteArrayInputStream(pdfData);
//CREATE ATTACHMENT ADD THE STREAM AS CONTENT
AttachmentPart attPDF = msg.createAttachmentPart();
attPDF.setContent(stream, "application/pdf");
msg.addAttachmentPart(attPDF);
return msg;

Similar Messages

  • IPAD3/IPAD2 :PDF files/ attachments  sent in an email  displayed inline ( embedded within the main email) in the message text on both my Ipad2 and Ipad three, however the same email displayed the PDF File icons/ attachment on both my Iphone and a friend's

    IPAD3/IPAD2 :PDF files/ attachments  sent in an email  displayed inline ( embedded within the main email) in the message text on both my Ipad2 and Ipad three, however the same email displayed the PDF File icons/ attachment on both my Iphone and a friend’s PC. How do i get both my IPAD devices to display the PDF icons/attachments? Bearing in mind if i open the same email over the internet the PDF Icons/attachments display OK!
    Has anyone come across this? Your advice/help would be most appreciated

    This happens to me all the time.
    If is a one page PDF it seems as though it comes over already open and inline in the body of the email. Multiple page PDF files show as the PDF icon.
    I can't find any official documentation of this - other than based on my own experience with PDF attachments in my various email accounts.
    Message was edited by: Demo

  • Not able to send pdf file as attachment in my apple mail.

    Hi, I was easily able to attach pdf files to my apple mail.  infact I could just open a pdf file and then send it as attachment in the email earlier. but after downloading and upgrading to os X Mountain lion, I am neither being able to attach and send pdf files in my apple mail, nor can I send PDF file as an attachment.
    Is there any issue with OS X Mountain Lion.
    Issue 1.  I compose Email , then click attach > Browse > select pdf file > click attach > it shows in my Email body either as an icon or as first page of the pdf document > I send it. >>> But when the receipient opens the Email, that pdf attachment is missing. In fact When I put a cc to my self and I open the Email, the attachment is mssing in the incoming E amil.
    Issue 2. I open the PDF document > Click on File > send as attachment in E-Mail > on right, a menu appears where I select the File and click attach> I get a message
    The SendMail doesnot know how to talk to your default mail client. Please select a different mail application to use. Attaching a screen shot.
    I never had these issues earlier with my Lion OS . but since the time I have upgraded to mountain Lion OS, I am having these issues.
    Are these the Mountain Lion issues, how to fix these please.

    I believe, the software team forgot to put a button for send or share as an attachment to preview.

  • Help? Adobe Acrobat 11 Standard - just purchased for windows 7 now I can't open pdf files or attach?

    Help!!!
    I just puchased the latest Adobe Acrobat XI Standard.
    I put in the Serial Key number but my computer tells me that a qualifying product could not be found on my computer so I can't use the adobe product. So now I can't open any files or attach pdf files onto emails without this message coming up. I've un-installed the "Adobe Acrobat XI Standard twice! with no luck.
    I need it sorted ASAP as I'm trying to work! Any suggestions?

    DotBellaParis if you are being asked for a qualifying product then it would appear you purchased an upgrade to Acrobat XI Standard.  You should have the opportunity to enter the serial number for your previous purchase of Acrobat.  You can find information on how to locate your previous serial numbers at http://forums.adobe.com/message/3987968#3987968?promoid=KBHJW.
    If you did not intend to purchase an upgrade then I would recommend submitting a return request.  You can find more details on submitting a return at Return, cancel, or exchange an Adobe order - http://helpx.adobe.com/x-productkb/policy-pricing/return-cancel-or-change-order.html.  Once you have returned the upgrade you can then purchase the full version which will not ask you for a qualifying product or serial number.

  • After updating os to 10.9.1can't open pdf files.  I get a message saying It may be damaged or use a file format that Preview doesn't recognise. I can still read older saved files but no new ones arriving by email.  Any help would be appreciated.

    After updating os to OSX 10.9.1 I can't open any new pdf files.  I get a message saying It may be damaged or use a file format that Preview doesn’t recognise. I can still read older saved files but no new ones arriving by email.  Also can't attach a pdf to an email to send out.  Any help would be appreciated.

    Back up all data before making any changes. Please take each of the following steps until the problem is resolved.
    Step 1
    If Adobe Reader or Acrobat is installed, and the problem is just that you can't print PDF's displayed in Safari, you may be able to print by moving the cursor to the the bottom edge of the page, somewhere near the middle. A black toolbar may appear under the cursor. Click the printer icon.
    Step 2
    There should be a setting in its preferences of the Adobe application such as Display PDF in Browser. I don't use those applications myself, so I can't be more precise. Deselect that setting, if it's selected.
    Step 3
    If you get a message such as ""Adobe Reader blocked for this website," then from the Safari menu bar, select
    Safari ▹ Preferences... ▹ Security
    and check the box marked
    Allow Plug-ins
    Then click
    Manage Website Settings...
    and make any required changes to the security settings for the Adobe PDF plugin.
    Step 4
    Triple-click anywhere in the line of text below on this page to select it, the copy the selected text to the Clipboard by pressing the key combination command-C:
    /Library/Internet Plug-ins
    In the Finder, select
    Go ▹ Go to Folder
    from the menu bar, or press the key combination shift-command-G. Paste into the text box that opens (command-V), then press return.
    From the folder that opens, move to the Trash any items that have "Adobe" or “PDF” in the name. You may be prompted for your login password. Then quit and relaunch Safari.
    Step 5
    The "Silverlight" web plugin distributed by Microsoft can interfere with PDF display in Safari, so you may need to remove it, if it's present. The same goes for a plugin called "iGetter," and perhaps others — I don't have a complete list. Don't remove Silverlight if you use the "Netflix" video-streaming service.
    Step 6
    Do as in Step 4 with this line:
    ~/Library/Internet Plug-ins
    If you don’t like the results of this procedure, restore the items from the backup you made before you started. Relaunch Safari.

  • When I try to open a pdf file I get an error message stating "There was an error opening the document.  The file is damaged and could not be repaired."  Other pdf files open fine.

    When I try to open a pdf file I get an error message stating "There was an error opening the document.  The file is damaged and could not be repaired."  Other pdf files open fine.

    You need to get a new copy of the PDF.

  • Have installed and uninstalled Adobe Acrobat XI Pro on my Dell desktop running Windows 7 Professional. Each time I try to open a PDF file, I receive ERROR: 16 message. Would appreciate any suggestions. Thanks.

    Have installed and uninstalled Adobe Acrobat XI Pro on my Dell desktop running Windows 7 Professional. Each time I try to open a PDF file, I receive ERROR: 16 message. Would appreciate any suggestions. Thanks.

    Hi Doug Talbott,
    Please refer to the page associated with this link (Configuration error 16 | CC, CS) and follow the procedure detailed for Windows 7 and let me know if your issue gets resolved.
    Regards,
    Rahul Tyagi

  • I have iphone6 and I cant open PDF files which attached to my email

    Dear All
    I have iPhone and I cant open PDF files which attached to my email
    Regards

    thanks for the suggestions weather15 - the firefox help site you directed me to explains what ought to happen but i cant make it work. I shut my firefox browser on my new machine and attach the hard drive from my old machine. I can explore the contents of that drive but when i search it for the suggested folder " %APPDATA%\Mozilla\Firefox\Profiles\" nothing is found. when i try and open firefox from the old drive, the browser opens that is the new version that i have on my new computer with no saved bookmarks! Am I doing everything right?

  • Hi. I was trying to open some pdf files and got a message my adobe reader was deinstalled. I installed a new version of Adobe Reader for Mac and when trying to open a PDF file I am getting a message in a foreign language. Any suggestions?

    Hi. I was trying to open some pdf files and got a message my adobe reader was deinstalled. I installed a new version of Adobe Reader for Mac and when trying to open a PDF file I am getting a message in a foreign language. Any suggestions?

    Are you launching Pages from an icon in your Dock? Installing the update does not change the Dock icons & it does not remove the older versions. Go to your Applications folder & launch the new Pages from there.

  • I have not been able to open PDF Files and i get a message saying Missing Plug-ins

    I have not been able to open PDF Files and i get a message saying Missing Plug-ins

    The message may be refering to Adobe plug-ins. To use Apple Preview to view PDF, right click on any PDF you have/Get Info. In the Info Window/Open with: Select Preview > Select Change All

  • After updating to Mavericks, I can't seem to open files to attach to gmail messages.

    After updating to Mavericks, I can't seem to open files to attach to gmail messages. I can still drag and drop into them, but I'm unable to click on my documents through the paperclip icon on the bottom of composing my message.  Anyone else know a solution or facing the same issue?
    Thanks!

    Select
    View ▹ Show View Options
    from the menu bar. In the dialog that opens, select
    Arrange by: None

  • I have 6 pdf files to attach to an email. I don't want them all to open in the body of the email. How do I just attach the pdf file?

    I have 6 pdf files to attach to an email. I don't want them all to open in the body of the email. How do I just attach the pdf file?

    Never mind. Found the solution here: Re: How to mail PDF file as an icon

  • Adding PDF File to Email Message

    When I attempt to add a PDF file to an email message (via Outlook) I get the following error message, after which the program shuts down: "The instruction at 0x6148f787 referenced memory at 0x00000000. The memory could not be read." Please Help!

    It runs in a Window titled Outlook all by itself. Guess I'm an idiot because I still can't find the version. Anyway, this problem only happens when I'm using IE. When I use Firefox, I can attach a PDF file to an email message just like I used to do using IE.
    [private data removed]

  • How to Sender PDF file as attachment in Payload?

    Hi Experts,
         After I done some of PI scenarios, I'm stuck with one of my requirement... In requirement, "Web service" will send request to "SAP ECC 6" in order to get PO document print out in PDF file by call smartform or any form printing as usual.
         In my understand, I'm using SOAP adapter as sender and RFC adapter in receiver side, in  RFC function, I will call form and generate PDF file by using normal ABAP function, but here, how can I send PDF file as response message of SYNC call from web service.
         I try to search and read some of document and blog, some said I can attach file as Payload attachment, but no clear solution or guide to do so.
        Here is example blog that I found, I really useful
           /people/michal.krawczyk2/blog/2006/04/19/xi-rfc-or-abap-proxy-abap-proxies-with-attachments
        Please suggest me in my case,
    Thanks in advance...
    Cheers,
    Terry

    Hi,
    >>In my understand, I'm using SOAP adapter as sender and RFC adapter in receiver side, in RFC function, I will call form and generate PDF file by using normal ABAP function, but here, how can I send PDF file as response message of SYNC call from web service.
    as per my blog you can attach PDF to a message only if you use abap proxy on ECC and not RFC
    the code is just copy and paste from my blog:
    /people/michal.krawczyk2/blog/2006/04/19/xi-rfc-or-abap-proxy-abap-proxies-with-attachments
    so there is nothing spectacular there
    Regards,
    Michal Krawczyk

  • Error while sendinf pdf file as attachment

    hi all.,
    am trying to send the pdf file of a smartform as attachment thru mail .. but its getting failed am getting error (sy-subrc = 6 ) after calling the fm so_new_document_att_send_api1 .. pls. suggest the possible cause of errors.
    CALL FUNCTION 'CONVERT_OTF_2_PDF'
            IMPORTING
              bin_filesize           = lv_bin_filesize
            TABLES
              otf                    = ls_job_output_info-otfdata
              doctab_archive         = it_docs
              lines                  = it_lines
            EXCEPTIONS
              err_conv_not_possible  = 1
              err_otf_mc_noendmarker = 2
              OTHERS                 = 3.
          IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
    *--- Get filename to store DYNAMIC
          IF p_lsdir IS NOT INITIAL.
            MOVE p_lsdir  TO lv_path.
          ENDIF.
          CONDENSE wa_kna1-kunnr.
          CONCATENATE 'SOA' wa_kna1-kunnr  '.pdf' INTO lv_name.
          CONCATENATE  lv_path lv_name INTO  lv_fullpath.
          break ibm_prasad.
          CLEAR wa_buffer.
          LOOP AT it_lines.
            TRANSLATE it_lines USING '~'.
            CONCATENATE wa_buffer it_lines INTO wa_buffer.
          ENDLOOP.
          TRANSLATE wa_buffer USING '~'.
          DO.
            i_record = wa_buffer.
            APPEND i_record.
            SHIFT wa_buffer LEFT BY 255 PLACES.
            IF wa_buffer IS INITIAL.
              EXIT.
            ENDIF.
          ENDDO.
          REFRESH: i_reclist,
                   i_objtxt,
                   i_objbin,
                   i_objpack.
          CLEAR wa_objhead.
          i_objbin[] = i_record[].
          i_objtxt = 'SOA test with pdf-Attachment!'.
          APPEND i_objtxt.
          DESCRIBE TABLE i_objtxt LINES v_lines_txt.
          READ TABLE i_objtxt INDEX v_lines_txt.
          wa_doc_chng-obj_name = 'SOA'.
          wa_doc_chng-expiry_dat = sy-datum + 10.
          wa_doc_chng-obj_descr = 'SOA'.
          wa_doc_chng-sensitivty = 'F'.
          wa_doc_chng-doc_size = v_lines_txt * 255.
    *     Maint Text
          CLEAR i_objpack-transf_bin.
          i_objpack-head_start = 1.
          i_objpack-head_num = 0.
          i_objpack-body_start = 1.
          i_objpack-body_num = v_lines_txt.
          i_objpack-doc_type = 'RAW'.
          APPEND i_objpack.
    * Attachment (pdf-Attachment)
          i_objpack-transf_bin = 'X'.
          i_objpack-head_start = 1.
          i_objpack-head_num = 0.
          i_objpack-body_start = 1.
          DESCRIBE TABLE i_objbin LINES v_lines_bin.
          READ TABLE i_objbin INDEX v_lines_bin.
          i_objpack-doc_size = v_lines_bin * 255 .
          i_objpack-body_num = v_lines_bin.
          i_objpack-doc_type = 'PDF'.
          i_objpack-obj_name = 'SOA Eail'.
          i_objpack-obj_descr = 'test'.
          APPEND i_objpack.
          CLEAR i_reclist.
          i_reclist-receiver =  <mail id>
          i_reclist-rec_type = 'U'.
          APPEND i_reclist.
          CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
            EXPORTING
              document_data              = wa_doc_chng
              put_in_outbox              = 'X'
              commit_work                = 'X'
            TABLES
              packing_list               = i_objpack
              object_header              = wa_objhead
              contents_bin               = i_objbin
              contents_txt               = i_objtxt
              receivers                  = i_reclist
            EXCEPTIONS
              too_many_receivers         = 1
              document_not_sent          = 2
              document_type_not_exist    = 3
              operation_no_authorization = 4
              parameter_error            = 5
              x_error                    = 6
              enqueue_error              = 7
              OTHERS                     = 8.
    thanks
    suresh

    u need to use this SO_NEW_DOCUMENT_ATT_SEND_API1
    check this code tutorial on how to add pdf file as an attachment
    u need to modify the code to read the pdf from directory then rest of code is same
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/snippets/mailsendthroughoutputcontrols
    кu03B1ятu03B9к
    Edited by: kartik tarla on Mar 9, 2009 7:31 PM

Maybe you are looking for