Java 类org.apache.http.client.methods.HttpDelete 实例源码
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwDataIntegrityUnicityException()
*/
@Test
public void testIntegrityUnicityError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/integrity-unicity");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("integrity-unicity", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("2003/PRIMARY", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:ticketing-service-paqx-parent-sample
文件:TicketingIntegrationService.java
private void delete(String url) throws IOException, HttpException {
CredentialsProvider credentials = credentialsProvider();
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credentials)
.build();
try {
HttpDelete httpDelete = new HttpDelete(url);
httpDelete.setHeader("Accept", "application/json");
System.out.println("Executing request " + httpDelete.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpDelete);
try {
LOG.debug("----------------------------------------");
LOG.debug((String)response.getStatusLine().getReasonPhrase());
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
项目:restheart-java-client
文件:HttpConnectionUtils.java
@Override
public CloseableHttpResponse sendHttpDelete(String url, List<Header> headers) {
CloseableHttpResponse execute = null;
try {
LOGGER.info("Sending GET request to url-" + url);
CloseableHttpClient httpClient = this.httpClientFactory.getHttpClient();
HttpDelete httpDelete = new HttpDelete(url);
if (headers != null && !headers.isEmpty()) {
for (Header header : headers) {
httpDelete.addHeader(header);
}
}
execute = httpClient.execute(httpDelete);
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "Was unable to send Get request to url-" + url, e);
}
return execute;
}
项目:devops-cstack
文件:RestUtils.java
/**
* sendDeleteCommand
*
* @param url
* @return
*/
public Map<String, String> sendDeleteCommand(String url, Map<String, Object> credentials)
throws ManagerResponseException {
Map<String, String> response = new HashMap<String, String>();
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpDelete httpDelete = new HttpDelete(url);
CloseableHttpResponse httpResponse;
try {
httpResponse = httpclient.execute(httpDelete, localContext);
ResponseHandler<String> handler = new CustomResponseErrorHandler();
String body = handler.handleResponse(httpResponse);
response.put("body", body);
httpResponse.close();
} catch (Exception e) {
throw new ManagerResponseException(e.getMessage(), e);
}
return response;
}
项目:devops-cstack
文件:JSONClient.java
public DockerResponse sendDelete(URI uri, Boolean httpRequired) throws JSONClientException {
if (logger.isDebugEnabled()) {
logger.debug("Send a delete request to : " + uri);
}
CloseableHttpResponse response = null;
try {
CloseableHttpClient httpClient = buildSecureHttpClient();
HttpDelete httpDelete = new HttpDelete(uri);
response = httpClient.execute(httpDelete);
} catch (IOException e) {
throw new JSONClientException("Error in sendDelete method due to : " + e.getMessage(), e);
}
if (logger.isDebugEnabled()) {
logger.debug("Status code : " + response.getStatusLine().getStatusCode());
}
return new DockerResponse(response.getStatusLine().getStatusCode(), "");
}
项目:bootstrap
文件:ExceptionMapperIT.java
private void assertNotFound(final String path, final String message) throws IOException, ClientProtocolException, JsonParseException, JsonMappingException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + path);
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("entity", result.get("code"));
Assert.assertEquals(message, result.get("message"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwCannotAcquireLockException()
*/
@Test
public void testCannotAcquireLockException() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/cannotAcquireLockException");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_CONFLICT, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("database-lock", result.get("code"));
Assert.assertNull(result.get("message"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:datarouter
文件:DatarouterHttpRequest.java
private HttpRequestBase getRequest(String url){
switch(method){
case DELETE:
return new HttpDelete(url);
case GET:
return new HttpGet(url);
case HEAD:
return new HttpHead(url);
case PATCH:
return new HttpPatch(url);
case POST:
return new HttpPost(url);
case PUT:
return new HttpPut(url);
default:
throw new IllegalArgumentException("Invalid or null HttpMethod: " + method);
}
}
项目:aws-sdk-java-v2
文件:ApacheHttpRequestFactory.java
private HttpRequestBase createApacheRequest(SdkHttpFullRequest request, String uri) {
switch (request.method()) {
case HEAD:
return new HttpHead(uri);
case GET:
return new HttpGet(uri);
case DELETE:
return new HttpDelete(uri);
case OPTIONS:
return new HttpOptions(uri);
case PATCH:
return wrapEntity(request, new HttpPatch(uri));
case POST:
return wrapEntity(request, new HttpPost(uri));
case PUT:
return wrapEntity(request, new HttpPut(uri));
default:
throw new RuntimeException("Unknown HTTP method name: " + request.method());
}
}
项目:elasticsearch_my
文件:Request.java
static Request delete(DeleteRequest deleteRequest) {
String endpoint = endpoint(deleteRequest.index(), deleteRequest.type(), deleteRequest.id());
Params parameters = Params.builder();
parameters.withRouting(deleteRequest.routing());
parameters.withParent(deleteRequest.parent());
parameters.withTimeout(deleteRequest.timeout());
parameters.withVersion(deleteRequest.version());
parameters.withVersionType(deleteRequest.versionType());
parameters.withRefreshPolicy(deleteRequest.getRefreshPolicy());
parameters.withWaitForActiveShards(deleteRequest.waitForActiveShards());
return new Request(HttpDelete.METHOD_NAME, endpoint, parameters.getParams(), null);
}
项目:marklogic-rdf4j
文件:ConnectedRESTQA.java
public static void deleteRESTUser(String usrName){
try{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/users/"+usrName);
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode()== 202){
Thread.sleep(3500);
}
}catch (Exception e) {
// writing error to Log
e.printStackTrace();
}
}
项目:marklogic-rdf4j
文件:ConnectedRESTQA.java
public static void deleteUserRole(String roleName){
try{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
HttpDelete delete = new HttpDelete("http://"+host+":8002/manage/v2/roles/"+roleName);
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode()== 202){
Thread.sleep(3500);
}
}catch (Exception e) {
// writing error to Log
e.printStackTrace();
}
}
项目:marklogic-rdf4j
文件:ConnectedRESTQA.java
public static void deleteRESTServerWithDB(String restServerName) {
try{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
HttpDelete delete = new HttpDelete("http://"+host+":8002/v1/rest-apis/"+restServerName+"?include=content&include=modules");
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode()== 202){
Thread.sleep(9500);
}
}catch (Exception e) {
// writing error to Log
e.printStackTrace();
}
}
项目:marklogic-rdf4j
文件:ConnectedRESTQA.java
public static void deleteRESTServer(String restServerName) {
try{
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
new AuthScope(host, 8002),
new UsernamePasswordCredentials("admin", "admin"));
HttpDelete delete = new HttpDelete("http://"+host+":8002/v1/rest-apis/"+restServerName+"&include=modules");
HttpResponse response = client.execute(delete);
if(response.getStatusLine().getStatusCode()== 202){
Thread.sleep(3500);
waitForServerRestart();
}
else System.out.println("Server response "+response.getStatusLine().getStatusCode());
}catch (Exception e) {
// writing error to Log
System.out.println("Inside Deleting Rest server is throwing an error");
e.printStackTrace();
}
}
项目:bubble2
文件:HttpUtils.java
private HttpUtils(HttpRequestBase request) {
this.request = request;
this.clientBuilder = HttpClientBuilder.create();
this.isHttps = request.getURI().getScheme().equalsIgnoreCase("https");
this.config = RequestConfig.custom().setCookieSpec(CookieSpecs.BROWSER_COMPATIBILITY);
this.cookieStore = new BasicCookieStore();
if (request instanceof HttpPost) {
this.type = 1;
this.builder = EntityBuilder.create().setParameters(new ArrayList<NameValuePair>());
} else if (request instanceof HttpGet) {
this.type = 2;
this.uriBuilder = new URIBuilder();
} else if (request instanceof HttpPut) {
this.type = 3;
this.builder = EntityBuilder.create().setParameters(new ArrayList<NameValuePair>());
} else if (request instanceof HttpDelete) {
this.type = 4;
this.uriBuilder = new URIBuilder();
}
}
项目:educational-plugin
文件:CCStepicConnector.java
public static void deleteTask(@NotNull final Integer task, Project project) {
final HttpDelete request = new HttpDelete(EduStepicNames.STEPIC_API_URL + EduStepicNames.STEP_SOURCES + task);
ApplicationManager.getApplication().invokeLater(() -> {
try {
final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
if (client == null) return;
final CloseableHttpResponse response = client.execute(request);
final HttpEntity responseEntity = response.getEntity();
final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
EntityUtils.consume(responseEntity);
final StatusLine line = response.getStatusLine();
if (line.getStatusCode() != HttpStatus.SC_NO_CONTENT) {
LOG.error("Failed to delete task " + responseString);
showErrorNotification(project, "Failed to delete task ", responseString);
}
}
catch (IOException e) {
LOG.error(e.getMessage());
}
});
}
项目:FCat
文件:HttpCallSSL.java
public String deleteFile(String deleteURL) throws IllegalStateException {
HttpResponse response = null;
HttpDelete delete = new HttpDelete(deleteURL);
try {
response = httpClient.execute(delete);
String statusCode = String.valueOf(response.getStatusLine().getStatusCode());
if (statusCode.indexOf("20") == 0) {
HttpEntity entity = response.getEntity();
String contentType = entity.getContentType().getValue();
LOG.info("contentType=" + contentType);
return StrUtil.readStream(entity.getContent(), responseContextEncode);
} else if (statusCode.indexOf("40") == 0) {
LOG.error("Page: " + deleteURL + " no find");
return "Page no find";
} else {
LOG.error("返回状态码:[" + statusCode + "]");
return "返回状态码:[" + statusCode + "]";
}
} catch (Exception e) {
e.printStackTrace();
} finally {
delete.releaseConnection();
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Deletes the customer and sets customerName to null ({@link #getCustomerName()})
*
* @param customerName unique name of the customer
* @return request object to check status codes and return values
*/
public Response deleteCustomer( String customerName )
{
HttpDelete request = new HttpDelete( this.yambasBase + "customers/" + customerName );
setAuthorizationHeader( request );
try
{
final HttpResponse response = this.client.execute( request );
this.customerName = null;
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Deletes a module
*
* @param moduleName
* the name of the module to delete
* @param deleteCompletely
* if set to false, the module is only deleted from the current system and wil still exist in database
* @return request object to check status codes and return values
*/
public Response deleteModule( String moduleName, boolean deleteCompletely )
{
HttpDelete request = new HttpDelete(
this.yambasBase + "modules/" + moduleName + "?deleteCompletely=" + String.valueOf( deleteCompletely ) );
setAuthorizationHeader( request );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Deletes the specified app
*
* @param customerName
* the name of the customer which owns the app
* @param appName
* the name of the app to delete
* @return request object to check status codes and return values
*/
public Response deleteApp( String customerName, String appName )
{
final HttpDelete request = new HttpDelete( this.yambasBase + "customers/" + customerName + "/apps/" + appName );
setAuthorizationHeader( request );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Drops all data contained in the currently set app
*
* @return request object to check status codes and return values
*/
public Response dropData( )
{
final HttpDelete request = new HttpDelete( this.yambasBase + "apps/" + this.appName + "/models" );
setAuthorizationHeader( request );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Delete the references for a specified object
*
* @param moduleName
* the name of the module
* @param dataModelName
* the name of the datamodel
* @param dataModelId
* the datamodel-id
* @param refAttributeName
* the attribute-name of the reference
* @param refId
* the reference id
* @return request object to check status codes and return values
*/
public Response deleteReference( String moduleName, String dataModelName, String dataModelId,
String refAttributeName, String refId )
{
final HttpDelete request = new HttpDelete( this.yambasBase + "apps/" + this.appName + "/models/" + moduleName +
"/" + dataModelName + "/" + dataModelId + "/" + refAttributeName + "/" + refId );
setAuthorizationHeader( request );
request.addHeader( "ContentType", "application/json" );
request.addHeader( "x-apiomat-apikey", this.apiKey );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Deletes an object
*
* @param moduleName
* the name of the module
* @param dataModelName
* the name of the datamodel
* @param dataModelId
* the datamodel-id
* @return request object to check status codes and return values
*/
public Response deleteObject( String moduleName, String dataModelName, String dataModelId )
{
final HttpDelete request = new HttpDelete( this.yambasBase + "apps/" + this.appName + "/models/" + moduleName +
"/" + dataModelName + "/" + dataModelId );
setAuthorizationHeader( request );
request.addHeader( "ContentType", "application/json" );
request.addHeader( "x-apiomat-apikey", this.apiKey );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:integration-test-helper
文件:AomHttpClient.java
/**
* Deletes static data, either image or file
*
* @param id the file id
* @param isImage indicates whether this is an image or a file
* @return request object to check status codes and return values
*/
public Response deleteStaticData( String id, final boolean isImage )
{
final HttpDelete request =
new HttpDelete(
this.yambasBase + "apps/" + this.appName + "/data/" + ( isImage ? "images/" : "files/" ) + id );
request.addHeader( "Content-Type", "application/octet-stream" );
request.addHeader( "x-apiomat-apikey", this.apiKey );
request.addHeader( "x-apiomat-system", this.system.toString( ) );
try
{
final HttpResponse response = this.client.execute( request );
return new Response( response );
}
catch ( final IOException e )
{
e.printStackTrace( );
}
return null;
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwFailSafe()
*/
@Test
public void testInternalError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/failsafe");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("internal", result.get("code"));
Assert.assertNull(result.get("message"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwFailSafe2()
*/
@Test
public void testInternalError2() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/failsafe2");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("internal", result.get("code"));
Assert.assertNull(result.get("message"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwFailSafe2()
*/
@Test
public void testInternalError3() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/failsafe3");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("internal", result.get("code"));
Assert.assertNull(result.get("message"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwDataIntegrityException()
*/
@Test
public void testIntegrityForeignError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/integrity-foreign");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("integrity-foreign", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("assignment/project", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwDataIntegrityUnknownException()
*/
@Test
public void testIntegrityUnknownError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/integrity-unknown");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_PRECONDITION_FAILED, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("integrity-unknown", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("Any SQL error", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
private void assertUnavailable(final String path) throws IOException, ClientProtocolException, JsonParseException, JsonMappingException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + path);
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertNull(result.get("message"));
Assert.assertEquals("database-down", result.get("code"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwCommunicationException()
*/
@Test
public void testCommunicationException() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/ldap");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("Connection refused", result.get("message"));
Assert.assertEquals("ldap-down", result.get("code"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwMailSendException()
*/
@Test
public void testMailSendException() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/mail");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_SERVICE_UNAVAILABLE, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertNull(result.get("message"));
Assert.assertEquals("mail-down", result.get("code"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwTechnical()
*/
@Test
public void testTechnicalErrorWithCause() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/technical");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("message", result.get("message"));
Assert.assertEquals("technical", result.get("code"));
Assert.assertNotNull(result.get("cause"));
@SuppressWarnings("unchecked")
final Map<?, ?> cause = (Map<String, String>) result.get("cause");
Assert.assertEquals("message", cause.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwBusiness()
*/
@Test
public void testBusinessError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/business");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals(BusinessException.KEY_UNKNOW_ID, result.get("message"));
Assert.assertEquals("business", result.get("code"));
Assert.assertNull(result.get("cause"));
@SuppressWarnings("unchecked")
final List<Object> parameters = (List<Object>) result.get("parameters");
Assert.assertNotNull(parameters);
Assert.assertEquals(2, parameters.size());
Assert.assertEquals("parameter1", parameters.get(0));
Assert.assertEquals("parameter2", parameters.get(1));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwWebApplication()
*/
@Test
public void testJaxRSError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/jax-rs");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("internal", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("HTTP 500 Internal Server Error", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwJSonMapping()
*/
@Test
public void testJSonMappingError() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/json-mapping");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
Assert.assertEquals("{errors={dialDouble=[{rule=Double}]}}", new ObjectMapperTrim().readValue(content, HashMap.class).toString());
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
@Test
public void testJaxRS404Error() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/unknow");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("internal", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("HTTP 404 Not Found", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwAuthenticationException()
*/
@Test
public void testAuthenticationException() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/security-401");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_UNAUTHORIZED, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("security", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("message", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwNotImplemented()
*/
@Test
public void notImplemented() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/not-implemented");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_NOT_IMPLEMENTED, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("not-implemented", result.get("code"));
Assert.assertNull(result.get("cause"));
Assert.assertEquals("message", result.get("message"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}
项目:bootstrap
文件:ExceptionMapperIT.java
/**
* @see ExceptionMapperResource#throwTransactionSystemException()
*/
@Test
public void testUnknownTransactionnalException() throws IOException {
final HttpDelete httpdelete = new HttpDelete(BASE_URI + RESOURCE + "/transaction-commit");
HttpResponse response = null;
try {
response = httpclient.execute(httpdelete);
Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatusLine().getStatusCode());
final String content = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
final Map<?, ?> result = new ObjectMapperTrim().readValue(content, HashMap.class);
Assert.assertEquals("message", result.get("message"));
Assert.assertEquals("technical", result.get("code"));
Assert.assertNull(result.get("cause"));
} finally {
if (response != null) {
response.getEntity().getContent().close();
}
}
}