當前位置: 首頁>>代碼示例>>Java>>正文


Java ResponseBuilder類代碼示例

本文整理匯總了Java中javax.ws.rs.core.Response.ResponseBuilder的典型用法代碼示例。如果您正苦於以下問題:Java ResponseBuilder類的具體用法?Java ResponseBuilder怎麽用?Java ResponseBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResponseBuilder類屬於javax.ws.rs.core.Response包,在下文中一共展示了ResponseBuilder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insert

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * Cadastra litersminute
 * 
 * @param User
 * @return Response
 */
@PermitAll
@POST
@Path("/")
@Consumes("application/json")
@Produces("application/json")
public Response insert(LitersMinute litersminute) {
    ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
    builder.expires(new Date());

    Timestamp date = new Timestamp(System.currentTimeMillis());
    litersminute.setDate(date);

    try {
        AirConditioning air = AirConditioningDao.getInstance().getById(litersminute.getAirconditioning().getId());

        if (air.getId().equals(null)) {
            AirConditioningDao.getInstance().insertU(litersminute.getAirconditioning());
        } else {
            litersminute.setAirconditioning(air);
        }

        Long id = LitersMinuteDao.getInstance().insertU(litersminute);
        litersminute.setId(id);

        System.out.println(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(date.getTime()));
        System.out.println(date.getTime());
        builder.status(Response.Status.OK).entity(litersminute);

    } catch (SQLException e) {
        builder.status(Response.Status.INTERNAL_SERVER_ERROR);
    }

    return builder.build();
}
 
開發者ID:mrh3nry,項目名稱:Celebino,代碼行數:41,代碼來源:LitersMinuteController.java

示例2: getAirConditioningById

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * Return all lmin by air
 * 
 * @return Response
 */
@PermitAll
@GET
@Path("/byair/{id}")
@Produces("application/json")
public Response getAirConditioningById(@PathParam("id") Long idAir) {
    ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
    builder.expires(new Date());

    try {
        List<LitersMinute> lmin = LitersMinuteDao.getInstance().getByAirId(idAir);

        if (lmin != null) {
            builder.status(Response.Status.OK);
            builder.entity(lmin);

        } else {
            builder.status(Response.Status.NOT_FOUND);
        }

    } catch (SQLException exception) {
        builder.status(Response.Status.INTERNAL_SERVER_ERROR);
    }

    return builder.build();
}
 
開發者ID:mrh3nry,項目名稱:Celebino,代碼行數:31,代碼來源:LitersMinuteController.java

示例3: getTranslations

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * Returns Translations of a given {@link Locale}
 * @param locale to get the Translation of
 * @param request The HTTP-Request - is injected automatically
 * @return the translation
 */
@GET
public Response getTranslations(@PathParam("locale") final String locale,
        @Context final Request request) {

    final Translator translator = TranslatorManager.getTranslator(LocaleUtil.toLocale(locale));
    if(translator == null) {
        throw new NotFoundException();
    }

    final File file = translator.getFile();
    final Date lastModified = new Date(file.lastModified());

    ResponseBuilder respBuilder = request.evaluatePreconditions(lastModified);
    if(respBuilder == null) {
        respBuilder = Response.ok();
    }

    return respBuilder.lastModified(lastModified).entity(new StreamingOutput() {
        @Override
        public void write(final OutputStream output) throws IOException, WebApplicationException {
            IOUtils.copy(new FileInputStream(file), output);
        }
    }).build();
}
 
開發者ID:XMBomb,項目名稱:InComb,代碼行數:31,代碼來源:TranslationService.java

示例4: getPostResponseBuilder

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * POST用のレスポンスビルダーを作成する.
 * @param ent OEntity
 * @param outputFormat Content-Type
 * @param responseStr レスポンスボディ
 * @param resUriInfo レスポンスのUriInfo
 * @param key レスポンスのエンティティキー
 * @return レスポンスビルダー
 */
protected ResponseBuilder getPostResponseBuilder(
        OEntity ent,
        MediaType outputFormat,
        String responseStr,
        UriInfo resUriInfo,
        String key) {
    ResponseBuilder rb = Response.status(HttpStatus.SC_CREATED).entity(responseStr).type(outputFormat)
            .header(HttpHeaders.LOCATION, resUriInfo.getBaseUri().toASCIIString()
                    + getEntitySetName() + key)
            .header(ODataConstants.Headers.DATA_SERVICE_VERSION, ODataVersion.V2.asString);

    // 応答にETAGを付與
    if (ent instanceof OEntityWrapper) {
        OEntityWrapper oew2 = (OEntityWrapper) ent;
        String etag = oew2.getEtag();
        if (etag != null) {
            rb = rb.header(HttpHeaders.ETAG, "W/\"" + etag + "\"");
        }
    }
    return rb;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:31,代碼來源:AbstractODataResource.java

示例5: get

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON})
public Response get(final @Context UriInfo uriInfo) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    StorageClusterVersionModel model = new StorageClusterVersionModel();
    model.setVersion(servlet.getAdmin().getClusterStatus().getHBaseVersion());
    ResponseBuilder response = Response.ok(model);
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (IOException e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return Response.status(Response.Status.SERVICE_UNAVAILABLE)
      .type(MIMETYPE_TEXT).entity("Unavailable" + CRLF)
      .build();
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:22,代碼來源:StorageClusterVersionResource.java

示例6: insert

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * Cadastrar air
 * 
 * @param AirConditioning
 * @return Response
 */
@PermitAll
@POST
@Path("/")
@Consumes("application/json")
@Produces("application/json")
public Response insert(AirConditioning air) {
    ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
    builder.expires(new Date());

    try {
        Long idAir = (long) AirConditioningDao.getInstance().insertU(air);
        air.setId(idAir);
        builder.status(Response.Status.OK).entity(air);

    } catch (SQLException e) {
        builder.status(Response.Status.INTERNAL_SERVER_ERROR);
    }

    return builder.build();
}
 
開發者ID:mrh3nry,項目名稱:Celebino,代碼行數:27,代碼來源:AirConditioningController.java

示例7: update

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
@PermitAll
@PUT
@Path("/")
@Produces("application/json")
@Consumes("application/json")
public Response update(AirConditioning air) {
    ResponseBuilder builder = Response.status(Response.Status.BAD_REQUEST);
    builder.expires(new Date());

    try {
        AirConditioningDao.getInstance().update(air);
        builder.status(Response.Status.OK).entity(air);

    } catch (SQLException exception) {
        builder.status(Response.Status.INTERNAL_SERVER_ERROR);
    }
    return builder.build();

}
 
開發者ID:mrh3nry,項目名稱:Celebino,代碼行數:20,代碼來源:AirConditioningController.java

示例8: get

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
@GET
@Produces({MIMETYPE_TEXT, MIMETYPE_XML, MIMETYPE_JSON, MIMETYPE_PROTOBUF,
  MIMETYPE_PROTOBUF_IETF})
public Response get(final @Context UriInfo uriInfo) {
  if (LOG.isDebugEnabled()) {
    LOG.debug("GET " + uriInfo.getAbsolutePath());
  }
  servlet.getMetrics().incrementRequests(1);
  try {
    ResponseBuilder response = Response.ok(getTableList());
    response.cacheControl(cacheControl);
    servlet.getMetrics().incrementSucessfulGetRequests(1);
    return response.build();
  } catch (Exception e) {
    servlet.getMetrics().incrementFailedGetRequests(1);
    return processException(e);
  }
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:19,代碼來源:RootResource.java

示例9: StringBuilder

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * LocationヘッダのURLのフラグメントにerror_descriptionが存在しない場合チェックがtrueを返すこと.
 * @throws UnsupportedEncodingException URLのエラー
 */
@Test
public void LocationヘッダのURLのフラグメントにerror_descriptionが存在しない場合チェックがtrueを返すこと() throws UnsupportedEncodingException {
    ResponseBuilder rb = Response.status(Status.FOUND).type(MediaType.APPLICATION_JSON_TYPE);
    StringBuilder sbuf = new StringBuilder(UrlUtils.cellRoot("authz") + "#" + OAuth2Helper.Key.ERROR + "=");
    sbuf.append(URLEncoder.encode("Server Connection Error.", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.STATE + "=");
    sbuf.append(URLEncoder.encode("0000000111", "utf-8"));
    sbuf.append("&" + OAuth2Helper.Key.CODE + "=");
    sbuf.append(URLEncoder.encode("PR503-SV-0002", "utf-8"));
    rb.header(HttpHeaders.LOCATION, sbuf.toString());

    Response res = rb.entity("").build();
    AuthzEndPointResourceMock authz = new AuthzEndPointResourceMock(null, null);
    assertTrue(authz.isSuccessAuthorization(res));
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:20,代碼來源:AuthzTest.java

示例10: createFolderPost

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * @param stagingUuid
 * @param parentFolder May or may not be present. This folder must already
 *            exist.
 * @param folder Mandatory
 * @return
 */
@Override
public Response createFolderPost(String stagingUuid, String parentFolder, GenericFileBean folder)
{
    final StagingFile stagingFile = getStagingFile(stagingUuid);
    ensureFileExists(stagingFile, parentFolder);

    final String filename = folder.getFilename();
    final String newPath = PathUtils.filePath(parentFolder, filename);

    boolean exists = fileSystemService.fileExists(stagingFile, newPath);
    fileSystemService.mkdir(stagingFile, newPath);

    // was: .entity(convertFile(stagingFile, newPath, false))
    ResponseBuilder resp = Response.status(exists ? Status.OK : Status.CREATED);
    if( !exists )
    {
        resp = resp.location(itemLinkService.getFileDirURI(stagingFile, URLUtils.urlEncode(newPath, false)));
    }
    return resp.build();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:28,代碼來源:FileResourceImpl.java

示例11: headFile

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
@Override
public Response headFile(HttpHeaders headers, String uuid, int version, String path)
{
    ItemId itemId = new ItemId(uuid, version);
    checkViewItem(itemId);

    ItemFile itemFile = itemFileService.getItemFile(itemId, null);
    ResponseBuilder builder = makeBlobHeaders(itemFile, path);

    String contentType = mimeService.getMimeTypeForFilename(path);
    builder.type(contentType);

    if( !fileSystemService.fileExists(itemFile, path) )
    {
        return Response.status(Status.NOT_FOUND).build();
    }
    return builder.build();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:19,代碼來源:ItemResourceImpl.java

示例12: toResponse

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
@Override
public Response toResponse(DefaultOptionsMethodException arg0)
{
    final ResponseBuilder response = Response.ok();
    response.header("Access-Control-Allow-Origin", "*");
    response.header("Access-Control-Allow-Methods", ALL_METHODS);
    response.header("Allow", ALL_METHODS);
    response.header("Access-Control-Allow-Headers", "X-Authorization, Content-Type");
    response.header("Access-Control-Max-Age", TimeUnit.DAYS.toSeconds(1));
    response.header("Access-Control-Expose-Headers", "Location");
    return response.build();
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:13,代碼來源:DefaultOptionsExceptionMapper.java

示例13: redirectToHome

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * Redirect to main home page.
 */
protected ResponseBuilder redirectToHome() throws URISyntaxException {
    final String user = securityHelper.getLogin();
    if (isAnonymous(user)) {
        // We know nothing about the user
        return redirectToUrl(configuration.get("redirect.external.home"));
    }

    // Guess the company of this user
    if (companyResource.isUserInternalCommpany()) {
        // Internal user, redirect to the default URL of corporate user
        return redirectToUrl(configuration.get("redirect.internal.home"));
    }

    // Not internal user, redirect to the other home page
    return redirectToUrl(configuration.get("redirect.external.home"));

}
 
開發者ID:ligoj,項目名稱:plugin-redirect,代碼行數:21,代碼來源:RedirectResource.java

示例14: createMessage

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
/**
 * 受信/送信メッセージEntityを作成する.
 * @param uriInfo URL情報
 * @param reader リクエストボディ
 * @return response情報
 */
protected Response createMessage(UriInfo uriInfo,
        Reader reader) {

    // response用URLに__ctlを追加する
    UriInfo resUriInfo = PersoniumCoreUtils.createUriInfo(uriInfo, 2, "__ctl");

    // Entityの作成を Producerに依頼
    OEntityWrapper oew = getOEntityWrapper(reader, odataResource, CtlSchema.getEdmDataServicesForMessage().build());
    EntityResponse res = getOdataProducer().createEntity(getEntitySetName(), oew);

    // レスポンスボディを生成する
    OEntity ent = res.getEntity();
    MediaType outputFormat = MediaType.APPLICATION_JSON_TYPE;
    List<MediaType> contentTypes = new ArrayList<MediaType>();
    contentTypes.add(MediaType.APPLICATION_JSON_TYPE);
    String key = AbstractODataResource.replaceDummyKeyToNull(ent.getEntityKey().toKeyString());
    String responseStr = renderEntityResponse(resUriInfo, res, "json", contentTypes);

    // 製禦コードのエスケープ処理
    responseStr = escapeResponsebody(responseStr);

    ResponseBuilder rb = getPostResponseBuilder(ent, outputFormat, responseStr, resUriInfo, key);
    return rb.build();
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:31,代碼來源:MessageODataResource.java

示例15: putForUpdate

import javax.ws.rs.core.Response.ResponseBuilder; //導入依賴的package包/類
@Override
public ResponseBuilder putForUpdate(final String contentType, final InputStream inputStream, String etag) {
    // ロック
    Lock lock = this.lock();
    try {
        // 更新には、更新対象のDavNodeが存在するため、更新対象のDavNodeをリロードして存在確認する。
        // 更新対象のDavNodeが存在しない場合:
        // ・更新対象の親DavNodeが存在しない場合:親ごと消えているため404を返卻
        // ・更新対象の親DavNodeが存在する場合:他のリクエストによって削除されたたため、作成処理を実行
        // 更新対象のDavNodeが存在する場合:更新処理を実行
        this.load();
        if (this.metaFile == null) {
            this.parent.load();
            if (this.parent.metaFile == null) {
                throw getNotFoundException().params(this.parent.getUrl());
            }
            return this.doPutForCreate(contentType, inputStream);
        }
        return this.doPutForUpdate(contentType, inputStream, etag);
    } finally {
        // ロックを開放する
        lock.release();
        log.debug("unlock2");
    }
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:26,代碼來源:DavCmpFsImpl.java


注:本文中的javax.ws.rs.core.Response.ResponseBuilder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。