Content-Type URLConnection

I need to set my content type to be XML. I used the following:
HttpURLConnection urlConn = null;
URL u = new URL( url );
urlConn = (HttpURLConnection)u.openConnection();
urlConn.setDoOutput( true );
urlConn.setDoInput( true );
urlConn.setRequestMethod("POST");
urlConn.setRequestProperty("Content-Type","text/xml");
Why then does urlConn.getContentType() return text/html;charset=ISO-8859-1?
Liz

Hi Liz,
a call of getContentType() receives data from the net and returns the content type of the fetched data.
"http://www.tutego.com/index.html" -> text/html
"http://www.tutego.com/images/customer-transition.gif" -> image/gif
Best wishes,
Christian Ullenboom | http://www.tutego.com/

Similar Messages

  • Content type of .key files

    Dear team ,
    please tell me the "contenttype" of the .pages file format....
    example: .doc....is having the content type as "application/ms-word"
    similarly can u tell me content type of .pages
    Regards,
    spradeepkumar

    hi balusC thanks, it works very well.
    your site http://balusc.xs4all.nl/srv/dev-jep-pdf.html helped me a lot.
    But one point. There is another method : URLConnection.guessContentTypeFromStream(InputStream)but it don't work and i receive as result a null.
    Is there another classes/methods which helps getting the content type of a file? not necessarily from sun. thanks
    bye

  • Content Type problem

    I am trying to retrieve the content type of a file.
    String strContentType ="";
              File file = new File(fileName);
              FileNameMap  fnmMime        = URLConnection.getFileNameMap ( ) ;
               if ( fnmMime != null ) {
                      strContentType = fnmMime.getContentTypeFor ( "file://c:2.avi" ) ;
    System.out.println(strContentType);It works perfect for image, video , sound formats, but it gives null for microsoft office documents and openoffice documents.
    can anyone help me?
    Thanks in Advance.

    Nirav-P-Thakar wrote:
    FileNameMap  fnmMime        = URLConnection.getFileNameMap ( ) ;
    fnmMime.getContentTypeFor(fileName);
    URLConnection.guessContentTypeFromName(fileName);I have tried out both methods but it returns null when the file is of type MS Office or Open Office.In reply 1 BalusC said..
    "Alternatively you can use ServletContext#getMimeType() for this. It guesses the content type based on the mime mapping as it is been definied in the web.xml of the application server and the webapplication. If it returns null, then you need to add new <mime-mapping> entry to the web.xml."
    I would try doing it this way. Try including entries for the mime mappings in the deployment descriptor of the web application.

  • Setting the correct content type

    Hi,
    We store files in a database and the actual uploading and retrieving process works very well.
    However, when serving a request for a file I would like to set the content type the browser can read.
    An example: a httpservletRequest header "accept" comes back with */* - accepting all. Say the file requested is a xls spreadsheet. Since the accept header does not give me any information about the accepted content types, the following possibilities arise for a xls spreadsheet:
    - application/excel
    - application/vnd.ms-excel
    - application/x-excel
    - application/x-msexcel
    Same thing for power point files (.ppt) and others.
    Which of the listed content types do I set as the contentType for the HttpServletReponse so that the browser displays the information correctly?
    Whenever possible I would like to avoid the save dialog and display the file inline in the browser.
    Thanks for the help,
    -Rogier

    Here is the complete list of the right MIME types: http://www.w3schools.com/media/media_mimeref.asp
    You can retrieve it from filename by URLConnection#guessContentTypeFromName(), or add an extra field to the database which saves the MIME type.
    Checkout this FileServlet example for some insights: http://balusc.xs4all.nl/srv/dev-jep-fil.html

  • URL getContent failing to determine content type

    Within my application I am trying to load a file using the URL class. The file is deployed to the web directory /reports/report.txt. If I use the following code it returns to me the message "no content-type" and fails to load the content of the file. I am not sure how to get this to determine the content type or what I need to modify to get this to load the file. Any pointers would be appreciated.
    Stirng templateUrl = "/myApp/reports/reports.txt";
    URL url = new URL("http", "localhost", 7001, templateUrl);
    URLConnection conn = url.openConnection();
    logger.debug("content type: " + conn.getContentType());

    mperemsky5 wrote:
    Within my application I am trying to load a file using the URL class. The file is deployed to the web directory /reports/report.txt. If I use the following code it returns to me the message "no content-type" and fails to load the content of the file. I am not sure how to get this to determine the content type or what I need to modify to get this to load the file. Any pointers would be appreciated.
    Stirng templateUrl = "/myApp/reports/reports.txt";
    URL url = new URL("http", "localhost", 7001, templateUrl);
    URLConnection conn = url.openConnection();
    logger.debug("content type: " + conn.getContentType());So my first question is:
    Does this file exist localhost/myApp/reports/report.txt ?
    If it does type in localhost/myApp/reports/report.txt and it should show in your browser.
    If not, then yes, you don't have any content there.

  • Extended Content type problem

    Extended Content type problem
    I want to extend the content type 'ExtendDocument' from 'Document'.
    So I use 'Oracle Internet File System Manager' to create a new Class Object named 'EXTENDDOCUMENT', which is extend from 'DOCUMENT', and add a attribute 'EXTENDURL'.
    This Class Object's bean class is 'ifs.beans.ExtendDocument' and server class is 'ifs.server.S_ExtendDocument'.
    I create these 2 java class and put the class files to ORACLE_AS_HOME\ifs\cmsdk\custom_classes directory.
    As I want to set the object type as 'ExtendDocument' when uploading a file which expend name is '*.wmv', so that need to change 2 default value 'ParserLookupByFileExtension' and 'IFS.PARSER.ObjectTypeLookupByFileExtension'
    So I add 'name=wmv, datatype=STRING, value=oracle.ifs.beans.parsers.ClassSelectionParser' to ParserLookupByFileExtension.
    And then add 'name=wmv, datatype=STRING, value=EXTENDDOCUMENT' to IFS.PARSER.ObjectTypeLookupByFileExtension.
    After done above actions, i restart my oracle application.
    I use CUP to upload a test file 'test.wmv' to CMSDK repository, and its type is 'EXTENDDOCUMENT'.
    But if I use FTP or WebStarterApp application to upload 'test.wmv' file to CMSDK repository, then its type is 'DOCUMENT'.
    Why and how to change to make FTP and WebStarterApp application can upload *.wmv file's type as 'EXTENDDOCUMENT'?
    anybody can help me?
    thanks.

    Nirav-P-Thakar wrote:
    FileNameMap  fnmMime        = URLConnection.getFileNameMap ( ) ;
    fnmMime.getContentTypeFor(fileName);
    URLConnection.guessContentTypeFromName(fileName);I have tried out both methods but it returns null when the file is of type MS Office or Open Office.In reply 1 BalusC said..
    "Alternatively you can use ServletContext#getMimeType() for this. It guesses the content type based on the mime mapping as it is been definied in the web.xml of the application server and the webapplication. If it returns null, then you need to add new <mime-mapping> entry to the web.xml."
    I would try doing it this way. Try including entries for the mime mappings in the deployment descriptor of the web application.

  • Get Website content type

    Hello,
    How can I get the content type of an url (e.g. text/plain)?
    thank you,
    Peter

    java.net.URL url = ...;
    java.net.URLConnection conn = url.openConnection();
    String contentType = conn.getContentType();

  • Application Error while activating the feature - for creating list content type, list definition and list instance

    Dear all,
    I am getting application error while enabling the feature. if any body can point out the issue - that will be helpful.
    content type
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <Field ID="{4C1B0A21-FCE0-4CFE-8742-A250672AFE4F}" Type="Note" Name="CourseDesc" DisplayName="Course Description" Required="TRUE" Group="Training Site Columns"/>
    <!-- Parent ContentType: Item (0x01) -->
    <ContentType ID="0x0100d57ecc53fde34177b096abd0ec90a8f9"
    Name="TrainingCourses"
    Group="Training Content Types"
    Description="Defines a Course"
    Inherits="TRUE"
    Version="0">
    <FieldRefs>
    <FieldRef ID="{4C1B0A21-FCE0-4CFE-8742-A250672AFE4F}" Name="CourseDesc" DisplayName="Course Description" Required="TRUE"/>
    </FieldRefs>
    </ContentType>
    </Elements>
    List definition
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->
    <ListTemplate
    Name="TrainingCourses"
    Type="10100"
    BaseType="0"
    OnQuickLaunch="TRUE"
    SecurityBits="11"
    Sequence="410"
    DisplayName="TrainingCourses"
    Description="Training Courses List Definition"
    Image="/_layouts/images/itgen.png"/>
    </Elements>
    List instance
    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
    <ListInstance Title="TrainingCourses"
    OnQuickLaunch="TRUE"
    TemplateType="10100"
    Url="Lists/TrainingCourses"
    Description="Training Course List Instance">
    </ListInstance>
    </Elements>
    schema
    <?xml version="1.0" encoding="utf-8"?>
    <List xmlns:ows="Microsoft SharePoint" Title="TrainingCourses" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/TrainingCourses-LD_TrainingCourses" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">
    <MetaData>
    <ContentTypes>
    <ContentType ID="0x0100d57ecc53fde34177b096abd0ec90a8f9" Name="TrainingCourses" Group="Training Content Types" Description="Defines a Course" Inherits="TRUE" Version="0">
    <FieldRefs>
    <FieldRef ID="{4C1B0A21-FCE0-4CFE-8742-A250672AFE4F}" Name="CourseDesc" DisplayName="Course Description" Required="TRUE" />
    </FieldRefs>
    </ContentType>
    </ContentTypes>
    <Fields>
    <Field ID="{4c1b0a21-fce0-4cfe-8742-a250672afe4f}" Type="Note" Name="CourseDesc" DisplayName="Course Description" Required="TRUE" Group="Training Site Columns" />
    </Fields>
    <Views>
    <View BaseViewID="0" Type="HTML" MobileView="TRUE" TabularView="FALSE">
    <Toolbar Type="Standard" />
    <XslLink Default="TRUE">main.xsl</XslLink>
    <RowLimit Paged="TRUE">30</RowLimit>
    <ViewFields>
    <FieldRef Name="LinkTitleNoMenu">
    </FieldRef>
    <FieldRef Name="CourseDesc">
    </FieldRef>
    </ViewFields>
    <Query>
    <OrderBy>
    <FieldRef Name="Modified" Ascending="FALSE">
    </FieldRef>
    </OrderBy>
    </Query>
    <ParameterBindings>
    <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
    <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
    <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_ONET_HOME)" />
    </ParameterBindings>
    </View>
    <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">
    <Toolbar Type="Standard" />
    <XslLink Default="TRUE">main.xsl</XslLink>
    <RowLimit Paged="TRUE">30</RowLimit>
    <ViewFields>
    <FieldRef Name="Attachments">
    </FieldRef>
    <FieldRef Name="LinkTitle">
    </FieldRef>
    <FieldRef Name="CourseDesc">
    </FieldRef>
    </ViewFields>
    <Query>
    <OrderBy>
    <FieldRef Name="ID">
    </FieldRef>
    </OrderBy>
    </Query>
    <ParameterBindings>
    <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
    <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
    </ParameterBindings>
    </View>
    </Views>
    <Forms>
    <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
    </Forms>
    </MetaData>
    </List>
    I am applying the feature to SPWeb level.
    cheers
    Sathya

    redeployed a new solution; since I was getting this error. I would have done typo errors etc.
    https://naveengopisetty.wordpress.com/2011/09/10/error-occurred-in-deployment-step-activate-features-invalid-file-name-the-file-name-you-specified-could-not-be-used-it-may-be-the-name-of-an-existing-file-or-directory-or-you-may-not-have-pe/
    Cheers
    Sathya

  • Not able to crawl all items from External content type

    Hello All,
    "All the records in my external content source are not getting crawled, only 1/3 rd of the data are getting crawled."
    Steps:
    I created "External content type" using sharepoint designer which connects to a SQL Server database.
    Have written a SQL View joining 2 tables, which return 9,00,000 rows when executed using the SQL Server management studio.
    I used the default "Business Data Connectivity Service" and "Search Service Application" and made sure the necessary permissions are set.
    Created a External Content source for the search service application and selected the "Business Data Connectivity Service" -> "Crawl selected External datasource" -> <my external datasource i created in sharepoint designer>
    Issue
    When i ran the full crawl for the first time it crawled "3,49,923" records in 01 hour and 07 seconds. And returned 1 error "Error crawling LOB Contents.(Error caused by exception: System.InvalidOperationException. There is an error in XML
    document...)
    Later i removed the below item from the index and started a full recrawl, this time it crawled "3,49,924" records 1 record extra from my previous crawl
    and no errors were returned.
    Please let me know what could be the issue. It doesn't look like the permission related issues as i am able to crawl the 1/3rd of my total data. Also i am able to search the crawled data. I also set the throtteling limit for the "Business data catalog"
    to -maximum 10000000 -default 1000000 which is less than the data it has to crawl.
    SRIRAM

    Hi ,
    I started the change suggested in the link shared by you, but got stuck at a point,
    The field which i set as identifier in BCS earlier is not having unique values. Total rows returned by the sql view is 899000, but the unique values present in the column that is set as identifier is
    3,49,923, which is equal to the number of rows crawled. - Is this the reason why it didnt crawl all records?
    The table that is used in the sql view has composite key, - Is it possible to have multiple identifier in BCS as well?
    Is it possible to make BCS to ignore the identifier? i mean creating BCS without an identifier column?
    Please let me know your suggestions on this.
    Thanks,
    SRIRAM
    Yes, BCS needs a UID. This is so it can figure out changes over time to a single record. Otherwise all changes to a row could be a potential new row without BCS knowing any better.
    Yes, or just have it run off the composite key instead of the field you're using now.
    Nope, BCS needs a UID field like in answer 1 :)
    Good luck!
    My CodePlex -
    My Blog - My Twitter
    Join me at the San Francisco SharePoint User Group!
    If this post helped you or answered your question please remember to mark it! :)

  • Cannot add hub-managed content type with external list lookup columns to a list -- Error:Id field is not set on the external data field

    This is a variation on the issue mentioned in this
    post
    We are using SP 2010 Content Hub to manage our content types.  On the content hub we've created a couple of exteranl lists, and then created some site columns as lookups against these lists.  We then added the columns to one of our content types
    and set it to publish.
    After the publishing job executed, I tried adding the content type (which now appears on the subscriber sites) to one of the document libraries on one of the subscriber sites.  When I did that it threw the following error:
    Microsoft.SharePoint.WebControls.BusinessDataListConfigurationException: Id field is not set on the external data field    
    at Microsoft.SharePoint.SPBusinessDataField.CreateIdField(SPAddFieldOptions op)     
    at Microsoft.SharePoint.SPBusinessDataField.OnAdded(SPAddFieldOptions op)     
    at Microsoft.SharePoint.SPFieldCollection.AddFieldAsXmlInternal(String schemaXml, Boolean addToDefaultView, SPAddFieldOptions op, Boolean isMigration, Boolean fResetCTCol)     
    at Microsoft.SharePoint.SPContentType.ProvisionFieldOnList(SPField field, Boolean bRecurAllowed)     
    at Microsoft.SharePoint.SPContentType.ProvisionFieldsOnList()     
    at Microsoft.SharePoint.SPContentType.DeriveContentType(SPContentTypeCollection cts, SPContentType& ctNew)     
    at Microsoft.SharePoint.SPContentTypeCollection.AddContentTypeToList(SPContentType contentType)     
    at Microsoft.SharePoint.SPContentTypeCollection.AddContentType(SPContentType contentType, Boolean updateResourceFileProperty, Boolean checkName, Boolean setNextChildByte)     
    at Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType)     
    at Microsoft.SharePoint.ApplicationPages.AddContentTypeToListPage.Update(Object o, EventArgs e)     
    at System.Web.UI.WebControls.Button.OnClick(EventArgs e)     
    at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)     
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)     
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)    b55297ed-717f-466d-8bdc-297b20344d3f
    I checked the external  content type configuration and it did specify an "id column".  Anyone know if what I am attempting to do is possible and if so, what special configurations are required?
    Thanks

    The issue is not External Content type or external list but the look up column.
    It's not possible to publish a look up column via the Content Type Hub.
    If you need to do this then an alternate way is to use a Managed Metadata column instead, otherwise you will have to implement this via a feature.
    Varun Malhotra
    =================
    If my post solves your problem could you mark the post as Answered or Vote As Helpful if my post has been helpful for you.

  • Problem with content type

    Hi All,
    I have set the content type to text/html by using the following statement in jsp
    <%@page contentType=�text/html�%>And if I give
    out.println("<a href="aaa.do">Click here</a>"); it is showing me a link to click here that's fine.
    But my problem here is that I am using struts <bean:write name="user1" property="subject"/> tag and the data in the subject field is Click here i.e the output from the database, now its not showing the link instead displaying every thing even if the content type is set. How can I achieve this? please help me out.

    in your bean:write tag try setting the filter attribute to false, like so
    <bean:write name="xxx" property="xxx" filter="false"/>
    http://struts.apache.org/1.2.9/userGuide/struts-bean.html#write

  • Look up column in Content Type Hub

    Hi,
     Would like to know whether look up columns are  supported /not supported in content type hub.
     Currently I am having few columns in my doc.libs which uses look up column and i want to implement content type hub.
    heard that this is a limitation in CTH.
    Can anyone from MS pls confirm.
     and at the same  time if I want to use the look up column functionality and implement CTH, any alternatives available.
    help is  highly appreciated!

    Hi,
    Please refer to the following article, it might help
    Content Type Hub Sync & Lookup lists
    And also refer to the following post.
    Content Type Hub Syndication and lookup site column within a content type
    Please mark it answered, if your problem resolved.

  • Sharepoint 2013 (Danish): Deploying site from a custom template fails with error "Duplicate content type"

    I cannot create a site-template in my own language (danish) and deploy a site based on the template.
    I created a template from a "fresh" SharePoint project site with no tampering.
    When trying to deploy a new site based on the templat I get the following error:
    In Danish:
    Beklager, men noget gik galt
    Det blev fundet et navn på en dubletindholdstype "billede".
    Tekniske oplysninger
    Fejlfinding af problemer med Microsoft SharePoint Foundation.
    Korrelations-id: 96646c9c-3213-a088-c6c4-537b0815313c
    Dato og klokkeslæt: 21-06-2014 10:23:36
    In English:
    Sorry, something went wrong
    A duplicate content type name "billede" was found.
    Technical Details
    Troubleshoot issues with Microsoft SharePoint Foundation.
    Correlation ID: 0b656c9c-52ee-a088-c6c4-5132070e3c4e
    Date and Time: 21-06-2014 10:31:35

    Need details from ULS logs about Correlation ID: 0b656c9c-52ee-a088-c6c4-5132070e3c4e
    Check below:
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/e955e737-e12e-4afa-b446-bb6e0f05e9b1/duplicated-content-type-error-creating-a-sharepoint-2010-site-from-a-custom-site-template?forum=sharepointgeneralprevious
    http://aramacciotti.wordpress.com/2012/04/04/the-case-of-the-duplicated-contenttype/
    http://community.office365.com/en-us/f/154/t/69416.aspx
    If this helped you resolve your issue, please mark it Answered

  • Versioning and Video Content type does not work.

    Hello,
    I have out of the box sharepoint installed.
    When I apply versioning to a library. And try to see "Document set version history" (as I suggest Video content type actually inherits from Document Set). I don't see any version.
    Can you tell me how can i see versions of the "Video" content type item in this Version History window?

    Document set versions are slightly different than item versions. Document sets can be managed by a separate ribbon tab called Document Set and group called Manage.
    Check below link for detail go through:
    How to retrieve document set version history
    Manage versions for Document Set
    Adnan Amin MCT, SharePoint Architect | If you find this post useful kindly please mark it as an answer :)

  • Crystal Report Preview vs. SAP B1 Report Preview  as a Layout under Content Type

    Hello good day i'm trying to create a report that will be preview under A/R Invoice but the details need is under delivery module for example i create a serialize Item and set the Management Method on Every Transaction Under Item master data, so the transaction flow will be like this SO -> Delivery -> A/R Invoice. So under delivery transaction i will choose the serial that i will deliver so that under A/R Invoice Transaction i will no longer choose again the said serial that i choose on Delivery Transaction. There for on my Report i will Based on Delivery Transaction to get the chosen Serial But the Report will be Preview under A/R Invoice.
    The main concern on This is why when i preview the said Report under Crystal Report the serial is showing but when i Import it on SAP B1 as a Layout under Content type it is no longer showing the serial on the preview?

    Please post to the SAP Business One Application forum
    - Ludek
    SCN Moderator

Maybe you are looking for

  • Firmware version 1.03 for 40UL605U units.

    Can someone direct me to a list of issues that this firmware addresses or post here a list of fixes for this firmware? I'm asking specifically for the 1.03 firmware for the 40UL605U units but if whomever is going to reply has a comprehensive list of

  • How do you freeze the tablix header row in an Excel export file in SSRS 2008?

    So this is totally killing me. I've found out how to make a tablix header row repeat on each page of a PDF export file in SSRS 2008 (which I won't even get started on because all I can say is that 2005 is way better), but I cannot figure out how to m

  • Material validation

    Hi, I have written a user exit prgram for material validation. I.e we maniatin a seprate "z" table, where the 'z' table contains filed like material code, wbs element & material price. when i create a P.O then it should check whether that material ex

  • Archiving... everything

    Premiere Pro, from at least cs4, made it fairly easy to archive using the Project Manger (Project ... Project Manager) popup window. But... many (most?) user projects reach beyond PPro and include work in After Effects, Audition, Photoshop (stills an

  • Patching ISE in distributed enviornment

    Hi We have couple of admin nodes managing couple of policy nodes in distributed environment. ISE version is 1.1 and patch level is 3. Can someone advise what will be Best practise to patch them to latest version. should I patch admin nodes first and