cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing config xml files in Web Dynpro

Former Member
0 Kudos

Hi,

I need to access some configuration files (xmls and not .properties files in configuration folder) in Web Dynpro. How should I can access these files? I mean, where should I keep them in the folder structure? i.e. src/configuration, src/packages, src/lib etc. I tried to place them every where but unable to access it from Web Dynpro. I tried with both XmlFileLoader and normal FileReader, but with no luck.

Highly appreciate any help.

Thanks.

MSR

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Place the file inside the "src/mimes/Components/<path to your component>" folder. Let's call the file "NewFile.xml" Then you can parse the file using the following code:


try {
String xmlUrl = WDURLGenerator.getResourcePath(wdComponentAPI
                                               .getComponent()
                                               .getDeployableObjectPart(), 
                                                "NewFile.xml");
if(xmlUrl != null){
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new File(xmlUrl));
//do further processing...
}
} catch(IOException e){
       //log
	wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage());
} catch (WDAliasResolvingException e){
       //log
	wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage());
} catch (ParserConfigurationException e){
       //log
	wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage());
} catch (SAXException e){
        //log
	wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage());
}

Regards,

Satyajit

Former Member
0 Kudos

Hi Satyajit,

Thanks so much for a quick answer. Yes, this works in reading the file from src folders.

But my actual requirement is a little more complex. I will explain it here.

I have some custom APIs in Jar files. They in turn use configuration xml files to get some values. Those APIs are originally written in Java for J2EE AS and the config files are supposed to be on the server.

Now, I need to use those APIs in my web dynpro project. When I am trying this scenario, the APIs are unable to read these xml files when kept in the folders such as src/configuration etc.

So, I am wondering

1. is there any way (eg: classpath) I can specify the path to the folder where those files are and the API s can read from there in my Web Dynpro project?

(or)

2. how I can deploy these config files on the server so that the jars can read them and I can use those APIs in my Web Dynpro project.

Appreciate the help.

Thanks.

MSR.

Former Member
0 Kudos

Hi,

That depends on how the APIs are trying to read the config files. Are they using "Properties" load methods? Can you post the code where your custom APIs are trying to access the files?

Regards,

Satyajit

Former Member
0 Kudos

Hi Satyajit,

When I created a standalone Java project to access those APIs they read the config xmls fine.

But only when I create it in Web Dynpro, I am unable to use those APIs.

To simulate the scenario, I created a standalone Java application and read a config file stored under the project folder. When used the same code inside Web dynpro, I get a message saying that the file doesn't exist, unless I use the WDURLGenerator.

The APIs use the similar code such as,

Loader ldr = new XmlFileLoader();

List lst = ldr.load("/config_test/xxxx.xml");

Thanks.

MSR.