Exemplo n.º 1
0
  @GET
  @Path("/all")
  @AnonymousAllowed
  public Response getLinks(@QueryParam("gadgetId") Long gadgetId) {
    final ApplicationUser applicationUser = authenticationContext.getUser();
    final User user = applicationUser.getDirectoryUser();

    if (this.justStarted) {
      Map<String, String> userPrefs =
          portletConfigurationManager.getByPortletId(gadgetId).getUserPrefs();
      // TODO: pass in the name of used UserPref as ajax parameter
      String allLinks = userPrefs.get("allLinks");
      if (customlinks.isEmpty() && allLinks != null && allLinks != "") userPrefProcess(allLinks);

      this.justStarted = false;
    }

    if (customlinks.isEmpty()) {
      CacheControl cc = new CacheControl();
      cc.setNoCache(true);
      return Response.ok(new Warning()).cacheControl(cc).build();
    }
    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    return Response.ok(customlinks).cacheControl(cc).build();
  }
Exemplo n.º 2
0
  public static Response generateStreamingImageResponse(
      final BufferedImage image, final MIMEImageFormat format) {

    if (image == null) {
      LOG.warn("response image is null");
    }

    StreamingOutput streamingOutput =
        new StreamingOutput() {
          public void write(OutputStream outStream) {
            try {
              long t0 = System.currentTimeMillis();
              ImageIO.write(image, format.type, outStream);
              long t1 = System.currentTimeMillis();
              LOG.debug("wrote image in {}msec", (int) (t1 - t0));
            } catch (Exception e) {
              LOG.error("exception while preparing image : {}", e.getMessage());
              throw new WebApplicationException(e);
            }
          }
        };

    CacheControl cc = new CacheControl();
    cc.setMaxAge(3600);
    cc.setNoCache(false);
    return Response.ok(streamingOutput).type(format.toString()).cacheControl(cc).build();
  }
Exemplo n.º 3
0
 /**
  * Edit the response headers to indicating no caching.
  *
  * @param response response
  * @return builder
  */
 protected ResponseBuilder noCache(final ResponseBuilder response) {
   final CacheControl cacheControl = new CacheControl();
   cacheControl.setPrivate(true);
   cacheControl.setNoCache(true);
   cacheControl.setNoStore(true);
   return response.cacheControl(cacheControl);
 }
Exemplo n.º 4
0
  private static Response generateStreamingGeotiffResponse(final GridCoverage2D coverage) {

    StreamingOutput streamingOutput =
        new StreamingOutput() {
          public void write(OutputStream outStream) {
            try {
              long t0 = System.currentTimeMillis();
              GeoTiffWriteParams wp = new GeoTiffWriteParams();
              wp.setCompressionMode(GeoTiffWriteParams.MODE_EXPLICIT);
              wp.setCompressionType("LZW");
              ParameterValueGroup params = new GeoTiffFormat().getWriteParameters();
              params
                  .parameter(AbstractGridFormat.GEOTOOLS_WRITE_PARAMS.getName().toString())
                  .setValue(wp);
              new GeoTiffWriter(outStream)
                  .write(
                      coverage,
                      (GeneralParameterValue[])
                          params.values().toArray(new GeneralParameterValue[1]));
              // new GeoTiffWriter(outStream).write(coverage, null); //wasn't this line writing
              // twice and trashing compressed version?
              long t1 = System.currentTimeMillis();
              LOG.debug("wrote geotiff in {}msec", t1 - t0);
            } catch (Exception e) {
              LOG.error("exception while preparing geotiff : {}", e.getMessage());
              throw new WebApplicationException(e);
            }
          }
        };

    CacheControl cc = new CacheControl();
    cc.setMaxAge(3600);
    cc.setNoCache(false);
    return Response.ok(streamingOutput).type("image/geotiff").cacheControl(cc).build();
  }
 @Test
 public void testMultipleNoCacheFields() {
   CacheControl cc = new CacheControl();
   cc.setNoCache(true);
   cc.getNoCacheFields().add("c");
   cc.getNoCacheFields().add("d");
   assertTrue(cc.toString().contains("no-cache=\"c,d\""));
 }
Exemplo n.º 6
0
  private Response.ResponseBuilder getNoCacheResponseBuilder(Response.Status status) {
    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    cc.setMaxAge(-1);
    cc.setMustRevalidate(true);

    return Response.status(status).cacheControl(cc);
  }
Exemplo n.º 7
0
 @GET
 @Path("/validate")
 public Response validateConfig() {
   // TODO: manipulate changed userPrefs here
   CacheControl cc = new CacheControl();
   cc.setNoCache(true);
   return Response.ok("No input validation errors found.").cacheControl(cc).build();
 }
 private Response response(String redirectUri, boolean asRequest)
     throws ProcessingException, ConfigurationException, IOException {
   URI uri = generateURI(redirectUri, asRequest);
   if (logger.isDebugEnabled()) logger.trace("redirect-binding uri: " + uri.toString());
   CacheControl cacheControl = new CacheControl();
   cacheControl.setNoCache(true);
   return Response.status(302)
       .location(uri)
       .header("Pragma", "no-cache")
       .header("Cache-Control", "no-cache, no-store")
       .build();
 }
Exemplo n.º 9
0
 /**
  * Builds the xml response.
  *
  * @param currentFolder The current folder.
  * @param language The language.
  * @param host The server address on which the gadget is deployed.
  * @return the response
  * @throws Exception the exception
  */
 public Response buildXMLResponse(String currentFolder, String language, String host)
     throws Exception {
   List<ApplicationCategory> applicationCategories = getGadgetCategories();
   Element rootElement = createRootElement(currentFolder, applicationCategories, language, host);
   Document document = rootElement.getOwnerDocument();
   CacheControl cacheControl = new CacheControl();
   cacheControl.setNoCache(true);
   cacheControl.setNoStore(true);
   DateFormat dateFormat = new SimpleDateFormat(IF_MODIFIED_SINCE_DATE_FORMAT);
   return Response.ok(new DOMSource(document), MediaType.TEXT_XML)
       .cacheControl(cacheControl)
       .header(LAST_MODIFIED_PROPERTY, dateFormat.format(new Date()))
       .build();
 }
Exemplo n.º 10
0
  /**
   * Checks permission of the currently logged-in user on any test by the given test Id. The input
   * parameters will be in the URL of the test.
   *
   * @param username The given user's Id, or the currently logged-in user.
   * @param testid The given test Id on which the permission is checked.
   * @param type The test type: _private_, _public_ or _shared_.
   * @return The JSON data value will be returned.
   * @throws Exception
   * @anchor EStudyApplication.checkPermission @LevelAPI Experimental
   */
  @GET
  @RolesAllowed("users")
  @Path("/checkPermission/{username}/{testid}/{type}/")
  public Response checkPermission(
      @PathParam("username") String username,
      @PathParam("testid") String calendarId,
      @PathParam("type") String type)
      throws Exception {
    JSONData data = new JSONData();
    CacheControl cacheControl = new CacheControl();
    cacheControl.setNoCache(true);
    cacheControl.setNoStore(true);

    return Response.ok(data, MediaType.APPLICATION_JSON).cacheControl(cacheControl).build();
  }
Exemplo n.º 11
0
 @POST
 @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
 public Response createVersion(
     @FormParam("label") String label,
     @FormParam("url") String url,
     @FormParam("text") String text) {
   // if there is no duplicate, the new link will add to the link collections and a response will
   // be sent back
   if (!duplicateCheck(label)) {
     CustomlinksResourceModel.Link reply =
         new CustomlinksResourceModel.Link(getNextLinkNum(), label, url, text);
     customlinks.add(reply);
     // TODO: add new link to UP_allLinks as well, this is now be done in jQuery
     CacheControl cc = new CacheControl();
     cc.setNoCache(true);
     return Response.ok(reply).cacheControl(cc).build();
   }
   // if there is duplicate, 204 will be sent and no other response
   else {
     CacheControl cc = new CacheControl();
     cc.setNoCache(true);
     return Response.status(204).cacheControl(cc).build();
   }
 }
 private void setHttpHeaders(Exchange exchange, Response.ResponseBuilder responseBuilder) {
   final String contentType = (String) exchange.getIn().getHeader(Exchange.CONTENT_TYPE);
   if (contentType != null) {
     responseBuilder.header(HttpHeaders.CONTENT_TYPE, contentType);
   }
   final String fileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME);
   if (fileName != null) {
     responseBuilder.header(
         HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + fileName + "\"");
   }
   final Boolean cache =
       exchange.getIn().getHeader(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.class);
   if (cache == null || cache) {
     final CacheControl cacheControl = new CacheControl();
     cacheControl.setNoCache(true);
     responseBuilder.cacheControl(cacheControl);
   }
 }
Exemplo n.º 13
0
  @DELETE
  @Path("/{value}")
  public Response delete(@PathParam("value") final String value) {
    // TODO: should use this for deleting items from restful table
    int v = Integer.valueOf(value);
    boolean flag = false;
    for (CustomlinksResourceModel.Link link : customlinks)
      if (link.getLinkNum() == v) {
        customlinks.remove(link);
        flag = true;
        break;
      }
    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    if (flag) return Response.ok(customlinks).cacheControl(cc).build();

    return Response.status(204).cacheControl(cc).build();
  }
Exemplo n.º 14
0
  @POST
  @Path("/update")
  // TODO: modify data consumed later
  public Response update(
      @FormParam("value") String value,
      @FormParam("label") String label,
      @FormParam("url") String url,
      @FormParam("text") String text) {
    boolean flag = false;
    for (CustomlinksResourceModel.Link link : customlinks)
      if (link.getLinkNum() == Integer.valueOf(value)) {
        link.setLabel(label);
        link.setUrl(url);
        link.setText(text);
        flag = true;
      }

    CacheControl cc = new CacheControl();
    cc.setNoCache(true);
    if (flag) return Response.ok(customlinks).cacheControl(cc).build();

    return Response.status(204).cacheControl(cc).build();
  }
Exemplo n.º 15
0
 static {
   noCache.setNoCache(true);
 }
Exemplo n.º 16
0
 static {
   RuntimeDelegate.setInstance(new RuntimeDelegateImpl());
   cacheControl = new CacheControl();
   cacheControl.setNoCache(true);
   cacheControl.setNoStore(true);
 }
 static {
   cacheControl = new CacheControl();
   cacheControl.setNoCache(true);
   cacheControl.setNoTransform(false);
 }
 @Test
 public void testNoCacheDisabled() {
   CacheControl cc = new CacheControl();
   cc.setNoCache(false);
   assertEquals("no-transform", cc.toString());
 }
Exemplo n.º 19
0
 static {
   cc.setNoCache(true);
   cc.setNoStore(true);
 }