Example #1
0
 @GET
 @Path("/{sitemapname: [a-zA-Z_0-9]*}/{pageid: [a-zA-Z_0-9]*}")
 @Produces({MediaType.WILDCARD})
 public SuspendResponse<Response> getPageData(
     @Context HttpHeaders headers,
     @PathParam("sitemapname") String sitemapname,
     @PathParam("pageid") String pageId,
     @QueryParam("type") String type,
     @QueryParam("jsoncallback") @DefaultValue("callback") String callback,
     @HeaderParam(HeaderConfig.X_ATMOSPHERE_TRANSPORT) String atmosphereTransport,
     @Context AtmosphereResource resource) {
   logger.debug(
       "Received HTTP GET request at '{}' for media type '{}'.",
       new String[] {uriInfo.getPath(), type});
   if (atmosphereTransport == null || atmosphereTransport.isEmpty()) {
     String responseType =
         MediaTypeHelper.getResponseMediaType(headers.getAcceptableMediaTypes(), type);
     if (responseType != null) {
       Object responseObject =
           responseType.equals(MediaTypeHelper.APPLICATION_X_JAVASCRIPT)
               ? new JSONWithPadding(
                   getPageBean(sitemapname, pageId, uriInfo.getBaseUriBuilder().build()), callback)
               : getPageBean(sitemapname, pageId, uriInfo.getBaseUriBuilder().build());
       throw new WebApplicationException(Response.ok(responseObject, responseType).build());
     } else {
       throw new WebApplicationException(Response.notAcceptable(null).build());
     }
   }
   GeneralBroadcaster sitemapBroadcaster =
       (GeneralBroadcaster)
           BroadcasterFactory.getDefault()
               .lookup(GeneralBroadcaster.class, resource.getRequest().getPathInfo(), true);
   sitemapBroadcaster.addStateChangeListener(new SitemapStateChangeListener());
   return new SuspendResponse.SuspendResponseBuilder<Response>()
       .scope(SCOPE.REQUEST)
       .resumeOnBroadcast(!ResponseTypeHelper.isStreamingTransport(resource.getRequest()))
       .broadcaster(sitemapBroadcaster)
       .outputComments(true)
       .build();
 }
Example #2
0
 @GET
 @Produces({MediaType.WILDCARD})
 public Response getSitemaps(
     @Context HttpHeaders headers,
     @QueryParam("type") String type,
     @QueryParam("jsoncallback") @DefaultValue("callback") String callback) {
   logger.debug(
       "Received HTTP GET request at '{}' for media type '{}'.",
       new String[] {uriInfo.getPath(), type});
   String responseType =
       MediaTypeHelper.getResponseMediaType(headers.getAcceptableMediaTypes(), type);
   if (responseType != null) {
     Object responseObject =
         responseType.equals(MediaTypeHelper.APPLICATION_X_JAVASCRIPT)
             ? new JSONWithPadding(
                 new SitemapListBean(getSitemapBeans(uriInfo.getAbsolutePathBuilder().build())),
                 callback)
             : new SitemapListBean(getSitemapBeans(uriInfo.getAbsolutePathBuilder().build()));
     return Response.ok(responseObject, responseType).build();
   } else {
     return Response.notAcceptable(null).build();
   }
 }