0

I have a class which connects to a web service and then returns the response. The class is working in a different thread. It is called SoapConnector. There is an interface which notify the caller that the response is ready. It is:

public interface ISoapConnectorObserver {
    public void onSoapRequestFinished(String response);

}

When the response is ready, the onSoapRequestFinished() is called.

I use the SoapConnector for fetching different data. For example CustomerReader for reading the customers from server and ProductReader for reading the products list. How can i change the ISoapConnectorObserver to differentiate the return value from CustomerReader or ProductReader?

public class CustomerReader {
    private observer ISoapConnectorObserver observer;

    public CustomerReader(ISoapConnectorObserver observer) {
        this.observer = observer;
    }
    .
    .
}

public class ProductReader {
    private observer ISoapConnectorObserver observer;

    public ProductReader(ISoapConnectorObserver observer) {
        this.observer = observer;
    }
    .
    .
}

I want to find an elegant way to not to use another helper class, but extending this interface or changing the onSoapRequestFinished(). Thanks

Ehsan Toghian
  • 548
  • 1
  • 6
  • 26
  • You either should only notify the source of the request or include a source parameter like `public void onSoapRequestFinished(object source, String response);` – Fildor Mar 08 '17 at 13:37
  • Possible duplicate of [How do I find the caller of a method using stacktrace or reflection?](http://stackoverflow.com/questions/421280/how-do-i-find-the-caller-of-a-method-using-stacktrace-or-reflection) – ΦXocę 웃 Пepeúpa ツ Mar 08 '17 at 13:39
  • @Fildor can you please write a sample? – Ehsan Toghian Mar 08 '17 at 13:45
  • @ehsantoghian Do you have a link to the API or method? The answer may lie in the parameter passed into the `onSoapRequestFinished()`. Maybe it contains the function that called it. – Developer Mar 08 '17 at 14:09
  • Actually no. Without having the SoapConnector code, that's pretty impossible. Whatever you do, you'll have to keep track of origin of request. – Fildor Mar 08 '17 at 14:39

0 Answers0