How to pass an XML file in a war file to the DocumentBuilder.parse

I am developing a webapp on the struts framework
I need to parse an XML file 'menu.xml' which I have placed under the 'WEB-INF/classes' folder
My Action class calls a helper class called XMLMenuBuilder which needs to parse the 'menu.xml'
Here are code snippets from my classes:
LogonAction.java
XMLMenuBuilder builder = new XMLMenuBuilder();
Vector menuVector = (Vector)builder.renderMenu();XMLMenuBuilder.java
public Vector renderMenu() throws AppException
  DocumentBuilder builder = factory.newDocumentBuilder();
  Document document = builder.parse( new File(xmlfile) );
}My Problem is how can I make the builder.parse access the 'menu.xml' file under the 'WEB-INF/classes' folder
instead of searching for it on the file system
Any help will be much appreciated

I got the answer myself
Got the answer myself. I needed the ActionServlet Context in the ActionClass. This is what I have done...
It works.
LogonAction.class
Code:
InputStream is = getServlet().getServletContext().getResourceAsStream("/WEB-INF/conf/menu.xml");
XMLMenuBuilder.java
Code:
Document document = builder.parse(is);
Thanks

Similar Messages

  • How to pass a xml CDATA in string element when OSB calling a webservice?

    How to pass a xml CDATA in string element when OSB calling a webservice?
    I have a business service (biz) that route to operation of a webservice.
    A example of request to this webservice legacy:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:eg="example">
    <soapenv:Header/>
    <soapenv:Body>
    <ex:execute>
    <ex:arg><![CDATA[<searchCustomerByDocumentNumber>
    <documentNumber>12345678909</documentNumber>
    </searchCustomerByDocumentNumber>]]></ex:arg>
    </ex:execute>
    </soapenv:Body>
    </soapenv:Envelope>
    the type of ex:arg is a string.
    How to pass this CDATA structure to webservice in OSB?

    Steps to solve this problem:
    1. Create a XML Schema. E.g.:
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
         elementFormDefault="unqualified">
         <xs:complexType name="searchCustomerByDocumentNumber">
              <xs:sequence>
                   <xs:element name="documentNumber" minOccurs="0">
                        <xs:annotation>
                             <xs:documentation>
                             </xs:documentation>
                        </xs:annotation>
                        <xs:simpleType>
                             <xs:restriction base="xs:string" />
                        </xs:simpleType>
                   </xs:element>
         </xs:sequence>
         </xs:complexType>
         <xs:element name="searchCustomerByDocumentNumber" type="searchCustomerByDocumentNumber"></xs:element>
    </xs:schema>
    With this XSD, the XML can be generate:
    <?xml version="1.0" encoding="UTF-8"?>
    <searchCustomerByDocumentNumber xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="searchCustomerByDocumentNumber.xsd">
    <documentNumber>documentNumber</documentNumber>
    </searchCustomerByDocumentNumber>
    2. Create a XQuery to create a searchCustomerByDocumentNumber ComplexType. E.g.:
    (:: pragma bea:global-element-return element="searchCustomerByDocumentNumber" location="searchCustomerByDocumentNumber.xsd" ::)
    declare namespace xf = "http://tempuri.org/NovoSia/CreateSearchCustomerByDocumentNumber/";
    declare function xf:CreateSearchCustomerByDocumentNumber($documentNumber as xs:string)
    as element(searchCustomerByDocumentNumber) {
    <searchCustomerByDocumentNumber>
    <documentNumber>{ $documentNumber }</documentNumber>
    </searchCustomerByDocumentNumber>
    declare variable $documentNumber as xs:string external;
    xf:CreateSearchCustomerByDocumentNumber($documentNumber)
    3. In your stage in pipeline proxy add a assign calling the XQuery created passing the document number of your payload.
    Assign to a variable (e.g.: called searchCustomerByDocumentNumberRequest)
    4. Create another XQuery Transformation (XQ) to create a request to the webservice legacy. E.g.:
    <ex:arg>{fn-bea:serialize($searchCustomerByDocumentNumberRequest)}</ex:arg>
    For more information about xquery serialize function:
    41.2.6 fn-bea:serialize()
    You can use the fn-bea:serialize() function if you need to represent an XML document as a string instead of as an XML element. For example, you may want to exchange an XML document through an EJB interface and the EJB method takes String as argument. The function has the following signature:
    fn-bea:serialize($input as item()) as xs:string
    Source: http://docs.oracle.com/cd/E14571_01/doc.1111/e15867/xquery.htm

  • How to pass an xml file as a command line argument

    hi,
    i would like to know how to pass xml tags (not an xml file) while running java command. i have already compiled the code and i have a .class file generated. i need to pass this argument in the java command because i am calling a web service which requires an xml as parameter to it.
    to be precise the java code contains soap request and i need to pass xml at run time.
    pl do reply if you have any ideas or solutions...
    Thanks in advance,
    gnsinhyd

    I got the answer myself
    Got the answer myself. I needed the ActionServlet Context in the ActionClass. This is what I have done...
    It works.
    LogonAction.class
    Code:
    InputStream is = getServlet().getServletContext().getResourceAsStream("/WEB-INF/conf/menu.xml");
    XMLMenuBuilder.java
    Code:
    Document document = builder.parse(is);
    Thanks

  • FTP how to pass dynamic filename/directory location - reading a file in 11g

    Hi All,
    We r using FTP adapter(SOA 11g) for getting files in remote server, May i know how to pass dynamic filename and directory where the file exists for reading in server.
    Thanks,
    Rak

    Hey according to my understanding, the Dynamic partner links are set only for the Outbound invocations only. Is my understanding right? if so, how do we create the dynamic partnerlinks for the ftp get kind of stuff...??
    Thanks in advance

  • How to pass values at runtime in JDBC - XI - File scenario

    Hi friends,
    In my scenario, data is coming from R/3 and i need to filter records from oracle database based on this data. There are 4 database tables that need to be queried using 2 select statements. The resultset after the execution of query will be mapped to the target flat file structure.
    here are my queries:
    1) Can I avoid BPM as data needs to be collected from the two database calls which involves two sender JDBC adapter instances with only one target structure?
    2) Can I use stored procedure in this scenario? If yes, than how to pass values to stored procedure at runtime via sender JDBC adapter.
    Thanks and regards,
    Nitin aggarwal.

    Hi Nitin,
    "..So i want to know if i can write multiple select statements in the stored procedure.."
    Read the below line that is mentioned in the SAP help documentation fro Sender JDBC adapter:-
    <i>Specify an SQL EXECUTE statement to execute a stored procedure, which contains exactly one SELECT statement.</i>
    I dont think it can be achieved...but there must be some workaround for this. You can probably use a join statement.
    Read this, again from the documentation:-
    <i>The expression must correspond to the SQL variant supported by the relevant JDBC driver. It can also contain table JOINs.</i>
    Regards,
    Sushumna

  • How to write an xml Document to a flat file using JAVA....

    Can any one help me out.....
    How to write a XML Document to the current filesystem using JAVA....
    without using com.sun.xml.tree.*....
    Document xmlDoc;
         Node rows = (Node) xmlDoc.createElement("ROWS");
    xmlDoc.appendChild(rows);
    and i have to write this xmlDoc to a file called(abc.xml) for further use...

    Have you considered using JDOM? ( www.jdom.org )
    The XMLOutputter class can write the Document to a file. ( The Document however will be an org.jdom.Document object ).
    If you are weary of a new API, you could just create a new File object called abc.xml and stream the data from the XML Document you have to this new File object.

  • How to pass MS CRM credentials from a config file to connect CRM from SSIS?

    Hi All,
    Can anyone please help me with the below requirement?
    I need to connect to Microsoft CRM from SSIS which is handled by a CRM proxy. However, configured the credentials in the code (hardcoded in script component) with respective MS CRM details. 
    Question: How can I pass my CRM credentials from a config file to my script component in SSIS to connect CRM?
    Thanks & Regards,
    Sri

    I used variables to pass the user and password details to my
    crm Script Component Destination and those variables can be filled by a regular config file or table.
    public override void PreExecute()
    base.PreExecute();
    // Fill .NET variables with values from project/package parameters/variables
    CrmUrl = this.Variables.CrmWebservice.ToString();
    CrmDomainName = this.Variables.CrmDomain.ToString();
    CrmUserName = this.Variables.CrmUser.ToString();
    CrmPassWord = this.Variables.CrmPassword.ToString();
    // Connect to webservice with credentials
    ClientCredentials credentials = new ClientCredentials();
    credentials.UserName.UserName = string.Format("{0}\\{1}", CrmDomainName, CrmUserName);
    credentials.UserName.Password = CrmPassWord;
    organizationservice = new OrganizationServiceProxy(new Uri(CrmUrl), null, credentials, null);
    Please mark the post as answered if it answers your question | My SSIS Blog:
    http://microsoft-ssis.blogspot.com |
    Twitter

  • How to pass command line parameters in calling ant file

    Hi All, I m using a Build file which calls another build file.
    That build file is run from the command prompt by give ant -lib <path of jars it needs for executing>.
    Now i m calling this file from main build file but it does not work as i m not able to set <b>-lib </b>.
    Pls can anybody let me know how to set such command line parameters to call the build file in ant script.
    Thanks in Advance.
    Ketan.B.Parekh

    Create the control file dynamically (and fill one of the columns with the file name as a constant) before you start SQL*Loader
    Another option is to use external tables
    Re: Data Loading
    Message was edited by:
    Jens Petersen

  • How to validate an xml with a schema w/o specifying the schema in the xml

    I have done xml validation with xml schemas, where the xml points to the xsd to use. However, I would like to not have to specifiy the xml schema in the xml document (and can't ensure that the xml coming to us has that in it). How do I, in the java code, tell it what schema to use in validation?
    Brian

    static final String schemaSource = argv[0];
    static final String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    DocumentBuilderFactory factory =
    DocumentBuilderFactory.newInstance();
    factory.setAttribute(JAXP_SCHEMA_SOURCE,
    new File(schemaSource));

  • Help! web.xml security without using WAR files

    I'm currently using the RDBMSRealm and URL ACL security for my app. I would like to use the web.xml descriptor for security so that I can specify login pages and such. We currently are not using WAR files. I've been having alot of trouble setting this up. Is there a way to use the RDBMS realm along with the web.xml security? It looks like it should work, but I can't seem to get it to function. How do I specify the regular document root as a webapp? I'm currently running WLS 5.1 with SP4. Thanks.

    The RDBMSRealm is just the authentication mechanism underneath WLS versus the
    web.xml of the WebApplication which describes all the access control for that WebApp.
    the later being scoped only to that WebApp.
    you don't need to deploy in a war file, you can expand the archive into an identical
    directory structure and then just point us towards the top level of that structure.
    see: http://www.weblogic.com/docs51/classdocs/webappguide.html
    .paul
    chris wrote:
    I'm currently using the RDBMSRealm and URL ACL security for my app. I would like to use the web.xml descriptor for security so that I can specify login pages and such. We currently are not using WAR files. I've been having alot of trouble setting this up. Is there a way to use the RDBMS realm along with the web.xml security? It looks like it should work, but I can't seem to get it to function. How do I specify the regular document root as a webapp? I'm currently running WLS 5.1 with SP4. Thanks.

  • How to deploy existing JSR 168 portlets (in war file) into portal?

    I have some JSR 168 portlets built and tested against another portal server that I would like to deploy in Bea portal server. They are packaged as a war file. I have a test portal and I am able to "develop" some new portlets in the Workshop but what I really want to do is just deploy the portlets as is. I have deployed the war using the web based deployment tool but I don't know how to "use" the portlets within a portal. Shouldn't this be easy? The docs don't discuss it much. Thanks for any help.
    -Andrew

    OK I found the answer:
    http://dev2dev.bea.com/products/wlportal81/articles/deployJava81sp3.jsp

  • How to export application developed in CQ as WAR file?

    Hi,
    We are using Eclipse as an IDE to develop our application using Adobe CQ's WCM capabilities. Is there a way to export the project files and its dependencies as a WAR file? We need this to run automated security scans on our code.
    We are using the following guidelines for developing our code:
    http://dev.day.com/docs/en/cq/current/developing/developmenttools/developing_with_eclipse. html

    Thank you Jorg. That was helpful.
    My concern was regarding 'exporting' the application that I create using CQ in a WAR format not importing a war file onto CQ5.
    But I think what you are saying is, since CQ5 doesnt have the functionality to import a project in war format, it doesnt provide the capability to export one.
    Many thanks!

  • Class file missing from war file deployment

    I have a web application that is being deployed to a war file. I have deployed several times successfully. Then with the latest changes, there is a class file that does not get included into the war file. It does get compiled and does exist in the project directory.
    The class file is in a seperate project from the project where the war file deployment profile is; however both projects are in the same workspace.
    There are several other classes in the project that contains the missing class file that does get included in the war file. I don't see anywhere in the profile where these files are selected individually.
    I'm at a loss as to how to fix this problem other than add the file after deployment.
    Appreciate any help or ideas...
    Keith...

    Hi Keith,
    You may want to follow this thread....
    class object missing from ear file
    Brigette

  • Single War file VS Separating WAR files suggestions

    Hi There
    We have big a debate whether to go with a single WAR file (JEE application) VS creating multiple WAR files.
    Here is the back ground: This is an IVR application.
    There are 4 types of callers Member, Provider, Dental, Vision. For each of them there is only JSP which will take care of all required Dialogues(Menus). At the end of the any call we collect MemberID regardless of the caller.
    There are 4 separate phone linse for the above 4 types of callers. However any caller can call into any of the lines. For example according to business requirements, Provider can call into Memebr line and hence Member(app) should be able to handle the logic. In other words Memebr & Provider are tied together.
    Arugents:
    I : I say create one single JEE project and have separate JSPs for the above 4 catagories so that teh application can share lot of common modules such as Logging, some Libs, configuraiton files, some JSFs, Some JSPs(We have some common JSPs that needed to be shared by 4 types of callers).
    Otherside argument: Each of the 4 call types should be created as a seperate WAR files so that change of one WAR does not affect the other.
    Even though that seems to be right given the nature of the business requirements change in one definitely affects other hence regression testing is needed on all of them anyway. In that case what benefits are we trying to reap except the extra maintainence.
    I would like some of your expert's opionions and thoughts on these approaches (Construction, vesioning, Maintenance perspective). I appreciate your inputs.

    This issue comes up repeatably. It's a real bug.
              I believe this problem was fixed in a 5.1 service pack, but I'm trying to
              find out the exact disposition of the issue. Noone seems to be complaining
              about this under 6.x, so a fix seems to have been made, the only question is
              whether or not it got back-ported to a 5.1 service pack.
              Gary
              david <[email protected]> wrote in message
              news:3ac4a39a$[email protected]..
              >
              > I work with WebLogic 5.1 and I'm trying to deploy a web application which
              gets
              > a properties file. If I deploy it as an expanded directory hierarchy (with
              the
              > properties files into WEB-INF/classes) I have no problems. While deploying
              it
              > by a .war file I get this message: "en_GB
              java.util.MissingResourceException:
              > Can't find resource for base name Agent, locale en " (the getBundle()
              method is
              > trying to get an english property file). What could I do? Is it really a
              weblogic
              > 5.1 bug?
              > Thanks,
              > David
              

  • Can a ear file contain two war files

    I have I want to merge two webapplications into single.
    is it possible?
    and also I want to know that can one .ear file contain more than one .war file?

    I don't see any problem about it... You might want to deploy to web sites into the same application server at once... I don�t think there are any kind of restrictions at this level.
    MeTitus

Maybe you are looking for

  • Copying large number of files with Finder

    When you copy lots of files and folders with Finder, it appears to count up the number of "items" and then start copying and at the same time the number of items remaining gets smaller and smaller as the copy process proceeds. My question is what are

  • Remove Header and Footer from a report

    Hi, I use the report S_ALR_87012104. But I want to export this report removing the header and footer. Is it possible to export the report excluding header and footer. That is line items only. Regards Mahbub

  • Display problem in ME47

    Sap Guru I m facing problem in RFQ i put all the vendor quotations thorugh RFQ ME47 and also all the terms and conditions, tax, VAT etc... i put 5 vendor quotation having tax code 2O - 5% VAT inclusive Excise out of 5 only one vendor displays the tax

  • I wander how to establish Webdispatcher on EP with HTTPS

    I wander how to establish Webdispatcher on EP with HTTPS . I can do it for HTTP. I found releated link in SAP Library: http://help.sap.com/saphelp_nw04/helpdata/en/d8/a922d7f45f11d5996e00508b5d5211/frameset.htm but still I do not understand as instal

  • Writing business apps, not flashy

    I work with a development community that shuns Flash because it's perceived as a tool for creating "flashy" apps, and not recognized at all for real solid businss apps involving payroll, order processing, inventory management, etc. I haven't worked w