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


Java StatusType.getReasonPhrase方法代碼示例

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


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

示例1: toResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
public Response toResponse(@NonNull Exception exception) {
	ResponseBuilder builder;
	StatusType statusInfo;
	if (exception instanceof WebApplicationException) {
		Response response = ((WebApplicationException) exception).getResponse();
		builder = Response.fromResponse(response);
		statusInfo = response.getStatusInfo();
	} else {
		builder = Response.serverError();
		statusInfo = Status.INTERNAL_SERVER_ERROR;
	}

	SimpleExceptionJson simpleExceptionJson = new SimpleExceptionJson(statusInfo.getReasonPhrase(),
			statusInfo.getStatusCode(), exception.getMessage());
	builder.entity(simpleExceptionJson);
	builder.type("application/problem+json");

	if (statusInfo.getFamily() == Family.CLIENT_ERROR) {
		log.debug("Got client Exception", exception);
	} else {
		log.error("Sending error to client", exception);
	}

	return builder.build();
}
 
開發者ID:Mercateo,項目名稱:rest-jersey-utils,代碼行數:27,代碼來源:RFCExceptionMapper.java

示例2: httpErrorContent

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
 * Creates an ErrorContent for a HTTP {@link ErrorSource#CLIENT_ERROR client}- or
 * {@link ErrorSource#SERVER_ERROR server} error.
 *
 * @param position the content position
 * @param response the HTTP response. This must either by a client-error response or a server-error response.
 * @param startedTs the timestamp when fetching the content has started.
 * @return ErrorContent
 * @throws IllegalArgumentException if the response is not a client- or server error response.
 */
public static ErrorContent httpErrorContent(final String source,
                                            final Position position,
                                            final Response response,
                                            final long startedTs) {
    final StatusType statusInfo = response.getStatusInfo();
    final Family family = statusInfo.getFamily();

    checkArgument(HTTP_ERRORS.contains(family),
            "Response is not a HTTP client or server error");

    final ErrorSource errorSource = family == CLIENT_ERROR
            ? ErrorSource.CLIENT_ERROR
            : ErrorSource.SERVER_ERROR;

    return new ErrorContent(source, position, statusInfo.getReasonPhrase(), errorSource, startedTs);
}
 
開發者ID:otto-de,項目名稱:rx-composer,代碼行數:27,代碼來源:ErrorContent.java

示例3: status

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
static void status(final StatusType statusInfo, final Family expectedFamily,
                   final Status... expectedStatuses) {
    requireNonNull(statusInfo, "null statusInfo");
    final Family actualFamily = statusInfo.getFamily();
    final int statusCode = statusInfo.getStatusCode();
    final String reasonPhrase = statusInfo.getReasonPhrase();
    logger.debug("-> response.status: {} {}", statusCode, reasonPhrase);
    if (expectedFamily != null) {
        assertEquals(actualFamily, expectedFamily);
    }
    if (expectedStatuses != null && expectedStatuses.length > 0) {
        assertTrue(
                Stream.of(expectedStatuses).map(Status::getStatusCode)
                .filter(v -> v == statusCode)
                .findAny()
                .isPresent()
        );
    }
}
 
開發者ID:jinahya,項目名稱:kt-ucloud-storage-client,代碼行數:20,代碼來源:StorageClientWsRsITs.java

示例4: insertAppointment

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public URI insertAppointment(AppointmentType resource) {
    Response response = client.target(connection)
            .path("/rest/api/appointments")
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .post(xml(resource));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }

    return response.getLocation();
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:18,代碼來源:RESTfulClientLevel3Service.java

示例5: updateIssueWithoutCharset

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssueWithoutCharset(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(xml(resource));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例6: updateIssue

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssue(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
                    // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例7: updateIssueAsJson

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssueAsJson(int issueId, ResourcesType resource) {
    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_JSON)));

    response.close();

    if (response.getStatus() >= HTTP_BAD_REQUEST) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:17,代碼來源:RestClientService.java

示例8: updateIssueIfLast

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public boolean updateIssueIfLast(int issueId, ResourcesType resource, String md5) {
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
    headers.putSingle("If-Match", md5);

    Response response = client.target(connection)
            .path("/rest/api/2.0-alpha1/issues/{id}")
            .resolveTemplate("id", issueId)
            .request()
            .headers(headers)
            // overrides previous headers: Content-Type, Content-Language, Content-Encoding
            .put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));

    response.close();

    if (response.getStatus() != HTTP_OK && response.getStatus() != HTTP_NOT_MODIFIED) {
        StatusType stat = response.getStatusInfo();
        throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
                + " " + stat.getReasonPhrase());
    }

    return response.getStatus() == HTTP_OK;
}
 
開發者ID:Tibor17,項目名稱:javaee-samples,代碼行數:23,代碼來源:RestClientService.java

示例9: setStatusInfo

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void setStatusInfo(final StatusType statusInfo) {
    if (statusInfo != null) {
        statusCode = statusInfo.getStatusCode();
        family = statusInfo.getFamily();
        reasonPhrase = statusInfo.getReasonPhrase();
    } else {
        setStatusInfo(Status.OK);
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:10,代碼來源:MinijaxStatusInfo.java

示例10: assertSuccesfulAuthentication

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
protected int assertSuccesfulAuthentication(final Response response) {
    final StatusType statusInfo = response.getStatusInfo();
    final Family family = statusInfo.getFamily();
    final int statusCode = statusInfo.getStatusCode();
    final String reasonPhrase = statusInfo.getReasonPhrase();
    assertEquals(family, SUCCESSFUL,
                 "status: " + statusCode + " " + reasonPhrase);
    return statusCode;
}
 
開發者ID:jinahya,項目名稱:kt-ucloud-storage-client,代碼行數:11,代碼來源:StorageClientWsRsIT.java

示例11: getReasonPhrase

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/** 
 * Get the reason phrase from the response or status info.
 * Jersey uses hard-coded reason phrases, so we try to read the 
 * reason phrase(s) directly from the headers first.
 * @param response to get the reason phrase from
 * @return Reason phrase from the response
 */
private String getReasonPhrase(Response response) {
	List<String> reasonPhrases = response.getStringHeaders().get("Reason-Phrase");
	StatusType status = response.getStatusInfo();
	String reasonPhrase;
	if ( reasonPhrases!=null&&reasonPhrases.size()>0 ) {
		reasonPhrase = reasonPhrases.toString();
	} else if ( status != null ) {
		reasonPhrase = status.getReasonPhrase();
	} else {
		reasonPhrase = response.toString();
	}
	return reasonPhrase;
}
 
開發者ID:fod-dev,項目名稱:FoDBugTrackerUtility,代碼行數:21,代碼來源:RestConnection.java

示例12: writeResponse

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
public void writeResponse(StatusType statusType, Map<String, List<String>> headers,
		OutputStream entityOutputStream) throws IOException {
	String body = ((ByteArrayOutputStream) entityOutputStream).toString(StandardCharsets.UTF_8.name());
	response = new DefaultServiceResponse(body, headers, statusType.getStatusCode(),
			statusType.getReasonPhrase());
}
 
開發者ID:bbilger,項目名稱:jrestless,代碼行數:8,代碼來源:ServiceRequestHandler.java

示例13: createApiException

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
 * Create an {@link AuthleteApiException} instance.
 */
private AuthleteApiException createApiException(Throwable cause, Response response)
{
    // Error message.
    String message = cause.getMessage();

    if (response == null)
    {
        // Create an exception without HTTP response information.
        return new AuthleteApiException(message, cause);
    }

    // Status code and status message.
    int statusCode = 0;
    String statusMessage = null;

    // Get the status information.
    StatusType type = response.getStatusInfo();
    if (type != null)
    {
        statusCode    = type.getStatusCode();
        statusMessage = type.getReasonPhrase();
    }

    // Response body.
    String responseBody = null;

    // If the response has response body.
    if (hasEntity(response))
    {
        // Get the response body.
        responseBody = extractResponseBody(response);
    }

    // Response headers.
    Map<String, List<String>> headers = response.getStringHeaders();

    // Create an exception with HTTP response information.
    return new AuthleteApiException(message, cause, statusCode, statusMessage, responseBody, headers);
}
 
開發者ID:authlete,項目名稱:authlete-java-jaxrs,代碼行數:43,代碼來源:AuthleteApiImpl.java

示例14: convert

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public String convert(Response response) {
    StatusType statusInfo = response.getStatusInfo();
    return statusInfo.getStatusCode() + " " + statusInfo.getReasonPhrase() + entityInfo(response);
}
 
開發者ID:t1,項目名稱:logging-interceptor,代碼行數:5,代碼來源:JaxRsLogConverters.java

示例15: Epilogue

import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
 * Builds the block containing the common information for every request that is saved when the logging of a
 * request is finalized.
 *
 * @param logMessage  The message to log
 * @param response  The status of the response
 * @param responseLengthObserver  An Observer that receives the length of the response streamed back to the client
 * once streaming is complete
 */
public Epilogue(String logMessage, StatusType response, CacheLastObserver<Long> responseLengthObserver) {
    this.status = response.getReasonPhrase();
    this.code = response.getStatusCode();
    this.logMessage = logMessage;
    this.responseLengthObserver = responseLengthObserver;
}
 
開發者ID:yahoo,項目名稱:fili,代碼行數:16,代碼來源:Epilogue.java


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