Package javax.ws.rs.core.Response

Examples of javax.ws.rs.core.Response.ResponseBuilder


      rowModel.addCell(
        new CellModel(value.getColumn(), value.getTimestamp(),
              value.getValue()));
    } while (--count > 0);
    model.addRow(rowModel);
    ResponseBuilder response = Response.ok(model);
    response.cacheControl(cacheControl);
    return response.build();
  }
View Full Code Here


      KeyValue value = generator.next();
      if (value == null) {
        LOG.info("generator exhausted");
        return Response.noContent().build();
      }
      ResponseBuilder response = Response.ok(value.getValue());
      response.cacheControl(cacheControl);
      response.header("X-Row", Base64.encode(value.getRow()));
      response.header("X-Column", Base64.encode(value.getColumn()));
      response.header("X-Timestamp", value.getTimestamp());
      return response.build();
    } catch (IllegalStateException e) {
      ScannerResource.delete(id);
      throw new WebApplicationException(Response.Status.GONE);
    }
  }
View Full Code Here

        }
      }
      for (String name: status.getDeadServerNames()) {
        model.addDeadNode(name);
      }
      ResponseBuilder response = Response.ok(model);
      response.cacheControl(cacheControl);
      return response.build();
    } catch (IOException e) {
      throw new WebApplicationException(e,
                  Response.Status.SERVICE_UNAVAILABLE);
    }
  }
View Full Code Here

            } else {
                throw new RuntimeException("Unknown client side exception");
            }
        }
        int status = responseCode.intValue();
        ResponseBuilder currentResponseBuilder = Response.status(status);
       
        for (Map.Entry<String, List<String>> entry : conn.getHeaderFields().entrySet()) {
            if (null == entry.getKey()) {
                continue;
            }
            if (entry.getValue().size() > 0) {
                if (HttpUtils.isDateRelatedHeader(entry.getKey())) {
                    currentResponseBuilder.header(entry.getKey(), entry.getValue().get(0));
                    continue;                   
                }
                for (String val : entry.getValue()) {
                    boolean splitPossible = !(HttpHeaders.SET_COOKIE.equalsIgnoreCase(entry.getKey())
                        && val.toUpperCase().contains(HttpHeaders.EXPIRES.toUpperCase()));
                    String[] values = splitPossible ? val.split(",") : new String[]{val};
                    for (String s : values) {
                        String theValue = s.trim();
                        if (theValue.length() > 0) {
                            currentResponseBuilder.header(entry.getKey(), theValue);
                        }
                    }
                }
            }
        }
        InputStream mStream = null;
        if (inMessage != null) {
            mStream = inMessage.getContent(InputStream.class);
        }
        if (status >= 400) {
            try {
                InputStream errorStream = mStream == null ? conn.getErrorStream() : mStream;
                currentResponseBuilder.entity(errorStream);
            } catch (Exception ex) {
                // nothing we can do really
            }
        } else {
            try {
                InputStream stream = mStream == null ? conn.getInputStream() : mStream;
                currentResponseBuilder.entity(stream);
            } catch (Exception ex) {
                // it may that the successful response has no response body
            }
        }
        ResponseBuilder rb = currentResponseBuilder.clone();
        state.setResponseBuilder(currentResponseBuilder);
        return rb;
    }
View Full Code Here

        /* Write the XML encoding to a writer and return it2 */
        StringWriter sw = new StringWriter();
        try {
            mpl.encode(sw);
            ResponseBuilder rb = Response.ok(sw.toString());
            return rb.build();
        } catch (javax.xml.bind.JAXBException excp) {
            /* Log an error and return an error response */
            logger.log(Level.WARNING, "[MODULES] GET PLUGINS Unable to encode", excp);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
    }
View Full Code Here

                        " with size " + partList.getChecksumMap().size());
                checksumList.putChecksums(partList.getChecksumMap());
            }
        }

        ResponseBuilder rb = Response.ok(checksumList);
        return rb.build();
    }
View Full Code Here

        ModuleManager manager = ModuleManager.getModuleManager();
        Module module = manager.getInstalledModules().get(moduleName);
        if (module == null) {
            /* Log an error and return an error response */
            logger.warning("ModuleManager: unable to locate module " + moduleName);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }

        // For the base URL of assets within a module, use the server URL and
        // point it to the webdav repository
        String hostname = System.getProperty(Constants.WEBSERVER_URL_PROP) + "webdav/content/modules/installed/" + moduleName;

        /* Fetch the module repository, return an error if it does not exist */
        ModuleRepository mr = module.getRepository();
        if (mr == null || mr.getResources() == null || mr.getResources().length == 0) {
            /*
             * If the repository doesn't exist (perhaps from a missing repository.xml
             * file, then create a fallback response with this server as the
             * master.
             */
            logger.info("A repository.xml file does not exist for module: " + moduleName);
            logger.info("Sending this server as fallback: " + hostname);
            ModuleRepository newRepository = new ModuleRepository();
            Repository rep = new Repository();
            rep.url = hostname;
            rep.isServer = true;
            newRepository.setMaster(rep);
            /* Write the XML encoding to a writer and return it */
            StringWriter sw = new StringWriter();
            try {
                /* Formulate the HTTP response and send the string */
                newRepository.encode(sw);
                ResponseBuilder rb = Response.ok(sw.toString());
                return rb.build();
            } catch (javax.xml.bind.JAXBException excp) {
                /* Log an error and return an error response */
                logger.warning("ModuleManager: unable to serialize repository for " + moduleName);
                ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
                return rb.build();
            }
        }
       
        /* Since we potentially edit fields below, make a copy of the repository */
        ModuleRepository newRepository = new ModuleRepository(mr);
       
        /* Replace the master if its string is the special %WL_SERVER% */
        if (newRepository.getMaster() != null && newRepository.getMaster().url.compareTo(ModuleRepository.WL_SERVER) == 0) {
            Repository rep = new Repository();
            rep.url = hostname;
            rep.isServer = true;
            newRepository.setMaster(rep);
        }
       
        /* Replace the mirrors if its string is the special %WL_SERVER% */
        Repository mirrors[] = newRepository.getMirrors();
        if (mirrors != null) {
            for (int i = 0; i < mirrors.length; i++) {
                if (mirrors[i] != null && mirrors[i].url.compareTo(ModuleRepository.WL_SERVER) == 0) {
                    Repository rep = new Repository();
                    rep.url = hostname;
                    rep.isServer = true;
                    mirrors[i] = rep;
                }
            }
            newRepository.setMirrors(mirrors);
        }
       
        /* Write the XML encoding to a writer and return it */
        StringWriter sw = new StringWriter();
        try {
            /* Formulate the HTTP response and send the string */
            newRepository.encode(sw);
            ResponseBuilder rb = Response.ok(sw.toString());
            return rb.build();
        } catch (javax.xml.bind.JAXBException excp) {
            /* Log an error and return an error response */
            logger.warning("ModuleManager: unable to serialize repository for " + moduleName);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();
        }
    }
View Full Code Here

        // all clients, since it is shared in places like webdav URL. Make
        // sure this returns the canonical public URL for the server XXX
        //out.setServerURL(getServerURL());

        try {
            ResponseBuilder rb = Response.ok(out);
            return rb.build();
        } catch (Exception excp) {
            logger.log(Level.WARNING, "Error writing response", excp);
            ResponseBuilder rb = Response.status(Response.Status.BAD_REQUEST);
            return rb.build();           
        }
    }
View Full Code Here

            if (log == null) {
                return Response.status(Response.Status.NOT_FOUND)
                               .entity("No object with id " + id).build();
            }
           
            ResponseBuilder out = Response.ok(new StreamingOutput() {
                public void write(OutputStream out) throws IOException, WebApplicationException {
                    PrintStream ps = new PrintStream(out);
                   
                    ps.println("User: " + log.getCreator());
                    ps.println("Submitted: " +
                            SimpleDateFormat.getDateTimeInstance().format(log.getTimeStamp()));
                    ps.println("Comments:");
                    ps.println(log.getComments());
                    ps.println("---------- Error Report ----------");
                    ps.println(log.getContent());
                }
            });

            if (asAttachment) {
                out.header("Content-Disposition",
                           "attachment; filename=" + log.getId() + ".txt");
            }
            
            return out.build();       
        } catch (ContentRepositoryException ce) {
            throw new WebApplicationException(ce, Response.Status.INTERNAL_SERVER_ERROR);
        } catch (JAXBException je) {
            throw new WebApplicationException(je, Response.Status.INTERNAL_SERVER_ERROR);
        }
View Full Code Here

        ServerName addr = e.getValue();
        model.add(
          new TableRegionModel(tableName, hri.getRegionId(),
            hri.getStartKey(), hri.getEndKey(), addr.getHostAndPort()));
      }
      ResponseBuilder response = Response.ok(model);
      response.cacheControl(cacheControl);
      servlet.getMetrics().incrementSucessfulGetRequests(1);
      return response.build();
    } catch (TableNotFoundException e) {
      servlet.getMetrics().incrementFailedGetRequests(1);
      return Response.status(Response.Status.NOT_FOUND)
        .type(MIMETYPE_TEXT).entity("Not found" + CRLF)
        .build();
View Full Code Here

TOP

Related Classes of javax.ws.rs.core.Response.ResponseBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.