当前位置: 首页>>代码示例>>Java>>正文


Java Response.ResponseBuilder方法代码示例

本文整理汇总了Java中javax.ws.rs.core.Response.ResponseBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java Response.ResponseBuilder方法的具体用法?Java Response.ResponseBuilder怎么用?Java Response.ResponseBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.core.Response的用法示例。


在下文中一共展示了Response.ResponseBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: authenticated

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Response authenticated(UserSessionModel userSession, AuthenticatedClientSessionModel clientSession) {
    ClientSessionCode<AuthenticatedClientSessionModel> accessCode = new ClientSessionCode<>(session, realm, clientSession);

    String service = clientSession.getRedirectUri();
    //TODO validate service

    String code;
    try {
        // Keycloak >3.4 branch: Method getCode was renamed to getOrGenerateCode, CODE_TO_TOKEN was removed
        Method getOrGenerateCode = ClientSessionCode.class.getMethod("getOrGenerateCode");
        code = (String) getOrGenerateCode.invoke(accessCode);
    } catch (ReflectiveOperationException e) {
        // Keycloak <=3.3 branch
        accessCode.setAction(CommonClientSessionModel.Action.CODE_TO_TOKEN.name());
        code = accessCode.getCode();
    }
    KeycloakUriBuilder uriBuilder = KeycloakUriBuilder.fromUri(service);
    uriBuilder.queryParam(TICKET_RESPONSE_PARAM, SERVICE_TICKET_PREFIX + code);

    URI redirectUri = uriBuilder.build();

    Response.ResponseBuilder location = Response.status(302).location(redirectUri);
    return location.build();
}
 
开发者ID:Doccrazy,项目名称:keycloak-protocol-cas,代码行数:26,代码来源:CASLoginProtocol.java

示例2: putConnectorConfig

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@PUT
@Path("/{connector}/config")
public Response putConnectorConfig(final @PathParam("connector") String connector,
                                   final @QueryParam("forward") Boolean forward,
                                   final Map<String, String> connectorConfig) throws Throwable {
    FutureCallback<Herder.Created<ConnectorInfo>> cb = new FutureCallback<>();
    String includedName = connectorConfig.get(ConnectorConfig.NAME_CONFIG);
    if (includedName != null) {
        if (!includedName.equals(connector))
            throw new BadRequestException("Connector name configuration (" + includedName + ") doesn't match connector name in the URL (" + connector + ")");
    } else {
        connectorConfig.put(ConnectorConfig.NAME_CONFIG, connector);
    }

    herder.putConnectorConfig(connector, connectorConfig, true, cb);
    Herder.Created<ConnectorInfo> createdInfo = completeOrForwardRequest(cb, "/connectors/" + connector + "/config",
            "PUT", connectorConfig, new TypeReference<ConnectorInfo>() { }, new CreatedConnectorInfoTranslator(), forward);
    Response.ResponseBuilder response;
    if (createdInfo.created())
        response = Response.created(URI.create("/connectors/" + connector));
    else
        response = Response.ok();
    return response.entity(createdInfo.result()).build();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:25,代码来源:ConnectorsResource.java

示例3: performMatchingServiceHealthCheck

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@GET
public Response performMatchingServiceHealthCheck() {
    final AggregatedMatchingServicesHealthCheckResult result = matchingServiceHealthCheckHandler.forceCheckAllMSAs();

    final Response.ResponseBuilder response = result.isHealthy() ? Response.ok() : Response.serverError();
    response.entity(result);
    return response.build();
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:9,代码来源:MatchingServiceVersionCheckResource.java

示例4: response

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
protected Response.ResponseBuilder response(Response.Status status, Throwable exception) {
    error = exception;

    InvalidConfigException ex = (InvalidConfigException) exception;

    ObjectMapper mapper = new ObjectMapper();
    String message = messageFrom(exception);
    ObjectNode result = mapper.createObjectNode()
            .put("code", status.getStatusCode())
            .put("message", message)
            .put("subjectKey", ex.subjectKey())
            .put("subject", ex.subject())
            .put("configKey", ex.configKey());

    if (ex.getCause() instanceof InvalidFieldException) {
        InvalidFieldException fieldException = (InvalidFieldException) ex.getCause();
        result.put("field", fieldException.field())
                .put("reason", fieldException.reason());
    }

    return Response.status(status).entity(result.toString());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:InvalidConfigExceptionMapper.java

示例5: createResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
public static Response createResponse(Response.Status status, MediaType mediaType, CASServiceResponse serviceResponse) {
    Response.ResponseBuilder builder = Response.status(status)
            .header(HttpHeaders.CONTENT_TYPE, mediaType.withCharset("utf-8"));
    if (MediaType.APPLICATION_JSON_TYPE.equals(mediaType)) {
        return builder.entity(ServiceResponseMarshaller.marshalJson(serviceResponse)).build();
    } else {
        return builder.entity(ServiceResponseMarshaller.marshalXml(serviceResponse)).build();
    }
}
 
开发者ID:Doccrazy,项目名称:keycloak-protocol-cas,代码行数:10,代码来源:ServiceResponseHelper.java

示例6: preflight

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
protected void preflight(String origin, ContainerRequestContext requestContext) throws IOException {
    checkOrigin(requestContext, origin);

    Response.ResponseBuilder builder = Response.ok();
    builder.header(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
    if (allowCredentials)
        builder.header(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    String requestMethods = requestContext.getHeaderString(ACCESS_CONTROL_REQUEST_METHOD);
    if (requestMethods != null) {
        if (allowedMethods != null) {
            requestMethods = this.allowedMethods;
        }
        builder.header(ACCESS_CONTROL_ALLOW_METHODS, requestMethods);
    }
    String allowHeaders = requestContext.getHeaderString(ACCESS_CONTROL_REQUEST_HEADERS);
    if (allowHeaders != null) {
        if (allowedHeaders != null) {
            allowHeaders = this.allowedHeaders;
        }
        builder.header(ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders);
    }
    if (corsMaxAge > -1) {
        builder.header(ACCESS_CONTROL_MAX_AGE, corsMaxAge);
    }
    requestContext.abortWith(builder.build());

}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:28,代码来源:CorsFilter.java

示例7: getTimeMapBuilder

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Create a response builder for a TimeMap response.
 *
 * @param baseUrl the base URL
 * @param req the LDP request
 * @param serializer the serializer to use
 * @return a response builder object
 */
public Response.ResponseBuilder getTimeMapBuilder(final LdpRequest req,
        final IOService serializer, final String baseUrl) {

    final List<MediaType> acceptableTypes = req.getHeaders().getAcceptableMediaTypes();
    final String identifier = getBaseUrl(baseUrl, req) + req.getPath();
    final List<Link> links = getMementoLinks(identifier, resource.getMementos()).collect(toList());

    final Response.ResponseBuilder builder = Response.ok().link(identifier, ORIGINAL + " " + TIMEGATE);
    builder.links(links.toArray(new Link[0])).link(Resource.getIRIString(), "type")
        .link(RDFSource.getIRIString(), "type").header(ALLOW, join(",", GET, HEAD, OPTIONS));

    final RDFSyntax syntax = getSyntax(acceptableTypes, of(APPLICATION_LINK_FORMAT)).orElse(null);
    if (nonNull(syntax)) {
        final IRI profile = ofNullable(getProfile(acceptableTypes, syntax)).orElse(expanded);

        final List<Triple> extraData = getExtraTriples(identifier);
        for (final Link l : links) {
            if (l.getRels().contains(MEMENTO)) {
                extraData.add(rdf.createTriple(rdf.createIRI(identifier), Memento.memento,
                                rdf.createIRI(l.getUri().toString())));
            }
        }

        final StreamingOutput stream = new StreamingOutput() {
            @Override
            public void write(final OutputStream out) throws IOException {
                serializer.write(concat(links.stream().flatMap(linkToTriples), extraData.stream()), out, syntax,
                        profile);
            }
        };

        return builder.type(syntax.mediaType()).entity(stream);
    }

    return builder.type(APPLICATION_LINK_FORMAT)
        .entity(links.stream().map(Link::toString).collect(joining(",\n")) + "\n");
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:46,代码来源:MementoResource.java

示例8: getTimeGateBuilder

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Create a response builder for a TimeGate response.
 *
 * @param req the LDP request
 * @param baseUrl the base URL
 * @return a response builder object
 */
public Response.ResponseBuilder getTimeGateBuilder(final LdpRequest req, final String baseUrl) {
    final String identifier = getBaseUrl(baseUrl, req) + req.getPath();
    return Response.status(FOUND)
        .location(fromUri(identifier + "?version=" + req.getDatetime().getInstant().toEpochMilli()).build())
        .link(identifier, ORIGINAL + " " + TIMEGATE)
        .links(getMementoLinks(identifier, resource.getMementos()).toArray(Link[]::new))
        .header(VARY, ACCEPT_DATETIME);
}
 
开发者ID:trellis-ldp,项目名称:trellis,代码行数:16,代码来源:MementoResource.java

示例9: synchronizeGroups

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Path("sync/groups")
@PUT
public Response synchronizeGroups() {
    Response.ResponseBuilder response;
    try {
        syncService.synchronizeAllGroups();
        response = Response.ok();
    } catch (LDAPException e) {
        log.error("Can't synchronize groups", e);
        response = ServerError.toResponse("LDAP_ERR", e);
    }
    return response.build();
}
 
开发者ID:hlavki,项目名称:g-suite-identity-sync,代码行数:14,代码来源:AdminService.java

示例10: toResponse

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
@Override
public Response toResponse(UnauthorizedException exception) {

    logger.info("{}. Returning {} response.", exception, Response.Status.UNAUTHORIZED);
    logger.debug(StringUtils.EMPTY, exception);

    final Response.ResponseBuilder response = Response.status(Response.Status.UNAUTHORIZED);
    if (exception.getWwwAuthenticateChallenge() != null) {
        response.header(AUTHENTICATION_CHALLENGE_HEADER_NAME, exception.getWwwAuthenticateChallenge());
    }
    response.entity(exception.getMessage()).type("text/plain");
    return response.build();

}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:15,代码来源:UnauthorizedExceptionMapper.java

示例11: noCache

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Edit the response headers to indicating no caching.
 *
 * @param response response
 * @return builder
 */
protected Response.ResponseBuilder noCache(final Response.ResponseBuilder response) {
    final CacheControl cacheControl = new CacheControl();
    cacheControl.setPrivate(true);
    cacheControl.setNoCache(true);
    cacheControl.setNoStore(true);
    return response.cacheControl(cacheControl);
}
 
开发者ID:apache,项目名称:nifi-registry,代码行数:14,代码来源:ApplicationResource.java

示例12: postUpdate

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private Response postUpdate(
    AuthPrincipal authPrincipal, String group, String featureKey,
    Function<Feature, Feature> updater)
    throws AuthenticationException {

  final long start = System.currentTimeMillis();
  grantedGuard(authPrincipal, group);

  final Response.ResponseBuilder rb =
      featureService.loadFeatureByKey(group, featureKey)
          .map(feature -> Response.ok(updater.apply(feature)))
          .orElseGet(this::featureNotFound);

  return headers.enrich(rb, start).build();
}
 
开发者ID:dehora,项目名称:outland,代码行数:16,代码来源:FeatureResource.java

示例13: build

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
/**
 * Build a response given a concrete request. If the request contain an <code>if-modified-since</code> or
 * <code>if-none-match</code> header this will be checked against the entity given to the builder returning
 * a response with status not modified if appropriate.
 */
public Response build(Request req) {
    EntityTag eTag = new EntityTag(Integer.toString(entity.hashCode()));
    Date lastModified = entity instanceof AbstractAuditable ? ((AbstractAuditable) entity).getLastModifiedTime() : Date.from(Instant.now());
    Response.ResponseBuilder notModifiedBuilder = req.evaluatePreconditions(lastModified, eTag);
    if (notModifiedBuilder != null) {
        return notModifiedBuilder.build();
    }

    Map<String, String> parameters = new ConcurrentHashMap<>();
    if (name != null) {
        parameters.put("concept", name);
    }
    if (version != null) {
        parameters.put("v", version);
    }
    MediaType type = getMediaType(parameters, supportsContentTypeParameter);

    Response.ResponseBuilder b = Response.ok(mapper.apply(entity))
            .type(type)
            .tag(eTag)
            .lastModified(lastModified);

    if (maxAge != null) {
        CacheControl cc = new CacheControl();
        cc.setMaxAge(maxAge);
        b.cacheControl(cc).expires(Date.from(Instant.now().plusSeconds(maxAge)));
    }

    return b.build();
}
 
开发者ID:psd2-in-a-box,项目名称:mid-tier,代码行数:36,代码来源:EntityResponseBuilder.java

示例14: ok

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
protected static Response.ResponseBuilder ok(Object obj) {
    return Response.ok(obj);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:4,代码来源:BaseResource.java

示例15: addJsonLinkHeader

import javax.ws.rs.core.Response; //导入方法依赖的package包/类
private Response.ResponseBuilder addJsonLinkHeader(Response.ResponseBuilder rb) {
    return rb.header("Link", Configuration.LINK_HEADER_VALUE);
}
 
开发者ID:Fiware,项目名称:NGSI-LD_Wrapper,代码行数:4,代码来源:EntityResource.java


注:本文中的javax.ws.rs.core.Response.ResponseBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。