org.apache.commons.httpclient.methods.DeleteMethod Java Examples

The following examples show how to use org.apache.commons.httpclient.methods.DeleteMethod. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserAuthenticationMgmtITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAuthentications() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    // create an authentication token
    final Identity adminIdent = baseSecurity.findIdentityByName("administrator");
    final Authentication authentication = baseSecurity.createAndPersistAuthentication(adminIdent, "REST-A-2", "administrator", "credentials");
    assertTrue(authentication != null && authentication.getKey() != null && authentication.getKey().longValue() > 0);
    DBFactory.getInstance().intermediateCommit();

    // delete an authentication token
    final String request = "/users/administrator/auth/" + authentication.getKey().toString();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);
    method.releaseConnection();

    final Authentication refAuth = baseSecurity.findAuthentication(adminIdent, "REST-A-2");
    assertNull(refAuth);
}
 
Example #2
Source File: HttpUtils.java    From Java-sdk with Apache License 2.0 6 votes vote down vote up
/**
 * 处理delete请求
 * @param url
 * @param headers
 * @return
 */
public static JSONObject doDelete(String url, Map<String, String> headers){
	
	HttpClient httpClient = new HttpClient();
	
	DeleteMethod deleteMethod = new DeleteMethod(url);
	
	//设置header
	setHeaders(deleteMethod,headers);
	
	String responseStr = "";
	
	try {
		httpClient.executeMethod(deleteMethod);
		responseStr = deleteMethod.getResponseBodyAsString();
	} catch (Exception e) {
		log.error(e);
		responseStr="{status:0}";
	} 
	return JSONObject.parseObject(responseStr);
}
 
Example #3
Source File: InterpreterRestApiTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddDeleteRepository() throws IOException {
  // Call create repository API
  String repoId = "securecentral";
  String jsonRequest = "{\"id\":\"" + repoId +
      "\",\"url\":\"https://repo1.maven.org/maven2\",\"snapshot\":\"false\"}";

  PostMethod post = httpPost("/interpreter/repository/", jsonRequest);
  assertThat("Test create method:", post, isAllowed());
  post.releaseConnection();

  // Call delete repository API
  DeleteMethod delete = httpDelete("/interpreter/repository/" + repoId);
  assertThat("Test delete method:", delete, isAllowed());
  delete.releaseConnection();
}
 
Example #4
Source File: UserAuthenticationMgmtITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteAuthentications() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    // create an authentication token
    final Identity adminIdent = baseSecurity.findIdentityByName("administrator");
    final Authentication authentication = baseSecurity.createAndPersistAuthentication(adminIdent, "REST-A-2", "administrator", "credentials");
    assertTrue(authentication != null && authentication.getKey() != null && authentication.getKey().longValue() > 0);
    DBFactory.getInstance().intermediateCommit();

    // delete an authentication token
    final String request = "/users/administrator/auth/" + authentication.getKey().toString();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);
    method.releaseConnection();

    final Authentication refAuth = baseSecurity.findAuthentication(adminIdent, "REST-A-2");
    assertNull(refAuth);
}
 
Example #5
Source File: ZeppelinRestApiTest.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteParagraph() throws IOException {
  Note note = null;
  try {
    note = TestUtils.getInstance(Notebook.class).createNote("note1_testDeleteParagraph", anonymous);

    Paragraph p = note.addNewParagraph(AuthenticationInfo.ANONYMOUS);
    p.setTitle("title1");
    p.setText("text1");

    TestUtils.getInstance(Notebook.class).saveNote(note, anonymous);

    DeleteMethod delete = httpDelete("/notebook/" + note.getId() + "/paragraph/" + p.getId());
    assertThat("Test delete method: ", delete, isAllowed());
    delete.releaseConnection();

    Note retrNote = TestUtils.getInstance(Notebook.class).getNote(note.getId());
    Paragraph retrParagrah = retrNote.getParagraph(p.getId());
    assertNull("paragraph should be deleted", retrParagrah);
  } finally {
    //cleanup
    if (null != note) {
      TestUtils.getInstance(Notebook.class).removeNote(note, anonymous);
    }
  }
}
 
Example #6
Source File: BigSwitchBcfApi.java    From cloudstack with Apache License 2.0 6 votes vote down vote up
protected HttpMethod createMethod(final String type, final String uri, final int port) throws BigSwitchBcfApiException {
    String url;
    try {
        url = new URL(S_PROTOCOL, host, port, uri).toString();
    } catch (MalformedURLException e) {
        S_LOGGER.error("Unable to build Big Switch API URL", e);
        throw new BigSwitchBcfApiException("Unable to build Big Switch API URL", e);
    }

    if ("post".equalsIgnoreCase(type)) {
        return new PostMethod(url);
    } else if ("get".equalsIgnoreCase(type)) {
        return new GetMethod(url);
    } else if ("delete".equalsIgnoreCase(type)) {
        return new DeleteMethod(url);
    } else if ("put".equalsIgnoreCase(type)) {
        return new PutMethod(url);
    } else {
        throw new BigSwitchBcfApiException("Requesting unknown method type");
    }
}
 
Example #7
Source File: CourseITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCourses() throws IOException {
    final ICourse course = CoursesWebService.createEmptyCourse(admin, "courseToDel", "course to delete", null);
    DBFactory.getInstance().intermediateCommit();

    final HttpClient c = loginWithCookie("administrator", "olat");
    final DeleteMethod method = createDelete("/repo/courses/" + course.getResourceableId(), MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    final List<String> courseType = new ArrayList<String>();
    courseType.add(CourseModule.getCourseTypeName());
    final Roles roles = new Roles(true, true, true, true, false, true, false);
    final List<RepositoryEntry> repoEntries = RepositoryServiceImpl.getInstance().genericANDQueryWithRolesRestriction("*", "*", "*", courseType, roles, "");
    assertNotNull(repoEntries);

    for (final RepositoryEntry entry : repoEntries) {
        assertNotSame(entry.getOlatResource().getResourceableId(), course.getResourceableId());
    }
}
 
Example #8
Source File: CourseITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCourses() throws IOException {
    final ICourse course = CoursesWebService.createEmptyCourse(admin, "courseToDel", "course to delete", null);
    DBFactory.getInstance().intermediateCommit();

    final HttpClient c = loginWithCookie("administrator", "olat");
    final DeleteMethod method = createDelete("/repo/courses/" + course.getResourceableId(), MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    final List<String> courseType = new ArrayList<String>();
    courseType.add(CourseModule.getCourseTypeName());
    final Roles roles = new Roles(true, true, true, true, false, true, false);
    final List<RepositoryEntry> repoEntries = RepositoryServiceImpl.getInstance().genericANDQueryWithRolesRestriction("*", "*", "*", courseType, roles, "");
    assertNotNull(repoEntries);

    for (final RepositoryEntry entry : repoEntries) {
        assertNotSame(entry.getOlatResource().getResourceableId(), course.getResourceableId());
    }
}
 
Example #9
Source File: CatalogITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCatalogEntry() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry2.getKey().toString()).build();
    final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true);

    final int code = c.executeMethod(method);
    assertEquals(200, code);
    method.releaseConnection();

    final List<CatalogEntry> entries = catalogService.getChildrenOf(root1);
    for (final CatalogEntry entry : entries) {
        assertFalse(entry.getKey().equals(entry2.getKey()));
    }
}
 
Example #10
Source File: RestUtilities.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
private static HttpMethodBase getMethod(HttpMethod method, String address) {
	String addr = address;
	if (method.equals(HttpMethod.Delete)) {
		return new DeleteMethod(addr);
	}
	if (method.equals(HttpMethod.Post)) {
		return new PostMethod(addr);
	}
	if (method.equals(HttpMethod.Get)) {
		return new GetMethod(addr);
	}
	if (method.equals(HttpMethod.Put)) {
		return new PutMethod(addr);
	}
	Assert.assertUnreachable("method doesn't exist");
	return null;
}
 
Example #11
Source File: DeleteRouteCommand.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected ServerStatus _doIt() {
	try {
		URI targetURI = URIUtil.toURI(target.getUrl());

		/* delete the route */
		URI routeURI = targetURI.resolve("/v2/routes/" + route.getGuid()); //$NON-NLS-1$

		DeleteMethod deleteRouteMethod = new DeleteMethod(routeURI.toString());
		ServerStatus confStatus = HttpUtil.configureHttpMethod(deleteRouteMethod, target.getCloud());
		if (!confStatus.isOK())
			return confStatus;
		
		deleteRouteMethod.setQueryString("recursive=true"); //$NON-NLS-1$

		ServerStatus status = HttpUtil.executeMethod(deleteRouteMethod);
		return status;

	} catch (Exception e) {
		String msg = NLS.bind("An error occured when performing operation {0}", commandName);
		logger.error(msg, e);
		return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
	}
}
 
Example #12
Source File: CatalogITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveOwner() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).path("owners").path(id1.getUser().getKey().toString())
            .build();
    final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true);

    final int code = c.executeMethod(method);
    method.releaseConnection();
    assertEquals(200, code);

    final CatalogEntry entry = catalogService.loadCatalogEntry(entry1.getKey());
    final List<Identity> identities = securityManager.getIdentitiesOfSecurityGroup(entry.getOwnerGroup());
    boolean found = false;
    for (final Identity identity : identities) {
        if (identity.getKey().equals(id1.getKey())) {
            found = true;
        }
    }
    assertFalse(found);
}
 
Example #13
Source File: UnmapRouteCommand.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected ServerStatus _doIt() {
	try {

		/* unmap route from application */
		URI targetURI = URIUtil.toURI(target.getUrl());
		DeleteMethod unmapRouteMethod = new DeleteMethod(targetURI.resolve("/v2/apps/" + app.getGuid() + "/routes/" + route.getGuid()).toString()); //$NON-NLS-1$//$NON-NLS-2$
		ServerStatus confStatus = HttpUtil.configureHttpMethod(unmapRouteMethod, target.getCloud());
		if (!confStatus.isOK())
			return confStatus;
		
		return HttpUtil.executeMethod(unmapRouteMethod);

	} catch (Exception e) {
		String msg = NLS.bind("An error occured when performing operation {0}", commandName); //$NON-NLS-1$
		logger.error(msg, e);
		return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
	}
}
 
Example #14
Source File: RemoteConnectorRequestImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected static HttpMethodBase buildHttpClientMethod(String url, String method)
{
    if ("GET".equals(method))
    {
        return new GetMethod(url);
    }
    if ("POST".equals(method))
    {
        return new PostMethod(url);
    }
    if ("PUT".equals(method))
    {
        return new PutMethod(url);
    }
    if ("DELETE".equals(method))
    {
        return new DeleteMethod(url);
    }
    if (TestingMethod.METHOD_NAME.equals(method))
    {
        return new TestingMethod(url);
    }
    throw new UnsupportedOperationException("Method '"+method+"' not supported");
}
 
Example #15
Source File: SchemaUtils.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
/**
 * Given host, port and schema name, send a http DELETE request to delete the {@link Schema}.
 *
 * @return <code>true</code> on success.
 * <P><code>false</code> on failure.
 */
public static boolean deleteSchema(@Nonnull String host, int port, @Nonnull String schemaName) {
  Preconditions.checkNotNull(host);
  Preconditions.checkNotNull(schemaName);

  try {
    URL url = new URL("http", host, port, "/schemas/" + schemaName);
    DeleteMethod httpDelete = new DeleteMethod(url.toString());
    try {
      int responseCode = HTTP_CLIENT.executeMethod(httpDelete);
      if (responseCode >= 400) {
        String response = httpDelete.getResponseBodyAsString();
        LOGGER.warn("Got error response code: {}, response: {}", responseCode, response);
        return false;
      }
      return true;
    } finally {
      httpDelete.releaseConnection();
    }
  } catch (Exception e) {
    LOGGER.error("Caught exception while getting the schema: {} from host: {}, port: {}", schemaName, host, port, e);
    return false;
  }
}
 
Example #16
Source File: ESBJAVA4852URITemplateWithCompleteURLTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
@Test(groups = { "wso2.esb" }, description = "Sending complete URL to API and for dispatching")
public void testCompleteURLWithHTTPMethod() throws Exception {
    logReader.start();

    DeleteMethod delete = new DeleteMethod(getApiInvocationURL(
            "myApi1/order/21441/item/17440079" + "?message_id=41ec2ec4-e629-4e04-9fdf-c32e97b35bd1"));
    HttpClient httpClient = new HttpClient();

    try {
        httpClient.executeMethod(delete);
        Assert.assertEquals(delete.getStatusLine().getStatusCode(), 202, "Response code mismatched");
    } finally {
        delete.releaseConnection();
    }

    Assert.assertTrue(logReader.checkForLog("order API INVOKED", DEFAULT_TIMEOUT),
            "Request Not Dispatched to API when HTTP method having full url");

    logReader.stop();
}
 
Example #17
Source File: CatalogITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteCatalogEntry() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry2.getKey().toString()).build();
    final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true);

    final int code = c.executeMethod(method);
    assertEquals(200, code);
    method.releaseConnection();

    final List<CatalogEntry> entries = catalogService.getChildrenOf(root1);
    for (final CatalogEntry entry : entries) {
        assertFalse(entry.getKey().equals(entry2.getKey()));
    }
}
 
Example #18
Source File: CatalogITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveOwner() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).path("owners").path(id1.getUser().getKey().toString())
            .build();
    final DeleteMethod method = createDelete(uri, MediaType.APPLICATION_JSON, true);

    final int code = c.executeMethod(method);
    method.releaseConnection();
    assertEquals(200, code);

    final CatalogEntry entry = catalogService.loadCatalogEntry(entry1.getKey());
    final List<Identity> identities = securityManager.getIdentitiesOfSecurityGroup(entry.getOwnerGroup());
    boolean found = false;
    for (final Identity identity : identities) {
        if (identity.getKey().equals(id1.getKey())) {
            found = true;
        }
    }
    assertFalse(found);
}
 
Example #19
Source File: PublicApiHttpClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public HttpResponse delete(final RequestContext rq, Binding cmisBinding, String version, String cmisOperation) throws IOException
{
    RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), cmisBinding, version, cmisOperation, null);
    String url = endpoint.getUrl();

    DeleteMethod req = new DeleteMethod(url.toString());
    return submitRequest(req, rq);
}
 
Example #20
Source File: CourseGroupMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSecurityDeleteCall() throws IOException {
    final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8");

    final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g2.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    method.releaseConnection();

    assertEquals(401, code);
}
 
Example #21
Source File: OlatJerseyTestCase.java    From olat with Apache License 2.0 5 votes vote down vote up
public DeleteMethod createDelete(final URI requestURI, final String accept, final boolean cookie) {
    final DeleteMethod method = new DeleteMethod(requestURI.toString());
    if (cookie) {
        method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    }
    if (StringHelper.containsNonWhitespace(accept)) {
        method.addRequestHeader("Accept", accept);
    }
    return method;
}
 
Example #22
Source File: CourseGroupMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteCourseGroup() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g1.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    method.releaseConnection();
    assertEquals(200, code);

    final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false);
    assertNull(bg);
}
 
Example #23
Source File: GroupMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteCourseGroup() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final String request = "/groups/" + g1.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false);
    assertNull(bg);
}
 
Example #24
Source File: UserMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteUser() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    // delete an authentication token
    final String request = "/users/" + id2.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);
    method.releaseConnection();

    final Identity deletedIdent = securityManager.loadIdentityByKey(id2.getKey());
    assertNotNull(deletedIdent);// Identity aren't deleted anymore
    assertEquals(Identity.STATUS_DELETED, deletedIdent.getStatus());
}
 
Example #25
Source File: ZeppelinServerMock.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
protected static DeleteMethod httpDelete(String path, String user, String pwd)
    throws IOException {
  LOG.info("Connecting to {}", URL + path);
  HttpClient httpClient = new HttpClient();
  DeleteMethod deleteMethod = new DeleteMethod(URL + path);
  deleteMethod.addRequestHeader("Origin", URL);
  if (userAndPasswordAreNotBlank(user, pwd)) {
    deleteMethod.setRequestHeader("Cookie", "JSESSIONID=" + getCookie(user, pwd));
  }
  httpClient.executeMethod(deleteMethod);
  LOG.info("{} - {}", deleteMethod.getStatusCode(), deleteMethod.getStatusText());
  return deleteMethod;
}
 
Example #26
Source File: OlatJerseyTestCase.java    From olat with Apache License 2.0 5 votes vote down vote up
public DeleteMethod createDelete(final URI requestURI, final String accept, final boolean cookie) {
    final DeleteMethod method = new DeleteMethod(requestURI.toString());
    if (cookie) {
        method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
    }
    if (StringHelper.containsNonWhitespace(accept)) {
        method.addRequestHeader("Accept", accept);
    }
    return method;
}
 
Example #27
Source File: UserMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteUser() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    // delete an authentication token
    final String request = "/users/" + id2.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_XML, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);
    method.releaseConnection();

    final Identity deletedIdent = securityManager.loadIdentityByKey(id2.getKey());
    assertNotNull(deletedIdent);// Identity aren't deleted anymore
    assertEquals(Identity.STATUS_DELETED, deletedIdent.getStatus());
}
 
Example #28
Source File: GroupMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteCourseGroup() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final String request = "/groups/" + g1.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    assertEquals(code, 200);

    final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false);
    assertNull(bg);
}
 
Example #29
Source File: CourseGroupMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteCourseGroup() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g1.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    method.releaseConnection();
    assertEquals(200, code);

    final BusinessGroup bg = businessGroupService.loadBusinessGroup(g1.getKey(), false);
    assertNull(bg);
}
 
Example #30
Source File: CourseGroupMgmtITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicSecurityDeleteCall() throws IOException {
    final HttpClient c = loginWithCookie("rest-c-g-3", "A6B7C8");

    final String request = "/repo/courses/" + course.getResourceableId() + "/groups/" + g2.getKey();
    final DeleteMethod method = createDelete(request, MediaType.APPLICATION_JSON, true);
    final int code = c.executeMethod(method);
    method.releaseConnection();

    assertEquals(401, code);
}