Setting Content-Type when posting a SOAPMessage

Hi,
I have to change the Content-Type header before I send the SOAPMessage. But when I try to do that with code similar to the one below, the old header is used anyway. Any solution?
SOAPMessage msg = createSOAPMessage();
MimeHeaders headers = msg.getMimeHeaders();
headers.setHeader("Content-Type", headers.getHeader("Content-Type")[0] + additionalParameters);
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection con = scf.createConnection();
SOAPMessage reply = con.call(msg, "http://localhost:8080");

I've found that when calling the saveChanges() method on a SOAPMessage instance that doesn't have any attachments, the 'Content-Type' header is set to 'text/xml; charset="utf-8"'. So what you should do is that you should be sure to set the 'Content-Type' header after any possible changes to the message have been saved.
SOAPMessage msg = createSOAPMessage();// Modify message by adding elements...
// Save the changes made to the message and then
// change the "Content-Type" header...
if (msg.saveRequired()) {
msg.saveChanges();
MimeHeaders headers = msg.getMimeHeaders();
headers.setHeader("Content-Type",
headers.getHeader("Content-Type")[0] +
additionalParameters);
SOAPConnectionFactory scf =
SOAPConnectionFactory.newInstance();
SOAPConnection con = scf.createConnection();
SOAPMessage reply = con.call(msg,
"http://localhost:8080");
Hope this helps!
BR
Daniel

Similar Messages

  • Content-Type for POST request

    Hi all again,
    I am setting content-type in the header to "text/xml"  yet when I do a POST sap sends as content-type
    "application/x-www-form-urlencoded". Is there something else I need to set to make it post with text/xml ?
      cl_http_client=>create_by_url( EXPORTING url = url
                                               ssl_id = 'ANONYM'
                                     IMPORTING client = http_client ).
    * create HTTP client object
    *  cl_http_client=>create_by_destination( EXPORTING DESTINATION = 'ZTOLLREQUEST'
    *                                 IMPORTING client = http_client ).
                                                                                    * Set HTTP headers
      http_client->request->set_header_field( name = '~request_method'
      value = 'POST' ).
      http_client->request->set_header_field( name = 'Content-Type'
      value = 'text/xml' ).
    *  http_client->request->set_header_field( name = 'Authorization'
    *  value = auth_string ).
    *  http_client->request->set_header_field( name = 'sap-password'
    *  value = 'ymous' ).
                                                                                    * Set payload
      http_client->request->set_cdata( xml_string ).
                                                                                    * send and receive
      CALL METHOD http_client->send
        EXCEPTIONS
          http_communication_failure = 1
          http_invalid_state         = 2.
    regards
    Allan

    i havent tried this (setting content type) when using create by url . may be try just the create method and then set the remaining part of the url as headers ~request_uri parameter. something like below.
    call method cl_http_client=>create
      exporting
        host          = 'www.webservicex.net'
        service       = '80'
        scheme        = '1'
        proxy_host    =  wf_proxy
        proxy_service =  wf_port
      importing
        client        = http_client.
    http_client->propertytype_logon_popup = http_client->co_disabled.
    wf_user = user .
    wf_password = password .
    call method http_client->authenticate
      exporting
        proxy_authentication = 'X'
        username             = wf_user
        password             = wf_password.
    call method http_client->request->set_header_field
      exporting
        name  = '~request_method'
        value = 'POST'.
    call method http_client->request->set_header_field
      exporting
        name  = '~server_protocol'
        value = 'HTTP/1.1'.
    call method http_client->request->set_header_field
      exporting
        name  = '~request_uri'
        value = '/airport.asmx'.
    Regards
    Raja

  • How to set content type while sending an email?

    Hello,
    I want to set content type text/html while send an email using org.apache.commons.httpclient api. I am using MultipartPostMethod method. and i am set using object of multipartpostmethod like post.
    and post.setRequestHeader("Content-Type","text/html").
    but it wont work.
    so please give me a proper solution.
    example::
    MultipartPostMethod post = new MultipartPostMethod("url");
    post.addParameter("msgbody","html message");
    post.setRequestHeader("Content-Type","text/html");
    Regards,
    Bhavesh Kharwa

    Actually, I'm writing a "HashMap" from servlet to applet. I have used your suggested content type "application/octet-stream" and another "appication/x-java-serialized-object" to try it. But in applet side, when I use (HashMap)in.readObject(), it always gives me a exception as:"java.util.HashMap; IllegalAccessException". Why?
    Thankd.

  • How do you *unset*  Content-Type when using HttpURLConnection ?

    Hi people,
    I am using HttpURLConnection to set some http headers. It all works fine except that this utility is setting Content-type to text/html even though I cam not coding it to do so. I can overwrite Content-type by setting it to say, a blank, explicitly in the code, but Content-type still appears as a header (eg if I view the headers in a proxy.)
    My question is - how do you completely unset Content-Type? Here's the code snippet :
    URL url = new URL("http://mymachine-uk.uk.company.com:24331/test.html");
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setIfModifiedSince(longdate); // I've set up longdate previously
    // set some headers
    con.setRequestProperty("Cache-Control","max-age=0");
    con.setRequestProperty("User-Agent","Mozilla/5.0");
    con.setRequestProperty("Keep-Alive","300");
    // I've tried hacking it like this :
    // con.setRequestProperty("Content-type",null);
    // but that just shows an empty Content-type, rather than get rid of it.
    // In a proxy window on port 24331, the three headers set explicitly above
    // all show up correctly. But Content-type:text/html is also shown, even though not coded.
    // If I fire off the same page request from a browser, Content-type ISN'T set.
    // so there must be a way of doing it :-) Help!
    thanks.
    Edited by: colin_the_aardvark on Feb 24, 2010 1:45 AM

    Hi there,
    thanks very much for trying this, the background to this is as follows :
    I am testing a software server caching product which is giving me weird behaviour; the actions the cache performs are supposed to be based on the various http headers. I am using a debug proxy ("Charles") (limited freeware-for-a-short-period) to see exactly what http headers are being set by the calling browser, or in this case, the java program. I am setting the headers directly in the code above to match what my browser is setting, as revealed by Charles. Trouble is, I'm getting different reponses back: The browser gets a http 304 from the cache and my java program gets a 200, so I have obviously failed to emulate the browser.. and the only difference I can see is that the Conetnt-Type is not set when I call the page from internet explorer, but with my program above, Content-Type is set, to a default of text/html. I want to get rid of it so I have copied the browser http header settings 100%.
    - I tried compiling this code and running it from the prompt (outside of development environment) and Content-Type is still showing up. So from what you are saying... if your attempt does not set this.. then it looks like Content-type must be getting set via some other means?
    thankyou :-)

  • I download itext  for convert jsp to PDF. How to set content type for PDF.

    I download itext for convert jsp to PDF. How to set content type for PDF. I try
    <%@ page contentType = "application/pdf;charset=TIS-620" %>
    , but the page does not PDF.
    Thank.

    PDF files are usually binary files, JSPs are not well-suited for binary content.
    (If you download the result of your JSP you'll see that it is not a valid PDF file; it will have probably a lot of whitespace and linefeeds, that will choke your PDF reader.). The first few characters must be
    "%PDF-" without whitespace.
    You can try using PDF files encoded as text - check if you can use text-encoded PDFs in iText.
    Try using a Servlet instead.

  • Set content type in respone

    Hi,
    I am using velocity model and to set the content type of response as csv report i am setting content type of response as
    $response.setContentType("application/vnd.ms-excel")
    This stmt opens up open-save download dialog box. But the problem is a new internet browser window also opens up. I want to hide this newly opened browser till i click on open button.
    How i can hide or disable this IE window.

    Ritu,
    U specified only content type , try to specifiy attributes like attachment where u can rid of the IE explorer.
    if u have any other doubts u r most welcome giving me a mail [email protected]
    Thanks.
    Sravan

  • I can't read the code to type when posting on the community page like craigslist

    Hi,
    I'm troubled when posting in craigslist through firefox.
    I cannot read the code or a word to type when posting for a security purpose (spam). This problem has started a couple months ago with Firefox. With Safari, this does not happen.
    Appreciated if you can help me out here because I use firefox as my primary internet browser.

    Basics from the manual are restrt, reset, restore.
    Have you tried each of these?

  • Choose a content type when creating a new list item

    Hi,
    I would like to know if there is a way how to change the "New" link in a SharePoint list.
    Problem:
    I have a list with free content types. If I click an existing item a form appears where I can change the content type. But if I create a new item by click the "New" link (directly to the link, not to the little arrow), I am automaticly creating the default content type (the first one).
    This is confusing for users. Can I change it so a user can choose a content type after he or she clicks the "New" link?
    Thanks for any advice.

    Hiya,
    I have a solution!
    If you have three set content types for a list, rather than encouraging people to click the arrow by the new button put three links on a new page that link to the new form for each content type.
    <a href="http://site/Lists/test/NewForm.aspx?ContentTypeId=CONTENTTYPEID1">Create a new item with content type 1</a>
    <a href="http://site/Lists/test/NewForm.aspx?ContentTypeId=CONTENTTYPEID2">Create a new item with content type 2</a>
    <a href="http://site/Lists/test/NewForm.aspx?ContentTypeId=CONTENTTYPEID3">Create a new item with content type 3</a>
    The main problem with this is that if you add new content types to the list, you have to add new links to the page.
    Mike
    The only thing I would add is that, the content type ID is a number (1, 2, 3.....) based on the order that the content types were added to the SP list.

  • Document Set Content Type Workflow

    I have a document library in Share Point 2013 that is using Document Sets.  I need to set up a workflow under the document content type that would send an e-mail if documents have not been uploaded by a specific due date in the document set.  Any
    Help will be greatly appreciated.

    Hi,
    Based on your description, my understanding is that you want to send an email if there is no document uploaded to the document set by a specific due date in the document set.
    I recommend to create retention policy on the document set content type in the library to start the workflow at the due date.
    The workflow can be created as the image below:
    Firstly, get the max id in the library for using in the loop condition in the workflow:
    You can follow the link below for details:
    http://social.technet.microsoft.com/Forums/en-US/a8a890b5-f5fb-447f-b96f-9f3abdb7e178/forum-faq-sharepoint-2013-extracting-values-from-a-multivalue-enabled-lookup-column-and-merge?forum=sharepointgeneral
    Secondly, we need to loop through the items in the library and then check if there are documents(including folders)
     existed inside the document set which is called text for example.
    Please change the string “/sites/victoria/lib set/” in the Replace Substring in String step to be the relative URL of your library and make sure that there is a space before the document set name in the if condition in the workflow as the image below shows:
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Set content type based on file extension after uploading into document library

    when there are multiple content types associated with a document library, say, report builder report, and excel documents, after you drag and drop a document into the document library, content type will not be detected based on the file extension. Suppose
    your default content type is document, and you had added the report build report content type, and you uploaded a .RDL file, the content type for the file will be set to the default document content type.
    I get a requirement to update the content type automatically based on the file extension, what follows is my code:
    public class setCNTByFileExtItemAdded : SPItemEventReceiver
    /// <summary>
    /// An item was added.
    /// </summary>
    public override void ItemAdded(SPItemEventProperties properties)
    if (properties.Web.GetFile(properties.AfterUrl).Exists)
    SPListItem CurrentListItem = properties.Web.GetFile(properties.AfterUrl).Item;
    String FileName = CurrentListItem.Name;
    if (FileName.EndsWith(".rdl",StringComparison.OrdinalIgnoreCase))
    CurrentListItem.Properties["ContentTypeId"] = "0x010100C3676CDFA2F24E1D949A8BF2B06F6B8B";
    CurrentListItem.SystemUpdate(false);
    base.ItemAdded(properties);
    What follows are references that helped me:
    http://stackoverflow.com/questions/7984300/properties-listitem-is-null-in-itemadded-event-while-uploading-documents-using
    http://williamvanstrien.blogspot.in/2011/10/read-content-of-uploaded-file-within.html
    http://blogs.msdn.com/b/manuj/archive/2009/09/22/itemadded-event-on-document-library-the-file-has-been-modified-by-on-error.aspx
    http://support.microsoft.com/kb/2647429

    user may have further requirement to detect whether the uploaded .xlsx file contains powerpivot data model, i tried the following code, the caveat is that .xlsx is actually a zip file, i just test whether the uploaded stream contains an entry xl/model/item.data.
    public partial class ApplicationPage2 : LayoutsPageBase
    protected void Page_Load(object sender, EventArgs e)
    if (this.IsPostBack)
    if (FileUpload1.PostedFile == null)
    return;
    string destWeb = DestinationUrl.Url;
    string destUrl = destWeb + "/" + FileUpload1.FileName;
    using (SPSite site = new SPSite(destWeb))
    using (SPWeb web = site.OpenWeb())
    SPFile f = web.Files.Add(destUrl, FileUpload1.PostedFile.InputStream);
    if (FileUpload1.FileName.EndsWith(".xlsx") )
    Stream fs = f.OpenBinaryStream() as Stream;
    using (ZipArchive zfs = new ZipArchive(fs, ZipArchiveMode.Read))
    if (zfs.GetEntry("xl/model/item.data") == null)
    Debug.WriteLine("Does not contain data model");
    else
    Debug.WriteLine("Contain data model");
    The code i posted here is part of an application page in layout folder, the reason why i use application page is described in
    http://social.msdn.microsoft.com/Forums/sharepoint/en-US/065d010a-d37e-4da4-9873-172ab2c50d6d/custom-list-new-application-page-with-listfielditerator-and-savebutton?forum=sharepointdevelopment#288a686e-bfbe-41aa-83d0-58a80f0cec07

  • How to set content type in servlet?

    Hi, there,
    I'm writing a servlet to use ObjectOutputStream to return an object to applet. How can I set this content type in servlet?
    Thanks.

    Actually, I'm writing a "HashMap" from servlet to applet. I have used your suggested content type "application/octet-stream" and another "appication/x-java-serialized-object" to try it. But in applet side, when I use (HashMap)in.readObject(), it always gives me a exception as:"java.util.HashMap; IllegalAccessException". Why?
    Thankd.

  • How to set Content-Type of attachment?

    Does anyone know how I can set the Content-Type of an attachment of an outgoing mail?
    I use Apple Mail, and with one correspondent I have this annoying problem that he never receives any excel or word attachments that I send (and possibly other ones, too).
    Our support now says that I should try to set the Content-Type
    of the excel attachments to "Content-Type: application/vnd.ms-excel".
    Apple Mail seems to set it to
    "Content-Type: application/octet-stream"
    and they think that attachments with this content-type might get blocked by the mail server of my correspondent.
    Any suggestions, ideas, etc., will be appreciated.
    Best regards,
    Gabriel.

    Thanks a lot for your test.
    Unfortunately, I get
    Content-Type: application/octet-stream;
    when I try to send an excel attachment to myself.
    Below is the beginning of the email (in "source" format).
    Any ideas why you get the correct mime-type, but I don't?
    Regards,
    Gabriel.
    ---------- beginning of email
    Return-Path: <[email protected]>
    Received: from [80.128.100.143] (account xxxxxxx HELO [192.168.2.100])
    by tu-clausthal.de (CommuniGate Pro SMTP 5.2.4)
    with ESMTPSA id 35503032 for [email protected]; Mon, 30 Jun 2008 21:59:05 +0200
    Message-Id: <[email protected]>
    From: Gabriel Zachmann <[email protected]>
    To: Gabriel Zachmann <[email protected]>
    Content-Type: multipart/signed; boundary=Apple-Mail-13-325543015; micalg=sha1; protocol="application/pkcs7-signature"
    Mime-Version: 1.0 (Apple Message framework v924)
    Subject: test
    Date: Mon, 30 Jun 2008 21:59:04 +0200
    X-Mailer: Apple Mail (2.924)
    --Apple-Mail-13-325543015
    Content-Type: multipart/mixed;
    boundary=Apple-Mail-12-325542957
    --Apple-Mail-12-325542957
    Content-Disposition: attachment;
    filename="Kostenabfrage AVILUS Gesamtinklusive_TPxyz 080606.xls"
    Content-Type: application/octet-stream;
    x-mac-creator=5843454C;
    x-unix-mode=0644;
    x-mac-type=584C5338;
    name="Gesamt.xls"
    Content-Transfer-Encoding: base64

  • Setting content type

    I am using servlet to display an Excel file to the browser.hence,for the same I need to set the content type.
    I make an object of file by:
    File file = new File("abc.xls");
    response.setContentType(application.getMimeType(file.getName()))which is giving the output as a garbled value.That is,it is not able to set the content type.
    but when I am using
    response.setContentType("application/vnd.ms-excel");It sets the content type.
    Any idea what is wrong with the first syntax?????//

    I think what you wrote and what I wrote is same.
    anyhow,the problem got solved using:
    response.setContentType(application.getMimeType(file.getName()));I added the following in web.xml
    <mime-mapping>
      <extension>xls</extension>
      <mime-type>application/vnd.ms-excel</mime-type>
    </mime-mapping>

  • Urgent: How to set content type on upload depending on target folder?

    Hi,
    i have to set the content type of a file uploaded via SMB depending on the folder the file is placed in. All files placed below a certain root directory have to be of my custom content type. All others should be stored as documents of type "Document". Is there an easy way to accomplish this task? I can't assume any specific file extensions and can therefore not register my custom content type to that extension.
    Any hints are welcome.
    Thanks.

    Hi,
    i have to set the content type of a file uploaded via SMB depending on the folder the file is placed in.All files placed below a certain root directory have to be of my custom content type.
    +++ Use an agent to verify the name and extension using the IfsEvent class and EVENTTYPE_CREATEINSTANCE
    All others should be stored as documents of type "Document". Is there an easy way to accomplish this task?
    +++ Those that aren't your custom content type move to a different folder using the agent.
    I can't assume any specific file extensions and can therefore not register my custom content type to that extension.
    +++I've found that registering content type only really affects things like how a browser knows what kind of file it's downloading/looking at (mime type) or how a renderer knows how to render it.
    Any hints are welcome.
    Thanks.

  • How to set content type for a JSF page

    Hi,
    I want to know is there any way we can specify the content type of a JSF page, like in JSPs we have the page attribute <%@ page contentType="application/vnd.ms-excel" %>
    In JSP we can create a html table with values and if we specify the contenType as application/vnd.ms-excel, we would get an excel file generated.
    But do we have something similar to this is JSF, as I am using Facelets I cannot use page directive in the xhtml file.
    I tried setting the content type in MangedBean's action as follows
    ((HttpServletResponse)FacesContext.getCurrentInstance().getExternalContext().getResponse()).setContentType("application/vnd.ms-excel"); but it did'nt work.
    Thanks in advance.

    //add related mutip-part to combine parts
    MimeMultipart multipart = new MimeMultipart("related");
    //attach a pdf
    messageBodyPart = new MimeBodyPart();
    fds = new FileDataSource("h:/something.pdf");
    messageBodyPart.setDataHandler(new DataHandler(fds));
    messageBodyPart.setFileName(fds.getName());
    multipart.addBodyPart(messageBodyPart);
    //add multipart to the message
    message.setContent(multipart);
    //send message
    Transport.send(message);

Maybe you are looking for

  • Store Filename on a table in PI server.

    Hey Guys I have a requirement in which i need to store all the filenames on a table in PI server and then run a ABAP report by the end of the day(every 24 hours) to display list of all the files which passed through PI. The solution i m thinking of r

  • E-mail alerts in planning & essbase log

    Hi All, 1).How to get the e-mail alerts in planning . 2).where can we find in detail log file in Essbase. Bunny

  • To display records fetched from the DB through ALBPM, in a custom JSP

    I want to display the records fetched from the database through ALBPM in a custom JSP as a table. Currently I am fetching the records and putting them in a BPM object group and sending it to the JSP as a BPM object. Now in the JSP I am trying to iter

  • FTI_TR_POSITIONS with LDB_PROCESS

    Hello everybody I am trying to get data ouf of the LDB FTI_TR_POSITIONS but all I get is a runtime error: LDB_SELECTIONS_NOT_ACCEPTED what am I doing wrong? DATA callback LIKE ldbcb OCCURS 0 WITH HEADER LINE.     DATA seltab   LIKE rsparams OCCURS 0

  • Flash CS5 Symbol stage stuck in top left corner

    In my adobe Flash CS5 when i create a new symbol it opens in a new screen as normal. the stage that I can edit it on however is stuck in the top left when I zoom out and it's starting to drive me nuts. I can't work with it like that. Anybody know how