Esempio n. 1
0
 private Response sendAuthorizationCodeResponse(AuthorizationRequest authReq) {
   String uri = authReq.getRedirectUri();
   String authorizationCode = getAuthorizationCodeValue();
   authReq.setAuthorizationCode(authorizationCode);
   authorizationRequestRepository.save(authReq);
   uri = uri + appendQueryMark(uri) + "code=" + authorizationCode + appendStateParameter(authReq);
   return Response.seeOther(UriBuilder.fromUri(uri).build())
       .cacheControl(cacheControlNoStore())
       .header("Pragma", "no-cache")
       .build();
 }
Esempio n. 2
0
 private Response sendImplicitGrantResponse(
     AuthorizationRequest authReq, AccessToken accessToken) {
   String uri = authReq.getRedirectUri();
   String fragment =
       String.format(
               "access_token=%s&token_type=bearer&expires_in=%s&scope=%s",
               accessToken.getToken(),
               accessToken.getExpiresIn(),
               StringUtils.join(authReq.getGrantedScopes(), ','))
           + appendStateParameter(authReq);
   if (authReq.getClient().isIncludePrincipal()) {
     fragment += String.format("&principal=%s", authReq.getPrincipal().getDisplayName());
   }
   return Response.seeOther(UriBuilder.fromUri(uri).fragment(fragment).build())
       .cacheControl(cacheControlNoStore())
       .header("Pragma", "no-cache")
       .build();
 }
  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);
  }
Esempio n. 4
0
 public UriBuilder buildUri(String url) {
   return UriBuilder.fromUri(url.startsWith("http:") ? url : getUrl(url));
 }