cancel
Showing results for 
Search instead for 
Did you mean: 

unable to access logon.properties path

Former Member
0 Kudos

package my.net.electcoms.model;
import java.util.*;
import java.io.*;
public class OrderedProperties extends java.util.Properties {
  ArrayList orderedKeys = new ArrayList();
  public OrderedProperties() {
    super();
  }
  public OrderedProperties(java.util.Properties defaults) {
    super(defaults);
  }
  public synchronized Iterator getKeysIterator() {
    return orderedKeys.iterator();
  }
  public static OrderedProperties load(String name)
                                  throws IOException {
    OrderedProperties props = null;
    java.io.InputStream is =OrderedProperties.class.getResourceAsStream(name);    
    if ( is != null ) {
      props = new OrderedProperties();
      props.load(is);
      return props;
    } else {
      if ( ! name.startsWith("/") ) {
        return load("/" + name);
      } else {
        throw new IOException("Properties could not be loaded.");
      }
    }
  }
  public synchronized Object put(Object key, Object value) {
    Object obj = super.put(key, value);
    orderedKeys.add(key);
    return obj;
  }
  public synchronized Object remove(Object key) {
    Object obj = super.remove(key);
    orderedKeys.remove(key);
    return obj;
  }
}


public class JCOConnection {
	
	private String connectionPool = "ElectcomsPool";
	private JCO.Repository mRepository = null;

	public JCOConnection(LogOnInfo logOnInfo){
		JCO.Pool pool = JCO.getClientPoolManager().getPool(connectionPool);
		if (pool == null) {
			System.out.println("createPool");
			//OrderedProperties logonProperties;
			try {
			
				
				logonProperties = OrderedProperties.load("/logon.properties");
				 JCO.addClientPool(connectionPool,5,logonProperties);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.err.println("logon:" +e);
			}
		       
			
		}
		mRepository = new JCO.Repository("ElectcomsRepository", connectionPool);
		System.out.println("mRepository " + mRepository);
	}


i get the sample code from the sdn sap, when i run the sample it works well,

but if i want to get the absolute path instead of "/" context

for instance c:
logon.properties or /WEB-INF/logon.properties in tomcat how i going to do this

logon.properties

jco.client.client=100

jco.client.user=cpic_sms

jco.client.passwd=exxx

jco.client.language=EN

jco.client.ashost=emi-sap

jco.client.sysnr=00

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Have a look at the ServletContext object. This object has a method getRealPath() hat allows to find out the exact path of your application. So, if you want to get the path for WEB-INF/logon.properties, try something like this:


String filename = getServletContext().getRealPath("/") + "WEB-INF/logon.properties";

If you don't work in a servlet context, it is also possible to access files with


this.getClass().getClassLoader().getResourceAsStream(
				"my/package/name/some.file");

Best regards,

Frank

former_member182294
Active Contributor
0 Kudos

Hi,

You can do this by creating a FileInputStream with absolute path of the property file. The only thing you need to do is, you need to override the <b>load</b> with InputStream.

public void load(InputStream inputS)

{

orderProperties.load(inputS);

}

//Create FileInputStream

FileInputStream fileIn = new FileInputStream("c:
logon.properties ");

//call your custom method..

obj.load(fileIn);

If you keep files under Web-Inf, tomcat automatically identifies the .properties. You need not to create FileInputStream for this case.

Regards

Abhilash

Regards

Abhilash

Former Member
0 Kudos

public JCOConnection(LogOnInfo logOnInfo){
		JCO.Pool pool = JCO.getClientPoolManager().getPool(connectionPool);
		if (pool == null) {
			System.out.println("createPool");
			OrderedProperties logonProperties;
			try {
				
                FileInputStream fileIn = new FileInputStream("c:\logon.properties");
	
       //>>>previous> logonProperties = OrderedProperties.load("/logon.properties");
				
	
      //error here			 	

logonProperties=OrderedProperties.load(fileIn);
				
	JCO.addClientPool(connectionPool,5,logonProperties);
				
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				System.err.println("logon:" +e);
			}
		       
		
		}
		mRepository = new JCO.Repository("ElectcomsRepository", connectionPool);
		System.out.println("mRepository " + mRepository);
	}

i dun understand your obj.load(fileIn);

your load method is void , instead i need to have a Properties to put it in

addClient(String,int,Properties);

Message was edited by:

yzme yzme

Message was edited by:

yzme yzme

former_member182294
Active Contributor
0 Kudos

Hi,

Replace your code with the following code.

// java.io.InputStream is =OrderedProperties.class.getResourceAsStream(name);

java.io.InputStream is =new FileInputStream(name);

Regards

Abhilash