Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

Code Block
languagejava
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;


class Main
{
	public static void main(String[] args) {
		Client client = Client.create();

		WebResource webResource = client
				.resource("http://localhost:8080/RESTfulExample/rest/json/metallica/get");

		ClientResponse response = webResource.accept("application/json")
				.get(ClientResponse.class);

	}

}


Client side load balancing

Usage of org.springframework.cloud.client.loadbalancer.LoadBalancerClient allows to choose a service to call so impacts the URL called.


Code Block
languagejava
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.cloud.client.ServiceInstance;
import java.net.URI;

class Main
{
    @Autowired
    private LoadBalancerClient loadBalancerClient;

    void f()
	{
		RestTemplate client ;
        ServiceInstance serviceInstance = loadBalancerClient.choose("user-auth");
        String path = serviceInstance.getUri().toString() + "/oauth/token";
        client.put(path, client);
	}
}

Image Added

Feign

Feign is a declarative web service client which makes writing web service clients easier. Native sample: "RequestLine" annotation indicates the presence of feign web service:

...

Code Block
class MyHttpCall
{
   void execute(String url, String method)
   {
      Client client = ClientBuilder.newClient();
      WebTarget myResource = client.target(url);

      if (method == "GET")
      {
          String response = myResource.request(MediaType.TEXT_PLAIN).get(String.class);
      }
      else if (method == "PUT")
      {
          myResource.request(MediaType.TEXT_PLAIN).put(null);
      }
         
   }

}

  • @Value on constructor or method parameters are not handled
  • For feign and retrofit2.http web services we do not evaluate strings inside annotations
  • Manual creation of feign clients is not supported