I am trying to write code to invoke external services using java Httpurlconnection and noticed code is getting duplicated , but I am confused now whether to duplicate code or use lots of if-else block and write everything in single place.
Following are scenarios or type of services needs to be invoked - 1. Post/put/get Rest service with basic authentication over http protocol 2. Post/put/get Rest service with basic authentication over Https protocol 3. Post/put/get services with different oauth authentication options, here one more call to get token is required. 4. Soap services with different authentication method.
The response processing logic also differs for different type of services.
As of now I have written separate methods for each of these, but this is not reusable as it's tightly coupled with type of service.
Can anyone suggests better design approach for this?
Aucun commentaire:
Enregistrer un commentaire