2

My below code was working fine in Tridion 2009 and recently we migrated to Tridion 2011, below code written in java.

Getting the file: ExtensionsConfiguration.java

package com.tridion.custom.extensions;

import com.tridion.configuration.Configuration;
import com.tridion.configuration.ConfigurationException;
import com.tridion.configuration.XMLConfigurationReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExtensionsConfiguration
{
  private static Logger logger = LoggerFactory.getLogger(ExtensionsConfiguration.class);
  private static Configuration configuration;


  public static Configuration getInstance()
  {
    if (configuration == null)
      try
      {
        XMLConfigurationReader localXMLConfigurationReader = new XMLConfigurationReader();
        configuration = localXMLConfigurationReader.readConfiguration("cd_deployer_ext.xml");
        logger.info("ExtensionsConfiguration.getInstance:File Read",configuration.getContent());
      }
      catch (ConfigurationException localConfigurationException)
      {
        logger.error("ExtensionsConfiguration.ConfigurationException: Unable to read configuration.", localConfigurationException);
      }
      catch (Exception ex)
      {
        logger.error("ExtensionsConfiguration.Exception: Unable to read configuration.", ex.getStackTrace());
      }
    return configuration;
  }

}

In above code I am trying to read the "cd_deployer_ext.xml" which is placed inside %TRIDION_HOME%/config and above code was working fine in in 2009.

Sample Format of cd_deployer_ext.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
    <DeployerCustomization Enable="true" Extension=".aspx" FilePath="F:\WWW\GoogleDataFiles\"></DeployerCustomization>
</Configuration>

Here is way how I am trying to read the values from this file

Reading the values: PageDeployer.java Below sample code which I am using to read the values from ExtensionsConfiguration.java

Configuration configData = ExtensionsConfiguration.getInstance();
String extensionFromFile = ConfigurationHelper.getStringValue(configData,"Configuration/DeployerCustomization/Extension", null);

Now extensionFromFile should give me the ".aspx".

Please suggest!!

Thanks.

Daniel Neagu
  • 1,711
  • 11
  • 13
Manoj Singh
  • 7,569
  • 34
  • 119
  • 198
  • Is your error occuring after successfully loading the file, or that it can't load the file? Can you provide a stack trace from the logs please? If the problem is loading the file, then it could be because it needs to be added to the java classpath. – Nickoli Roussakov Nov 14 '12 at 05:02
  • I am not getting any exception, please suggest how to verify that!! – Manoj Singh Nov 14 '12 at 07:29
  • How about simply using regular XML handling to read the file? – Frank van Puffelen Nov 14 '12 at 11:52
  • By looking at the import statements, you are using slf4j for your logging, so I would expect there to be some kind of a properties file specifying logging levels and locations of the log files. So have a look there. Also, look for a file called logback.xml on your Deployer which specifies Tridion's log file locations. – Nickoli Roussakov Nov 14 '12 at 12:55

1 Answers1

5

It looks to me your ExtensionsConfiguration class looks fine, but the problem is with the code on reading the values in 'PageDeployer`.

Your xml file has a node DeployerCustomization with attributes like Name etc which you are trying to read using the XPath and you XPath expression does not seem to be looking for an attribute it is looking for a node under DeployerCustomization.

You need to change the code to the following and try(note the @ for attribute and / in the begining ):

  String extensionFromFile = ConfigurationHelper.getStringValue(configData,
"/Configuration/DeployerCustomization/@Extension", null);

Hope that helps to get the config.

Logging:

You create a new package class which is not configured to log using logback.xml. If you want to configure logging you need to add your package to the logback configuration (something like below as an example).

<logger name="com.tridion.custom.extensions">
  <appender-ref ref="rollingDeployerLog"/>
</logger>

On completely separate note, the API you are using com.tridion.configuration.XMLConfigurationReader seems like not public. I could not find this anywhere in javadoc unless I missed it. However, I would leave that up to you.

Ram G
  • 4,829
  • 1
  • 16
  • 26
  • Thanks @Ram, I will try above changes, however I have some doubt how it was working fine in Tridion 2009 without "@", will check and confirm. Just to update you com.tridion.configuration.XMLConfigurationReader class is the part of cd_core.jar and after decompliling it I can find that it simply reading the file, if you want I can sent the code. – Manoj Singh Nov 19 '12 at 05:07