Java Code Examples for org.apache.commons.httpclient.methods.PutMethod#setQueryString()

The following examples show how to use org.apache.commons.httpclient.methods.PutMethod#setQueryString() . 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: CatalogITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicSecurityPutCall() throws IOException {
    final HttpClient c = loginWithCookie("rest-catalog-two", "A6B7C8");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Not-sub-entry-3"), new NameValuePair("description", "Not-sub-entry-description-3"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) });

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

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    boolean saved = false;
    for (final CatalogEntry child : children) {
        if ("Not-sub-entry-3".equals(child.getName())) {
            saved = true;
            break;
        }
    }

    assertFalse(saved);
}
 
Example 2
Source File: CatalogITCase.java    From olat with Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicSecurityPutCall() throws IOException {
    final HttpClient c = loginWithCookie("rest-catalog-two", "A6B7C8");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Not-sub-entry-3"), new NameValuePair("description", "Not-sub-entry-description-3"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) });

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

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    boolean saved = false;
    for (final CatalogEntry child : children) {
        if ("Not-sub-entry-3".equals(child.getName())) {
            saved = true;
            break;
        }
    }

    assertFalse(saved);
}
 
Example 3
Source File: StopAppCommand.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public ServerStatus _doIt() {
	try {
		URI targetURI = URIUtil.toURI(target.getUrl());

		String appUrl = this.app.getAppJSON().getString("url");
		URI appURI = targetURI.resolve(appUrl);

		PutMethod stopMethod = new PutMethod(appURI.toString());
		ServerStatus confStatus = HttpUtil.configureHttpMethod(stopMethod, target.getCloud());
		if (!confStatus.isOK())
			return confStatus;
		
		stopMethod.setQueryString("inline-relations-depth=1");

		JSONObject stopComand = new JSONObject();
		stopComand.put("console", true);
		stopComand.put("state", "STOPPED");
		StringRequestEntity requestEntity = new StringRequestEntity(stopComand.toString(), CFProtocolConstants.JSON_CONTENT_TYPE, "UTF-8");
		stopMethod.setRequestEntity(requestEntity);

		GetAppCommand.expire(target, app.getName());
		return HttpUtil.executeMethod(stopMethod);
	} 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 4
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdminCanEditCourse() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-admin-0"),
            new NameValuePair("longTitle", "Structure-long-admin-0"), new NameValuePair("objectives", "Structure-objectives-admin-0") });
    final int code = c.executeMethod(method);
    assertEquals(200, code);
}
 
Example 5
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testIdCannotEditCourse() throws IOException {
    final HttpClient c = loginWithCookie("id-c-s-0", "A6B7C8");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-id-0"),
            new NameValuePair("longTitle", "Structure-long-id-0"), new NameValuePair("objectives", "Structure-objectives-id-0") });
    final int code = c.executeMethod(method);
    assertEquals(401, code);
}
 
Example 6
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthorCannotEditCourse() throws IOException {
    // author but not owner
    final HttpClient c = loginWithCookie("id-c-s-1", "A6B7C8");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-id-0"),
            new NameValuePair("longTitle", "Structure-long-id-0"), new NameValuePair("objectives", "Structure-objectives-id-0") });
    final int code = c.executeMethod(method);
    assertEquals(401, code);
}
 
Example 7
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthorCanEditCourse() throws IOException {
    // author and owner
    final HttpClient c = loginWithCookie("id-c-s-2", "A6B7C8");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-id-0"),
            new NameValuePair("longTitle", "Structure-long-id-0"), new NameValuePair("objectives", "Structure-objectives-id-0") });
    final int code = c.executeMethod(method);
    assertEquals(200, code);
}
 
Example 8
Source File: CatalogITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutCategoryQuery() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Sub-entry-2"), new NameValuePair("description", "Sub-entry-description-2"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) });

    final int code = c.executeMethod(method);
    assertEquals(200, code);
    final String body = method.getResponseBodyAsString();
    method.releaseConnection();
    final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
    assertNotNull(vo);

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    boolean saved = false;
    for (final CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            saved = true;
            break;
        }
    }

    assertTrue(saved);
}
 
Example 9
Source File: CatalogITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutCatalogEntryQuery() throws IOException {
    final RepositoryEntry re = createRepository("put-cat-entry-query", 6458439l);

    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Sub-entry-2"), new NameValuePair("description", "Sub-entry-description-2"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)), new NameValuePair("repoEntryKey", re.getKey().toString()) });

    final int code = c.executeMethod(method);
    assertEquals(200, code);
    final String body = method.getResponseBodyAsString();
    method.releaseConnection();
    final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
    assertNotNull(vo);

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    CatalogEntry ce = null;
    for (final CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            ce = child;
            break;
        }
    }

    assertNotNull(ce);
    assertNotNull(ce.getRepositoryEntry());
    assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
}
 
Example 10
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testAdminCanEditCourse() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-admin-0"),
            new NameValuePair("longTitle", "Structure-long-admin-0"), new NameValuePair("objectives", "Structure-objectives-admin-0") });
    final int code = c.executeMethod(method);
    assertEquals(200, code);
}
 
Example 11
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testIdCannotEditCourse() throws IOException {
    final HttpClient c = loginWithCookie("id-c-s-0", "A6B7C8");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-id-0"),
            new NameValuePair("longTitle", "Structure-long-id-0"), new NameValuePair("objectives", "Structure-objectives-id-0") });
    final int code = c.executeMethod(method);
    assertEquals(401, code);
}
 
Example 12
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthorCannotEditCourse() throws IOException {
    // author but not owner
    final HttpClient c = loginWithCookie("id-c-s-1", "A6B7C8");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-id-0"),
            new NameValuePair("longTitle", "Structure-long-id-0"), new NameValuePair("objectives", "Structure-objectives-id-0") });
    final int code = c.executeMethod(method);
    assertEquals(401, code);
}
 
Example 13
Source File: CourseSecurityITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthorCanEditCourse() throws IOException {
    // author and owner
    final HttpClient c = loginWithCookie("id-c-s-2", "A6B7C8");

    // create an structure node
    final URI newStructureUri = getElementsUri(course).path("structure").build();
    final PutMethod method = createPut(newStructureUri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("position", "0"), new NameValuePair("shortTitle", "Structure-id-0"),
            new NameValuePair("longTitle", "Structure-long-id-0"), new NameValuePair("objectives", "Structure-objectives-id-0") });
    final int code = c.executeMethod(method);
    assertEquals(200, code);
}
 
Example 14
Source File: CatalogITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutCategoryQuery() throws IOException {
    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Sub-entry-2"), new NameValuePair("description", "Sub-entry-description-2"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)) });

    final int code = c.executeMethod(method);
    assertEquals(200, code);
    final String body = method.getResponseBodyAsString();
    method.releaseConnection();
    final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
    assertNotNull(vo);

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    boolean saved = false;
    for (final CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            saved = true;
            break;
        }
    }

    assertTrue(saved);
}
 
Example 15
Source File: CatalogITCase.java    From olat with Apache License 2.0 5 votes vote down vote up
@Test
public void testPutCatalogEntryQuery() throws IOException {
    final RepositoryEntry re = createRepository("put-cat-entry-query", 6458439l);

    final HttpClient c = loginWithCookie("administrator", "olat");

    final URI uri = UriBuilder.fromUri(getContextURI()).path("catalog").path(entry1.getKey().toString()).build();
    final PutMethod method = createPut(uri, MediaType.APPLICATION_JSON, true);
    method.setQueryString(new NameValuePair[] { new NameValuePair("name", "Sub-entry-2"), new NameValuePair("description", "Sub-entry-description-2"),
            new NameValuePair("type", String.valueOf(CatalogEntry.TYPE_NODE)), new NameValuePair("repoEntryKey", re.getKey().toString()) });

    final int code = c.executeMethod(method);
    assertEquals(200, code);
    final String body = method.getResponseBodyAsString();
    method.releaseConnection();
    final CatalogEntryVO vo = parse(body, CatalogEntryVO.class);
    assertNotNull(vo);

    final List<CatalogEntry> children = catalogService.getChildrenOf(entry1);
    CatalogEntry ce = null;
    for (final CatalogEntry child : children) {
        if (vo.getKey().equals(child.getKey())) {
            ce = child;
            break;
        }
    }

    assertNotNull(ce);
    assertNotNull(ce.getRepositoryEntry());
    assertEquals(re.getKey(), ce.getRepositoryEntry().getKey());
}
 
Example 16
Source File: UpdateApplicationCommand.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected ServerStatus _doIt() {
	try {
		// get stack object
		Object stackId = JSONObject.NULL;
		if (stack != null) {
			GetStackByNameCommand getStackCommand = new GetStackByNameCommand(target, stack);
			ServerStatus getStackStatus = (ServerStatus) getStackCommand.doIt();
			if (!getStackStatus.isOK())
				return getStackStatus;
			if (getStackCommand.getStack() == null)
				return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Stack {0} not found", stack), null);
			stackId = getStackCommand.getStack().getGuid();
		}

		/* get application URL */
		URI targetURI = URIUtil.toURI(target.getUrl());
		URI appURI = targetURI.resolve(application.getAppJSON().getString(CFProtocolConstants.V2_KEY_URL));

		PutMethod updateApplicationMethod = new PutMethod(appURI.toString());
		ServerStatus confStatus = HttpUtil.configureHttpMethod(updateApplicationMethod, target.getCloud());
		if (!confStatus.isOK())
			return confStatus;

		updateApplicationMethod.setQueryString("async=true&inline-relations-depth=1"); //$NON-NLS-1$

		/* set request body */
		JSONObject updateAppRequest = new JSONObject();
		updateAppRequest.put(CFProtocolConstants.V2_KEY_NAME, appName);
		updateAppRequest.put(CFProtocolConstants.V2_KEY_INSTANCES, appInstances);
		updateAppRequest.put(CFProtocolConstants.V2_KEY_COMMAND, appCommand);
		updateAppRequest.put(CFProtocolConstants.V2_KEY_MEMORY, appMemory);
		updateAppRequest.put(CFProtocolConstants.V2_KEY_ENVIRONMENT_JSON, env != null ? env : new JSONObject());
		updateAppRequest.put(CFProtocolConstants.V2_KEY_BUILDPACK, buildPack != null ? buildPack : JSONObject.NULL);
		updateAppRequest.put(CFProtocolConstants.V2_KEY_STACK_GUID, stackId);

		updateApplicationMethod.setRequestEntity(new StringRequestEntity(updateAppRequest.toString(), "application/json", "utf-8")); //$NON-NLS-1$ //$NON-NLS-2$

		ServerStatus status = HttpUtil.executeMethod(updateApplicationMethod);
		if (!status.isOK())
			return status;
		GetAppCommand.expire(target, application.getName());
		return status;

	} 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);
	}
}