예제 #1
0
 private AccessToken createAccessToken(AuthorizationRequest request, boolean isImplicitGrant) {
   Client client = request.getClient();
   long expireDuration = client.getExpireDuration();
   long expires =
       (expireDuration == 0L ? 0L : (System.currentTimeMillis() + (1000 * expireDuration)));
   String refreshToken =
       (client.isUseRefreshTokens() && !isImplicitGrant) ? getTokenValue(true) : null;
   AuthenticatedPrincipal principal = request.getPrincipal();
   AccessToken token =
       new AccessToken(
           getTokenValue(false),
           principal,
           client,
           expires,
           request.getGrantedScopes(),
           refreshToken);
   return accessTokenRepository.save(token);
 }
  public static void main(String[] args) {

    java.net.URI serviceURI = UriBuilder.fromUri("http://localhost:8080/jaxrs").build();

    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    WebResource weatherService = client.resource(serviceURI);

    String weatherResult =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Rain")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);
    String weatherResult2 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Temperature/94043")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);
    String weatherResult3 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("Temperature/12345")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    System.out.println(weatherResult);
    System.out.println(weatherResult2);
    System.out.println(weatherResult3);

    MultivaluedMap formData = new MultivaluedMapImpl();
    formData.add("temperature", "25");
    formData.add("humidity", "15%");
    formData.add("rain", "false");
    formData.add("zipCode", "94043");

    String response =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .type("application/x-www-form-urlencoded")
            .post(String.class, formData);

    System.out.println(response);

    String weatherResult4 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("WeatherData/94043")
            .accept(MediaType.APPLICATION_JSON)
            .get(String.class);

    System.out.println(weatherResult4);

    String weatherResult5 =
        weatherService
            .path("Rest")
            .path("WeatherService")
            .path("WeatherData/94043")
            .accept(MediaType.APPLICATION_XML)
            .get(String.class);

    System.out.println(weatherResult5);
  }