Page tree

Versions Compared

Key

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


Panel

On this page:

Table of Contents

Target audience:

Users of the extension providing Web services calls from Java.

Extension ID

com.castsoftware.java.service

What's new?

See REST service call for Java - 1.0 - Release Notesfor  for more information.

Description

This extension provides support for some web services calls from Java.

Supported REST client libraries

Native
  • java.net.URLConnection
  • java.net.HttpURLConnection
JAX-RS
  • javax.ws.rs.client.ClientBuilder
  • javax.ws.rs.client.Client
  • org.glassfish.jersey.client.JerseyClient
  • javax.ws.rs.client.WebTarget
  • javax.ws.rs.client.Invocation
  • javax.ws.rs.client.Invocation.Builder
  • javax.ws.rs.core.UriBuilder
  • org.jboss.resteasy.client.jaxrs.ResteasyClient
  • org.jboss.resteasy.client.jaxrs.ResteasyWebTarget
  • org.jboss.resteasy.client.ClientRequest
  • com.sun.jersey.api.client.Client
  • com.sun.jersey.api.client.WebResource
Spring
  • org.springframework.web.client.RestTemplate
  • org.springframework.web.util.UriComponentsBuilder
  • org.springframework.web.util.UriComponents
  • org.springframework.web.util.HtmlUtils
  • org.springframework.social.support.URIBuilder
  • org.springframework.web.reactive.function.client.WebClient
Apache
  • org.apache.cxf.jaxrs.client.WebClient
  • org.apache.http.client.HttpClient
  • org.apache.http.impl.client.CloseableHttpClient
  • org.apache.http.impl.nio.client.CloseableHttpAsyncClient
  • org.apache.http.client.utils.URIBuilder
  • org.apache.wink.client.Resource

  • org.apache.wink.client.RestClient
Vert.x
  • io.vertx.core.http.HttpClientRequest
  • io.vertx.ext.web.client.HttpRequest
  • io.vertx.ext.web.client.WebClient
Other
  • org.resthub.web.Client
  • org.springframework.cloud.openfeign.FeignClient
  • org.springframework.cloud.netflix.feign.FeignClient
  • feign.Feign
  • feign.RequestLine
  • retrofit2.http.DELETE

  • retrofit2.http.GET

  • retrofit2.http.PATCH

  • retrofit2.http.POST

  • retrofit2.http.PUT

Function Point, Quality and Sizing support

...

Function Points
(transactions)
Quality and Sizing
(tick)(tick)(error)(error)

...

AIP Core compatibility

This extension is compatible with:

CAST AIP Core release

Supported

8.3.x(tick)(tick)

Supported DBMS servers

This extension is compatible with the following DBMS servers:

CAST AIP releaseCSSOracleMicrosoft
All supported releases(tick)(tick)(tick)(tick)(error)(error)

Prerequisites

(tick)(tick)Installation of any compatible release of CAST AIP Core (see table above)

Dependencies with other extensions

The REST Service Calls for Java extension requires that ≥ 1.2.8-funcrel of the JEE Analyzer is also installed and used in order to ensure the most complete set of results. This dependency with the JEE AnalyzerAnalyzer is not automatically handled when downloading the REST Service Calls for Java extension via CAST Extension Downloader, CAST Server Manager or AIP Console, therefore you must MANUALLY download and install the JEE Analyzer before starting an analysis.

Download and installation instructions

Please see:

...

...

The latest release status of this extension can be seen when downloading it from the CAST Extend server.

Packaging, delivering and analyzing your source code

Package your JEE code as described in JEE - Prepare and deliver the source code - the REST Service Calls for Java extension will be run when you perform the analysis.

What results can you expect?

Features

This extension analyses some web services call analyzes web service calls made from Java code through some classical classic fluent APIs. For example with com.sun.jersey:

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);

	}

}

Native

API analysed:

  • java.net.URLConnection
  • java.net.HttpURLConnection

Jax-RS

API analysed:

  • javax.ws.rs.client.ClientBuilder
  • javax.ws.rs.client.Client
  • org.glassfish.jersey.client.JerseyClient
  • javax.ws.rs.client.WebTarget
  • javax.ws.rs.client.Invocation
  • javax.ws.rs.client.Invocation.Builder
  • javax.ws.rs.core.UriBuilder
  • org.jboss.resteasy.client.jaxrs.ResteasyClient
  • org.jboss.resteasy.client.jaxrs.ResteasyWebTarget
  • org.jboss.resteasy.client.ClientRequest
  • com.sun.jersey.api.client.Client
  • com.sun.jersey.api.client.WebResource

Spring

API analysed:

  • org.springframework.web.client.RestTemplate
  • org.springframework.web.util.UriComponentsBuilder
  • org.springframework.web.util.UriComponents
  • org.springframework.web.util.HtmlUtils
  • org.springframework.social.support.URIBuilder
  • org.springframework.web.reactive.function.client.WebClient

Apache

API analysed:

  • org.apache.cxf.jaxrs.client.WebClient
  • org.apache.http.client.HttpClient
  • org.apache.http.impl.client.CloseableHttpClient
  • org.apache.http.impl.nio.client.CloseableHttpAsyncClient
  • org.apache.http.client.utils.URIBuilder
  • org.apache.wink.client.Resource

  • org.apache.wink.client.RestClient

Various

API analysed:

...

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
languagejava
interface GitHub {
  @RequestLine("GET /repos/{owner}/{repo}/contributors")
  List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo);
}
 
public static class Contributor {
  String login;
  int contributions;
}
 
public class MyApp {
  public static void main(String... args) {
    GitHub github = Feign.builder()
                         .decoder(new GsonDecoder())
                         .target(GitHub.class, "https://api.github.com");
   
    // Fetch and print a list of the contributors to this library.
    List<Contributor> contributors = github.contributors("OpenFeign", "feign");
    for (Contributor contributor : contributors) {
      System.out.println(contributor.login + " (" + contributor.contributions + ")");
    }
  }
}

Image Added

"FeignClient" annotation associated with "RequestMapping" and "GetMapping" annotations indicates the presence of feign web service:

Code Block
languagejava
import java.util.List;
 
@FeignClient(
        name = "${client.name}",
        path= "${client.path}",
        configuration = FeignConfiguration.class
)
public interface ClientConfiguration {
 
    @RequestMapping(method = RequestMethod.POST, value = "/services/clients")
    List<SupplierTransitionDTO> getData(@RequestBody List<String> codes) throws FeignException;
}

Image Added

Code Block
languagejava
@FeignClient(name = "Client", url = "${build.api.url}", path = "/api/v1")
public interface ClientConfiguration {

    @GetMapping("/sites/{site-id}/clients")
    ConsentResponse getConfiguration(
            @PathVariable("site-id") String siteId,
            @RequestParam("types") List<ConfigType> types);
}

Image Added

Retrofit2.http

With Retrofit 2, endpoints are defined inside an interface using special retrofit annotations to encode details about the parameters and request method. Annotations like "GET", "POST", "PUT", "DELETE" and "PATCH", for example:

Code Block
languagejava
import retrofit2.http.GET;

public interface ExampleGetService {
    @GET("getservice.example")
    Single<ExampleApi> getMode();
}

Image Added

Objects

The following objects are displayed in CAST Enlighten:

IconDescription

Delete Resource Service

Get Resource Service

Post Resource Service

Put Resource Service
Image AddedPatch Resource Service

Rules

None.

Limitations

  • When the code uses a custom URL builder, we cannot evaluate the URL.
  • When the standard java API is encapsulated in a custom method where the "http method" (put, get, post, delete) is passed as a parameter, the dynamic evaluation will generally fail.
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 annotations, ${name}where name is a property/yaml variable name are kept as is instead of being expansed
  • Manual creation of feign clients is not supported