Announcement Announcement Module
Collapse
No announcement yet.
Getting the proxied bean... Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    You may do:

    Code:
    ((Advised)proxy).getTargetSource().getTarget()
    -Ramnivas

    Comment


    • #3
      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?

      Comment


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

        -Ramnivas

        Comment


        • #5
          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, 10:09 AM. Reason: additional information

          Comment

          Working...
          X