vendredi 20 février 2015

How can I inject local variables of a static method inside an abstract class using Spring?

I'm new to Spring and ran into this problem.I tried using @Autowired on the method but it didnt work,on the variables I get the error "The annotation @Autowired is disallowed for this location" from eclipse. I have the required beans created in the xml.


Below is the code,this method is inside an abstract class..



private static HttpResponse rawExecuteReqeust(HttpUriRequest request) throws ClientProtocolException, IOException
{
HttpClient client=new DefaultHttpClient();
ProxyInterface proxyI; //needs to be Injected
User user; // needs to be Injected
System.out.println("About to execute "+request.getMethod()+ " request on "+request.getURI());
if(proxyI.getProxyHost() != null && proxyI.getProxyPort() != 0 )
{
if (user.getProxyUser() != null && user.getProxyPassword() != null)
{
((AbstractHttpClient) client).getCredentialsProvider().setCredentials(new AuthScope(proxyI.getProxyHost(), proxyI.getProxyPort()),new UsernamePasswordCredentials(user.getProxyUser(),user.getProxyPassword()));
}
HttpHost proxy =new HttpHost(proxyI.getProxyHost(), proxyI.getProxyPort(), "http");
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,proxy);
}

HttpResponse response = client.execute(request);
return response;
}

(p.s Im new to stackOverflow and hope I formatted the question properly :) )


Aucun commentaire:

Enregistrer un commentaire