Results 1 to 5 of 5

Thread: Getting the proxied bean...

  1. #1

    Default Getting the proxied bean...

    All,

    I have a proxied bean injected into another bean, but the bean doesn't automatically resolve itself into the actual bean.
    Instead I see something like Proxy64 etc.

    What is happening?
    How can I get the actual bean from the Proxy Object?

    --
    Richard Senior

  2. #2
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    You may do:

    Code:
    ((Advised)proxy).getTargetSource().getTarget()
    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  3. #3

    Default Thanks!

    That's great.
    The problem I have now is that when I call methods on my bean, they return null... Is there a special way I have to call the methods on the bean that is returned using the method you suggested?

  4. #4
    Join Date
    Jun 2006
    Location
    SF Bay Area, California
    Posts
    524

    Default

    What is your use case? It is not normal for you to access the underlying bean instead of proxy, so wondering.

    -Ramnivas
    Ramnivas Laddad (Follow me on Twitter)
    AspectJ in Action: Enterprise AOP with Spring Applications (2nd edition). Now available!

  5. #5

    Default

    Here is my code :

    Code:
    		log.info("TESTING_WEBSERVICES");
    		PrintWriter out = response.getWriter();
    		out.println("<html><head><title>Test Webservices</title></head><body><h1>Status of webservices listed below</h1>");
    		Map services = getApplicationContext().getBeansOfType(ECareWebserviceClient.class);		
    		Iterator i = services.entrySet().iterator();
    		ECareWebserviceClient service;
    		while (i.hasNext()) {			
    			long before =System.currentTimeMillis();
    			Object o = ((Entry)i.next()).getValue();
    			if (o instanceof Advised) {
    				service = (ECareWebserviceClient)((Advised)o).getTargetSource().getTarget();				
    			} else {
    				service = (ECareWebserviceClient)o;	
    			}			
    			String endpoint = service.getEndpointUrl();
    			out.println("Name       	: <b>" + service.getClass().getName() + "</b><br/>");
    			out.println("Endpoint   	: " + endpoint + "<br/>");
    			out.println("Status     	: " + getStatus(endpoint) + "<br/>");
    			out.println("ResponseTime   : " + (System.currentTimeMillis() - before) + "<p></p>");
    		}						
    		out.println("</body></html>");
    		out.flush();
    this works great for the beans that aren't proxied by EHCache, but for the one that is proxied I get :

    Name : com.rms.test.SamApiClientImpl
    Endpoint : null
    Status : no protocol: null?wsdl
    ResponseTime : 4546
    Last edited by richard_senior; Nov 19th, 2009 at 10:09 AM. Reason: additional information

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •