I have set up a 'secure' HttpInvoker invoked service call that works fine. It is as per pages 586-588 of the Pro Spring book. My problem with it is that the password is in a config file (actually it will be a resource in a jar but that's not a secure place for it to be either). I want the user to enter the password. I'm new to Spring and have been battling with this problem here (http://www.strandz.org/mvnforum/mvnf...read?thread=28). Basically the point that I've reached is needing to code the bean definition file directly - that way the password can be set at runtime. Is there any other way? This is where I am trying to replicate the bean as code:
I find myself wishing that as well as there being a PropertiesBeanDefinitionReader and an XmlBeanDefinitionReader, there was also an ObjectGraphDefinitionReader. I would like to be able to construct the beanFactory like this:Code:public void invoke() { HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean(); properties = PropertyUtils.getProperties( PROPS); String serverName = PropertyUtils.getProperty( "serverName", properties); String httpPort = PropertyUtils.getProperty( "httpPort", properties); String contextPath = PropertyUtils.getProperty( "contextPath", properties); proxy.setServiceUrl( "http://" + serverName + ":" + httpPort + contextPath + "/httpinvoker/rosterServiceSecure"); proxy.setServiceInterface( example.spring.RosterService.class); HttpInvokerRequestExecutor httpInvokerRequestExecutor = obtainHttpInvokerRequestExecutor(); proxy.setHttpInvokerRequestExecutor( httpInvokerRequestExecutor); //What to do now? When everything was in the bean I could just: //RosterService rosterService = (RosterService)beanFactory.getBean( "rosterServiceSecure"); //String roster = rosterService.getRoster( MonthInYear.JULY, 2006); //But there is no beanFactory, just an object graph of what is in a bean } private HttpInvokerRequestExecutor obtainHttpInvokerRequestExecutor() { CommonsHttpInvokerRequestExecutor result = new CommonsHttpInvokerRequestExecutor(); result.setHttpClient( obtainHttpClient()); return result; } private HttpClient obtainHttpClient() { HttpClient result = null; HttpClientFactoryBean resultBean = new HttpClientFactoryBean(); resultBean.setUsername( PropertyUtils.getProperty( "userName", properties)); resultBean.setPassword( PropertyUtils.getProperty( "password", properties)); try { result = (HttpClient)resultBean.getObject(); } catch(Exception e) { Err.error( e); } return result; }
I imagine that this all seems like a bit of a descent into madness from a Spring user's point of view, which is why I'm here. Am I right in thinking that there is no way to dynamically 'get at' the bean before it starts to realise itself? Another way of putting this: "Am I right in thinking that Spring is only to be used for design-time configuration"? How should I really be going about solving this problem?Code:ListableBeanFactory beanFactory = new ObjectGraphApplicationContext( proxy);
Any help appreciated - Chris Murphy


Reply With Quote