本文整理汇总了Java中javax.ws.rs.core.Response.Status.OK属性的典型用法代码示例。如果您正苦于以下问题:Java Status.OK属性的具体用法?Java Status.OK怎么用?Java Status.OK使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类javax.ws.rs.core.Response.Status
的用法示例。
在下文中一共展示了Status.OK属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapResponse_withHeaders
@Test
public void mapResponse_withHeaders() {
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.add("h", "v");
new Expectations() {
{
jaxrsResponse.getStatusInfo();
result = Status.OK;
jaxrsResponse.getEntity();
result = "result";
jaxrsResponse.getHeaders();
result = headers;
}
};
Response response = mapper.mapResponse(null, jaxrsResponse);
Assert.assertEquals(Status.OK, response.getStatus());
Assert.assertEquals("result", response.getResult());
Assert.assertEquals(1, response.getHeaders().getHeaderMap().size());
Assert.assertThat(response.getHeaders().getHeader("h"), Matchers.contains("v"));
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:TestJaxrsProducerResponseMapper.java
示例2: execute
@POST
public Response execute(String x) {
GraphQLRequest request = Json.loads(x, GraphQLRequest.class);
String query = request.query;
Object context = null;
Map<String, Object> arguments = request.variables;
if (query == null) { query = ""; }
if (arguments == null) {arguments = Collections.emptyMap(); }
ExecutionResult result = graphql
.execute(query, context, arguments);
List<Object> errors = handleErrors(result);
Map<String, Object> output = new LinkedHashMap<>();
Status status = Status.OK;
if (!errors.isEmpty()) {
// react-relay rejected when
// key "errors" presented even it's empty
output.put("errors", errors);
status = Status.BAD_REQUEST;
}
output.put("data", result.getData());
return Response
.status(status)
.type(MediaType.APPLICATION_JSON)
.entity(Json.dumps(output))
.build();
}
示例3: testInvocationException
@Test
public void testInvocationException() {
InvocationException oExceptionIn = new InvocationException(Status.OK, "I am gone now");
oExceptionIn = ExceptionFactory.convertConsumerException(new Throwable());
Assert.assertEquals(490, oExceptionIn.getStatusCode());
oExceptionIn = ExceptionFactory.convertConsumerException(new Throwable(), "abc");
Assert.assertEquals(490, oExceptionIn.getStatusCode());
Assert.assertEquals("abc", ((CommonExceptionData) oExceptionIn.getErrorData()).getMessage());
oExceptionIn = ExceptionFactory.convertProducerException(new Throwable());
Assert.assertEquals(590, oExceptionIn.getStatusCode());
oExceptionIn = ExceptionFactory.convertProducerException(new Throwable(), "abcd");
Assert.assertEquals(590, oExceptionIn.getStatusCode());
Assert.assertEquals("abcd", ((CommonExceptionData) oExceptionIn.getErrorData()).getMessage());
oExceptionIn =
ExceptionFactory.convertConsumerException(new InvocationException(Status.OK, new String("fake-object")));
Assert.assertEquals(200, oExceptionIn.getStatusCode());
oExceptionIn = ExceptionFactory.convertConsumerException(new InvocationTargetException(new Throwable()));
Assert.assertNotEquals("java.lang.Throwable", oExceptionIn.getMessage());
InvocationException oTemp = new InvocationException(Status.OK, new CommonExceptionData("testObject"));
Assert.assertEquals("OK", oTemp.getReasonPhrase());
Assert.assertEquals("CommonExceptionData [message=testObject]", (oTemp.getErrorData().toString()));
}
示例4: mapResponse_withoutHeaders
@Test
public void mapResponse_withoutHeaders() {
new Expectations() {
{
jaxrsResponse.getStatusInfo();
result = Status.OK;
jaxrsResponse.getEntity();
result = "result";
}
};
Response response = mapper.mapResponse(null, jaxrsResponse);
Assert.assertEquals(Status.OK, response.getStatus());
Assert.assertEquals("result", response.getResult());
Assert.assertNull(response.getHeaders().getHeaderMap());
}
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:TestJaxrsProducerResponseMapper.java
示例5: testAfterReceiveResponseNormal
@Test
public void testAfterReceiveResponseNormal(@Mocked Invocation invocation,
@Mocked HttpServletResponseEx responseEx,
@Mocked Buffer bodyBuffer,
@Mocked OperationMeta operationMeta,
@Mocked ResponseMeta responseMeta,
@Mocked RestOperationMeta swaggerRestOperation,
@Mocked ProduceProcessor produceProcessor) throws Exception {
MultiMap responseHeader = new CaseInsensitiveHeaders();
responseHeader.add("b", "bValue");
Object decodedResult = new Object();
new Expectations() {
{
responseEx.getHeader(HttpHeaders.CONTENT_TYPE);
result = "json";
responseEx.getHeaderNames();
result = Arrays.asList("a", "b");
responseEx.getHeaders("b");
result = responseHeader.getAll("b");
swaggerRestOperation.findProduceProcessor("json");
result = produceProcessor;
produceProcessor.decodeResponse(bodyBuffer, responseMeta.getJavaType());
result = decodedResult;
invocation.getOperationMeta();
result = operationMeta;
operationMeta.getExtData(RestConst.SWAGGER_REST_OPERATION);
result = swaggerRestOperation;
responseEx.getStatusType();
result = Status.OK;
}
};
Response response = filter.afterReceiveResponse(invocation, responseEx);
Assert.assertSame(decodedResult, response.getResult());
Assert.assertEquals(1, response.getHeaders().getHeaderMap().size());
Assert.assertEquals(response.getHeaders().getHeader("b"), Arrays.asList("bValue"));
}
示例6: deleteManifest
/**
* {@inheritDoc}
*/
@Override public IAdfJobStatusInfo deleteManifest(String aUrn) throws AdfRestException
{
IAdfRestClient restClient = this.getRestClient();
if (!restClient.hasSession())
{
throw new AdfAuthorizationException(NO_SESSION_ERROR_MESSAGE);
}
if (LOG.isDebugEnabled())
{
LOG.debug("Requesting 'delete manifest' for the URN - " + aUrn);
}
String encodedUrn = encode(aUrn);
String deleteManifestUri = DELETE_MANIFEST_URI.replace("{urn}", encodedUrn);
AdfRestRequest<Void> request = new AdfRestRequest<>();
request.addHeader(CONTENT_TYPE_FORM_HEADER);
request.addHeader(ACCEPT_JSON_HEADER);
IAdfRestResponse<AdfJobStatusInfo> adfResponse = restClient.post(deleteManifestUri, request, AdfJobStatusInfo.class);
Status responseStatus = adfResponse.getStatus();
if (responseStatus == Status.OK)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Delete manifest request successeeded for the URN - " + aUrn);
}
return adfResponse.getData();
}
if (LOG.isDebugEnabled())
{
LOG.debug("Delete manifest request failed for the URN - " + aUrn + "\n" + adfResponse);
}
throw new AdfRestException("Delete manifest api call failed - " + adfResponse);
}
示例7: downloadDerivative
/**
* {@inheritDoc}
*/
@Override public InputStream downloadDerivative(String aUrn) throws AdfRestException
{
IAdfRestClient restClient = this.getRestClient();
if (!restClient.hasSession())
{
throw new AdfAuthorizationException(NO_SESSION_ERROR_MESSAGE);
}
if (LOG.isTraceEnabled())
{
LOG.trace("Downloading derivative for the URN - " + aUrn);
}
String encodedUrn = encode(aUrn);
String manifestUri = GET_DERIVATIVES_URI.replace("{urn}", encodedUrn);
AdfRestRequest<Void> request = new AdfRestRequest<>();
request.addHeader(CONTENT_ENCODING);
IAdfRestResponse<InputStream> adfResponse = restClient.get(manifestUri, request, InputStream.class);
Status responseStatus = adfResponse.getStatus();
if (responseStatus == Status.OK)
{
if (LOG.isTraceEnabled())
{
LOG.trace("Download derivative succeeded for the URN - " + aUrn);
}
return adfResponse.getData();
}
if (LOG.isDebugEnabled())
{
LOG.debug("Failed to download derivative for the URN - " + aUrn + "\n" + adfResponse);
}
throw new AdfRestException("REST call to get manifest info failed - " + adfResponse);
}
示例8: doGetManifest
/**
* DOCUMENT ME!
*
* @param aUri DOCUMENT ME!
* @param aUrn DOCUMENT ME!
* @param aClass DOCUMENT ME!
*
* @return DOCUMENT ME!
*
* @throws AdfRestException DOCUMENT ME!
* @throws AdfAuthorizationException DOCUMENT ME!
*/
private <T> T doGetManifest(String aUri, String aUrn, Class<T> aClass) throws AdfRestException
{
IAdfRestClient restClient = this.getRestClient();
if (!restClient.hasSession())
{
throw new AdfAuthorizationException(NO_SESSION_ERROR_MESSAGE);
}
if (LOG.isDebugEnabled())
{
LOG.debug("Requesting manifest for the URN - " + aUrn);
}
String encodedUrn = encode(aUrn);
String manifestUri = aUri.replace("{urn}", encodedUrn);
AdfRestRequest<Void> request = new AdfRestRequest<>();
request.addHeader(ACCEPT_JSON_HEADER);
IAdfRestResponse<T> adfResponse = restClient.get(manifestUri, request, aClass);
Status responseStatus = adfResponse.getStatus();
if (responseStatus == Status.OK)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Get manifest succeeded for the URN - " + aUrn);
}
return adfResponse.getData();
}
if (LOG.isDebugEnabled())
{
LOG.debug("Get manifest failed for the URN - " + aUrn + "\n" + adfResponse);
}
throw new AdfRestException("REST call to get manifest info failed - " + adfResponse);
}
示例9: createRunResponse
private Response createRunResponse(Run run, boolean async) throws MalformedURLException {
Document doc = run.toXML(true);
supplementDocument(doc);
URL url = new URL(getURLBase() + "/api/runs/" + run.getId());
Status status = async ? Status.OK : Status.ACCEPTED;
return Response
.status(status)
.entity(doc)
.header("Location", url)
.build();
}
示例10: InvocationContext
public InvocationContext() {
httpStatus = Status.OK;
}
示例11: convertSVF
/**
* {@inheritDoc}
*/
@Override public IAdfJobStatusInfo convertSVF(String aUrn, boolean aXAdsForce) throws AdfRestException
{
IAdfRestClient restClient = this.getRestClient();
if (!restClient.hasSession())
{
throw new AdfAuthorizationException(NO_SESSION_ERROR_MESSAGE);
}
if (LOG.isDebugEnabled())
{
LOG.debug("Requesting 'conversion to SVF' for the object identified by URN - " + aUrn);
}
String encodedUrn = Base64.getEncoder().encodeToString(aUrn.getBytes());
AdfConvertJobInput input = new AdfConvertJobInput();
input.setUrn(encodedUrn);
AdfConvertJobFormat format = new AdfConvertJobFormat();
format.setType(FileType.SVF);
format.addView(ViewType._3D);
AdfConvertJobOutput output = new AdfConvertJobOutput();
output.addFormat(format);
AdfConvertJob convertJob = new AdfConvertJob();
convertJob.setInput(input);
convertJob.setOutput(output);
AdfRequestBody<AdfConvertJob> body = new AdfRequestBody<>();
body.setData(convertJob);
AdfRestRequest<AdfConvertJob> request = new AdfRestRequest<>();
request.setBody(body);
request.addHeader(new NameValue<String>("x-ads-force", String.valueOf(aXAdsForce)));
request.addHeader(CONTENT_TYPE_JSON_HEADER);
request.addHeader(ACCEPT_JSON_HEADER);
IAdfRestResponse<AdfJobStatusInfo> adfResponse = restClient.post(CONVERT_JOB_URI, request, AdfJobStatusInfo.class);
Status responseStatus = adfResponse.getStatus();
if (responseStatus == Status.OK)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Conversion to SVF request succeeded for the object identified by URN - " + aUrn);
}
return adfResponse.getData();
}
if (LOG.isDebugEnabled())
{
LOG.debug("Convert to SVF API call failed for the object identified by URN - " + aUrn + "\n" + adfResponse);
}
throw new AdfRestException("Convert to SVF api call failed - " + adfResponse, adfResponse);
}
示例12: downloadThumbnail
/**
* {@inheritDoc}
*/
@Override public InputStream downloadThumbnail(String aUrn, String aGuid) throws AdfRestException
{
IAdfRestClient restClient = this.getRestClient();
if (!restClient.hasSession())
{
throw new AdfAuthorizationException(NO_SESSION_ERROR_MESSAGE);
}
if (LOG.isTraceEnabled())
{
LOG.trace("Downloading thumbnail for the URN - " + aUrn);
}
String encodedUrn = encode(aUrn);
String manifestUri = GET_THUMBNAIL_URI.replace("{urn}", encodedUrn);
manifestUri += "?width=400&height=400&role=rendered";
if (aGuid != null)
{
manifestUri += "&guid=" + aGuid;
}
AdfRestRequest<Void> request = new AdfRestRequest<>();
request.addHeader(ACCEPT_OCTET_STREAM_HEADER);
IAdfRestResponse<InputStream> adfResponse = restClient.get(manifestUri, request, InputStream.class);
Status responseStatus = adfResponse.getStatus();
if (responseStatus == Status.OK)
{
if (LOG.isTraceEnabled())
{
LOG.trace("Download thumbnail succeeded for the URN - " + aUrn);
}
return adfResponse.getData();
}
if (LOG.isDebugEnabled())
{
LOG.debug("Failed to download thumbnail for the URN - " + aUrn + "\n" + adfResponse);
}
throw new AdfRestException("REST call to download thumbnail failed - " + adfResponse);
}
示例13: upload
/**
* {@inheritDoc}
*/
@Override public IAdfObjectInfo upload(IFileData aFileData, IAdfBaseBucket aBucketInfo) throws AdfRestException
{
IAdfRestClient restClient = this.getRestClient();
if (!restClient.hasSession())
{
throw new AdfAuthorizationException("No session, need authenticated session to upload file.");
}
if (aFileData.getLength() <= 0)
{
throw new IllegalArgumentException("Given file for upload is empty/invalid.");
}
if (LOG.isDebugEnabled())
{
LOG.debug("Uploading file " + aFileData + " into bucket - " + aBucketInfo.getBucketKey());
}
String bucketKey = encode(aBucketInfo.getBucketKey());
String objectName = encode(aBucketInfo.getObjectName());
String uploadUri = UPLOAD_URI.replace("{bucketKey}", bucketKey) //
.replace("{objectName}", objectName);
AdfRestRequest<IFileData> request = new AdfRestRequest<>();
request.addHeader(CONTENT_TYPE_OCTET_STREAM_HEADER);
request.addHeader(ACCEPT_JSON_HEADER);
AdfRequestBody<IFileData> body = new AdfRequestBody<>();
body.setData(aFileData);
request.setEntityBuilder(new AdfStreamEntityBuilder());
request.setBody(body);
IAdfRestResponse<AdfObjectInfo> adfResponse = restClient.put(uploadUri, request, AdfObjectInfo.class);
Status responseStatus = adfResponse.getStatus();
if (responseStatus == Status.OK)
{
if (LOG.isDebugEnabled())
{
LOG.debug("Successfully uploaded file " + aFileData + " into bucket - " + aBucketInfo.getBucketKey());
}
return adfResponse.getData();
}
if (LOG.isDebugEnabled())
{
LOG.debug("Failed to upload file " + aFileData + " into bucket - " + aBucketInfo.getBucketKey() + "\n" + adfResponse);
}
throw new AdfRestException("Failed to upload file to autodesk develeoper api server - " + adfResponse);
}
示例14: MinijaxStatusInfo
public MinijaxStatusInfo() {
this(Status.OK);
}