本文整理匯總了Java中org.eclipse.jetty.http.HttpStatus類的典型用法代碼示例。如果您正苦於以下問題:Java HttpStatus類的具體用法?Java HttpStatus怎麽用?Java HttpStatus使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
HttpStatus類屬於org.eclipse.jetty.http包,在下文中一共展示了HttpStatus類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testRetry
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Test
public void testRetry() throws Exception {
SalesforceComponent sf = context().getComponent("salesforce", SalesforceComponent.class);
String accessToken = sf.getSession().getAccessToken();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setSslContext(new SSLContextParameters().createSSLContext(context));
HttpClient httpClient = new HttpClient(sslContextFactory);
httpClient.setConnectTimeout(60000);
httpClient.start();
String uri = sf.getLoginConfig().getLoginUrl() + "/services/oauth2/revoke?token=" + accessToken;
Request logoutGet = httpClient.newRequest(uri)
.method(HttpMethod.GET)
.timeout(1, TimeUnit.MINUTES);
ContentResponse response = logoutGet.send();
assertEquals(HttpStatus.OK_200, response.getStatus());
JobInfo jobInfo = new JobInfo();
jobInfo.setOperation(OperationEnum.INSERT);
jobInfo.setContentType(ContentType.CSV);
jobInfo.setObject(Merchandise__c.class.getSimpleName());
createJob(jobInfo);
}
示例2: parseSendirResponse
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
private void parseSendirResponse(final ContentResponse response) {
final String responseContent = response.getContentAsString();
if ((responseContent == null) || responseContent.isEmpty()) {
throw new CommunicationException("Empty response received!");
}
if (responseContent.startsWith(SENDIR_SUCCESS)) {
return;
}
if (responseContent.startsWith(SENDIR_BUSY)) {
throw new DeviceBusyException("Device is busy!");
}
if ((response.getStatus() != HttpStatus.OK_200) || responseContent.startsWith(SENDIR_ERROR)) {
throw new CommunicationException(String.format("Failed to send IR code: %s", responseContent));
}
}
示例3: writeErrorResponse
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
private void writeErrorResponse(String errorMessage, HttpServletResponse resp)
{
_logger.debug("entering");
byte[] responseBodyBytes =
UTF_8.encode(new ErrorJsonResponse(errorMessage).toString()).array();
resp.setHeader("Content-Type", "application/json");
resp.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
try
{
resp.getOutputStream().write(responseBodyBytes);
}
catch (IOException e)
{
_logger.error(e.getMessage(), e);
}
_logger.debug("exiting");
}
示例4: doPost
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp, String requestBody) throws IOException
{
_logger.debug("entering");
try
{
doPostHelp(req, resp, requestBody);
}
catch (Throwable e)
{
_logger.error(e.getMessage(), e);
JSONObject responseBody = new ErrorJsonResponse("Unexpected exception during synthesis.");
if(resp != null)
resp.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500);
writeObjectToServletOutputStream(responseBody, resp);
}
finally
{
_logger.debug("exiting");
}
}
示例5: applyAccessControlHeaderIfAllowed
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
/**
* If the given request's origin is present and a member of the allowed origins as decided by corsHeaderSetter
* sets the response Access-Control-Allow-Origin header to the request's origin.
*
* If not, sets the response code to 403 via resp.
*
* @param req the http request
* @param resp the http response
* @param corsHeaderSetter the source of truth on allowed origins
* @return whether req represents a request from an allowed origin.
*/
default boolean applyAccessControlHeaderIfAllowed(HttpServletRequest req, HttpServletResponse resp,
CorsHeaderSetter corsHeaderSetter)
{
Logger _logger = LogManager.getLogger(CorsAwareServlet.class.getName());
_logger.debug("entering");
// only allow CORS processing from origins we approve
boolean requestFromAllowedOrigin = corsHeaderSetter.applyAccessControlHeaderIfAllowed(req, resp);
if(!requestFromAllowedOrigin)
{
resp.setStatus(HttpStatus.FORBIDDEN_403);
_logger.warn("request from unauthorized origin.");
}
_logger.debug("exiting");
return requestFromAllowedOrigin;
}
示例6: testGetDataSourcePermissions
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Test
public void testGetDataSourcePermissions() {
final DocRef docRef = createDocument();
final String authorisedUsername = UUID.randomUUID().toString();
final String unauthorisedUsername = UUID.randomUUID().toString();
final String unauthenticatedUsername = UUID.randomUUID().toString();
giveDocumentPermission(authenticatedUser(authorisedUsername), docRef.getUuid(), DocumentPermission.READ);
final Response authorisedResponse = queryClient.getDataSource(authenticatedUser(authorisedUsername), docRef);
assertEquals(HttpStatus.OK_200, authorisedResponse.getStatus());
final Response unauthorisedResponse = queryClient.getDataSource(authenticatedUser(unauthorisedUsername), docRef);
assertEquals(HttpStatus.FORBIDDEN_403, unauthorisedResponse.getStatus());
final Response unauthenticatedResponse = queryClient.getDataSource(unauthenticatedUser(unauthenticatedUsername), docRef);
assertEquals(HttpStatus.UNAUTHORIZED_401, unauthenticatedResponse.getStatus());
// Create index, update, authorised get, unauthorised get
checkAuditLogs(4);
}
示例7: get
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response get(final ServiceUser user,
final String uuid){
return SimpleAuditWrapper.withUser(user)
.withAuthSupplier(() -> authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(this.service.getType())
.uuid(uuid)
.build(),
DocumentPermission.READ))
.withResponse(() -> service.get(user, uuid)
.map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("GET_DOC_REF");
eventDetail.setDescription("Get a single doc ref");
}).callAndAudit(eventLoggingService);
}
示例8: getInfo
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response getInfo(final ServiceUser user,
final String uuid){
return SimpleAuditWrapper.withUser(user)
.withAuthSupplier(() -> authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(this.service.getType())
.uuid(uuid)
.build(),
DocumentPermission.READ))
.withResponse(() -> service.getInfo(user, uuid)
.map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("GET_DOC_REF_INFO");
eventDetail.setDescription("Get info for a single doc ref");
}).callAndAudit(eventLoggingService);
}
示例9: createDocument
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response createDocument(final ServiceUser user,
final String uuid,
final String name,
final String parentFolderUUID){
return SimpleAuditWrapper.withUser(user)
.withAuthSupplier(() -> authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(DocumentPermission.FOLDER)
.uuid(parentFolderUUID)
.build(),
DocumentPermission.CREATE.getTypedPermission(service.getType())))
.withResponse(() -> service.createDocument(user, uuid, name)
.map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("CREATE_DOC_REF");
eventDetail.setDescription("Create a Doc Ref");
}).callAndAudit(eventLoggingService);
}
示例10: moveDocument
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response moveDocument(final ServiceUser user,
final String uuid,
final String parentFolderUUID){
return SimpleAuditWrapper.withUser(user)
.withAuthSupplier(() -> authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(this.service.getType())
.uuid(uuid)
.build(),
DocumentPermission.READ) &&
authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(DocumentPermission.FOLDER)
.uuid(parentFolderUUID)
.build(),
DocumentPermission.CREATE.getTypedPermission(service.getType())))
.withResponse(() -> service.moveDocument(user, uuid)
.map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("MOVE_DOC_REF");
eventDetail.setDescription("Move a Doc Ref");
}).callAndAudit(eventLoggingService);
}
示例11: deleteDocument
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response deleteDocument(final ServiceUser user,
final String uuid){
return SimpleAuditWrapper.withUser(user)
.withAuthSupplier(() -> authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(this.service.getType())
.uuid(uuid)
.build(),
DocumentPermission.DELETE))
.withResponse(() -> service.deleteDocument(user, uuid).map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("DELETE_DOC_REF");
eventDetail.setDescription("Delete a Doc Ref");
}).callAndAudit(eventLoggingService);
}
示例12: importDocument
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response importDocument(final ServiceUser user,
final String uuid,
final String name,
final Boolean confirmed,
final Map<String, String> dataMap){
return SimpleAuditWrapper.withUser(user)
.withDefaultAuthSupplier()
.withResponse(() -> service.importDocument(user, uuid, name, confirmed, dataMap)
.map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("IMPORT_DOC_REF");
eventDetail.setDescription("Import a Doc Ref");
}).callAndAudit(eventLoggingService);
}
示例13: exportDocument
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response exportDocument(final ServiceUser user,
final String uuid){
return SimpleAuditWrapper.withUser(user)
.withAuthSupplier(() -> authorisationService.isAuthorised(user,
new DocRef.Builder()
.type(this.service.getType())
.uuid(uuid)
.build(),
DocumentPermission.EXPORT))
.withResponse(() -> {
final ExportDTO result = service.exportDocument(user, uuid);
if (result.getValues().size() > 0) {
return Response.ok(result).build();
} else {
return Response.status(HttpStatus.NOT_FOUND_404)
.entity(result)
.build();
}
})
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("EXPORT_DOC_REF");
eventDetail.setDescription("Export a single doc ref");
}).callAndAudit(eventLoggingService);
}
示例14: getDataSource
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
@Override
public Response getDataSource(final ServiceUser user,
final DocRef docRef){
return DocRefAuditWrapper.<T>withUser(user)
.withDocRef(docRef)
.withDocRefEntity(d -> docRefService.get(user, docRef.getUuid()))
.withAuthSupplier(d -> authorisationService.isAuthorised(user,
d,
DocumentPermission.READ))
.withResponse(docRefEntity -> service.getDataSource(user, docRef)
.map(d -> Response.ok(d).build())
.orElse(Response.status(HttpStatus.NOT_FOUND_404)
.build()))
.withPopulateAudit((eventDetail, response, exception) -> {
eventDetail.setTypeId("GET_DATA_SOURCE");
eventDetail.setDescription("Get Datasource For Document");
final Search search = new Search();
eventDetail.setSearch(search);
final Outcome outcome = new Outcome();
outcome.setSuccess(null != exception);
search.setOutcome(outcome);
}).callAndAudit(eventLoggingService);
}
示例15: login
import org.eclipse.jetty.http.HttpStatus; //導入依賴的package包/類
public void login() throws Exception {
JSONObject sessionRes, loginRes = httpClient.Get(this.getUrl(buildUrl(LOGIN)));
if (loginRes != null) {
httpClient.COOKIES = (Header[]) loginRes.get("COOKIE");
httpClient.COOKIES = (Header[]) loginRes.get("COOKIE");
sessionRes = httpClient.post(this.getUrl(buildUrl(SESSION)), "");
if (sessionRes.get("status").equals(HttpStatus.CREATED_201)) {
DLogger.Log("session created");
httpClient.COOKIES = (Header[]) sessionRes.get("COOKIE");
} else {
DLogger.Log("session not available status : ", sessionRes.get("status"));
}
httpClient.LOGIN_KEY = true;
} else {
httpClient.LOGIN_KEY = null;
}
}