List of usage examples for org.apache.commons.httpclient HttpStatus SC_METHOD_NOT_ALLOWED
int SC_METHOD_NOT_ALLOWED
To view the source code for org.apache.commons.httpclient HttpStatus SC_METHOD_NOT_ALLOWED.
Click Source Link
From source file:hudson.plugins.matrix_configuration_parameter.MatrixCombinationsJenkinsRule.java
/** * Get Web Client that allows 405 Method Not Allowed. * This happens when accessing build page of a project with parameters. * // w w w . j a va 2s . c om * @return WebClient */ public WebClient createAllow405WebClient() { return new WebClient() { private static final long serialVersionUID = 2209855651713458482L; @Override public void throwFailingHttpStatusCodeExceptionIfNecessary(WebResponse webResponse) { if (webResponse.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { // allow 405. return; } super.throwFailingHttpStatusCodeExceptionIfNecessary(webResponse); } @Override public void printContentIfNecessary(WebResponse webResponse) { if (webResponse.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { // allow 405. return; } super.printContentIfNecessary(webResponse); } }; }
From source file:jp.ikedam.jenkins.plugins.pagedecorator.testutils.PageDecoratorJenkinsRule.java
/** * Get Web Client that allows 405 Method Not Allowed. * This happens when accessing build page of a project with parameters. * //from ww w . ja v a2s .c om * @return WebClient */ public WebClient createAllow405WebClient() { return new WebClient() { private static final long serialVersionUID = 8593017011781195503L; @Override public void throwFailingHttpStatusCodeExceptionIfNecessary(WebResponse webResponse) { if (webResponse.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { // allow 405. return; } super.throwFailingHttpStatusCodeExceptionIfNecessary(webResponse); } @Override public void printContentIfNecessary(WebResponse webResponse) { if (webResponse.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { // allow 405. return; } super.printContentIfNecessary(webResponse); } }; }
From source file:jp.ikedam.jenkins.plugins.extensible_choice_parameter.ExtensibleChoiceParameterJenkinsRule.java
/** * Get Web Client that allows 405 Method Not Allowed. * This happens when accessing build page of a project with parameters. * /* w ww . ja v a 2s.co m*/ * @return WebClient */ public WebClient createAllow405WebClient() { return new WebClient() { private static final long serialVersionUID = -7231209645303821638L; @Override public void throwFailingHttpStatusCodeExceptionIfNecessary(WebResponse webResponse) { if (webResponse.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { // allow 405. return; } super.throwFailingHttpStatusCodeExceptionIfNecessary(webResponse); } @Override public void printContentIfNecessary(WebResponse webResponse) { if (webResponse.getStatusCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { // allow 405. return; } super.printContentIfNecessary(webResponse); } }; }
From source file:com.moss.bdbadmin.openejb.BdbAdminOpenEjbAdapter.java
public void onMessage(final HttpRequest request, final HttpResponse response) throws Exception { final IdProof assertion; {/*from w ww.ja v a 2 s . com*/ IdProof a = null; String value = request.getHeader(AuthenticationHeader.HEADER_NAME); if (value != null && value.length() > 0) { try { a = AuthenticationHeader.decode(value); } catch (Exception ex) { ex.printStackTrace(); a = null; } } else { System.out.println("No assertion included in request header"); a = null; } assertion = a; } final ServiceResource resource; { String path; if (request.getURI().getPath().length() >= contextPath.length()) { path = request.getURI().getPath().substring(contextPath.length()).trim(); } else { path = request.getURI().getPath(); } ServiceResource r = null; ; try { r = service.resolve(path); } catch (ResourcePathException ex) { ex.printStackTrace(); } resource = r; } if (assertion == null || resource == null) { response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } else { abstract class Handler { abstract void handle() throws Exception; } Handler handler = resource.acceptVisitor(new ServiceResourceVisitor<Handler>() { public Handler visit(BdbMapResource map) { return new Handler() { public void handle() throws IdProovingException, NotAuthorizedException, IOException { if ("OPTIONS".equals(request.getMethod().name())) { byte[] data = service.map(assertion); response.setHeader("Content-Length", Integer.toString(data.length)); response.getOutputStream().write(data); response.setStatusCode(HttpStatus.SC_OK); } else { response.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED); } } }; } public Handler visit(BdbCategory category) { return null; } public Handler visit(BdbEnv env) { return null; } public Handler visit(final BdbDb db) { return new Handler() { public void handle() throws IdProovingException, NotAuthorizedException, IOException { if ("GET".equals(request.getMethod().name())) { byte[] data = service.dbInfo(assertion, db); response.setHeader("Content-Length", Integer.toString(data.length)); response.getOutputStream().write(data); response.setStatusCode(HttpStatus.SC_OK); } else if ("DELETE".equals(request.getMethod().name())) { service.clearDb(assertion, db); response.setStatusCode(HttpStatus.SC_OK); } else { response.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED); } } }; } public Handler visit(final BdbEntityResource entity) { return new Handler() { public void handle() throws IdProovingException, NotAuthorizedException, IOException { if ("OPTIONS".equals(request.getMethod().name())) { byte[] data = service.entryInfo(assertion, entity); if (data == null) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); } else { response.setHeader("Content-Length", Integer.toString(data.length)); response.getOutputStream().write(data); response.setStatusCode(HttpStatus.SC_OK); } } else if ("GET".equals(request.getMethod().name())) { byte[] data = service.getEntry(assertion, entity); if (data == null) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); } else { response.setHeader("Content-Length", Integer.toString(data.length)); response.getOutputStream().write(data); response.setStatusCode(HttpStatus.SC_OK); } } else if ("HEAD".equals(request.getMethod().name())) { byte[] data = service.getEntry(assertion, entity); if (data == null) { response.setStatusCode(HttpStatus.SC_NOT_FOUND); } else { response.setStatusCode(HttpStatus.SC_OK); } } else if ("PUT".equals(request.getMethod().name())) { byte[] input; { InputStream in = request.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buffer = new byte[1023 * 10]; //10k buffer for (int numRead = in.read(buffer); numRead != -1; numRead = in.read(buffer)) { out.write(buffer, 0, numRead); } in.close(); out.close(); input = out.toByteArray(); } service.putEntry(assertion, entity, input); response.setStatusCode(HttpStatus.SC_OK); } else if ("DELETE".equals(request.getMethod().name())) { if (service.deleteEntry(assertion, entity)) { response.setStatusCode(HttpStatus.SC_OK); } else { response.setStatusCode(HttpStatus.SC_NOT_FOUND); } } else { response.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED); } } }; } }); if (handler == null) { System.out.println("Cannot perform any methods on requested path"); response.setStatusCode(HttpStatus.SC_METHOD_NOT_ALLOWED); } else { try { handler.handle(); } catch (IdProovingException ex) { ex.printStackTrace(); response.setStatusCode(HttpStatus.SC_BAD_REQUEST); } catch (NotAuthorizedException ex) { ex.printStackTrace(); response.setStatusCode(HttpStatus.SC_UNAUTHORIZED); } catch (Exception ex) { throw new ServletException(ex); } } } response.getOutputStream().close(); }
From source file:com.google.collide.server.fe.WebFE.java
/** * Writes cookies for the session ID that is posted to it. *///from w w w . j av a2 s . c om private void writeSessionCookie(final HttpServerRequest req) { if (!"POST".equals(req.method)) { sendStatusCode(req, HttpStatus.SC_METHOD_NOT_ALLOWED); return; } // Extract the post data. req.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer buff) { String contentType = req.headers().get("Content-Type"); if ("application/x-www-form-urlencoded".equals(contentType)) { QueryStringDecoder qsd = new QueryStringDecoder(buff.toString(), false); Map<String, List<String>> params = qsd.getParameters(); List<String> loginSessionIdList = params.get(JsonFieldConstants.SESSION_USER_ID); List<String> usernameList = params.get(JsonFieldConstants.SESSION_USERNAME); if (loginSessionIdList == null || loginSessionIdList.size() == 0 || usernameList == null || usernameList.size() == 0) { sendStatusCode(req, 400); return; } final String sessionId = loginSessionIdList.get(0); final String username = usernameList.get(0); vertx.eventBus().send("participants.authorise", new JsonObject().putString("sessionID", sessionId).putString("username", username), new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if ("ok".equals(event.body.getString("status"))) { req.response.headers().put("Set-Cookie", AUTH_COOKIE_NAME + "=" + sessionId + "__" + username + "; HttpOnly"); sendStatusCode(req, HttpStatus.SC_OK); } else { sendStatusCode(req, HttpStatus.SC_FORBIDDEN); } } }); } else { sendRedirect(req, "/static/login.html"); } } }); }
From source file:com.idega.slide.business.FileSystemCopyServiceBean.java
private void handleException(Exception ex) { if (ex instanceof HttpException) { if (((HttpException) ex).getReasonCode() == HttpStatus.SC_METHOD_NOT_ALLOWED) { System.out.println("Warning: Not WebDAV-enabled?"); } else if (((HttpException) ex).getReasonCode() == HttpStatus.SC_UNAUTHORIZED) { System.out.println("Warning: Unauthorized"); } else {//www . ja va 2 s . c o m System.out.println("Warning: " + ex.getMessage()); } } else if (ex instanceof IOException) { System.out.println("Error: " + ex.getMessage()); } else { System.out.println("Fatal Error: " + ex.getMessage()); ex.printStackTrace(System.out); System.out.println("Please, email to slide-user@jakarta.apache.org"); } }
From source file:org.alfresco.rest.api.tests.TestActivities.java
@Test public void testPersonActivities() throws Exception { People peopleProxy = publicApiClient.people(); //Test with default tenant domain. see ALF-20448 {//from w w w . j a v a 2s . c o m List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person5.getId(), null, false, true); return activities; } }, person5.getId(), defaultNetwork.getId()); for (Activity activity : expectedActivities) { if (activity.getSiteId() == null) { fail("SiteId should present in user-joined activity."); } } { int skipCount = 0; int maxItems = expectedActivities.size(); Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("who", String.valueOf(ActivityWho.me)); publicApiClient.setRequestContext(new RequestContext(defaultNetwork.getId(), person5.getId())); ListResponse<Activity> response = peopleProxy.getActivities(person5.getId(), params); checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response); } } // Test Case cloud-2204 // Test case cloud-1500 // Test Case cloud-2216 // paging // Test Case cloud-1500 { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); return activities; } }, person1.getId(), network1.getId()); { int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("who", String.valueOf(ActivityWho.me)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params); checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response); } { int skipCount = 2; int maxItems = expectedActivities.size() - 2; assertTrue(maxItems > 0); Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("who", String.valueOf(ActivityWho.me)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params); checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response); } // "-me-" user { int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("who", String.valueOf(ActivityWho.me)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Activity> response = peopleProxy .getActivities(org.alfresco.rest.api.People.DEFAULT_USER, params); checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response); } } // unknown user - 404 try { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); return activities; } }, person1.getId(), network1.getId()); int skipCount = 0; int maxItems = 2; publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); peopleProxy.getActivities(GUID.generate(), createParams(paging, null)); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // unknown site - 404 try { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); return activities; } }, person1.getId(), network1.getId()); int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("siteId", GUID.generate()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.getActivities(GUID.generate(), params); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // user from another network - 404 try { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); return activities; } }, person1.getId(), network1.getId()); int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person3.getId())); peopleProxy.getActivities(person1.getId(), createParams(paging, null)); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_UNAUTHORIZED, e.getHttpResponse().getStatusCode()); } // another user from the same network - 403 try { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); return activities; } }, person1.getId(), network1.getId()); int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person2.getId())); peopleProxy.getActivities(person1.getId(), createParams(paging, null)); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_FORBIDDEN, e.getHttpResponse().getStatusCode()); } try { List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); return activities; } }, person1.getId(), network1.getId()); assertTrue(activities.size() > 0); Activity activity = activities.get(0); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.remove("people", person1.getId(), "activities", String.valueOf(activity.getId()), "Unable to DELETE a person activity"); fail(""); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } // Test Case cloud-1500 // other user activities { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> expectedActivities = repoService.getActivities(person1.getId(), null, true, false); return expectedActivities; } }, person1.getId(), network1.getId()); int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("who", String.valueOf(ActivityWho.others)); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params); checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response); } // all activities with siteId exclusion { List<Activity> expectedActivities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> expectedActivities = repoService.getActivities(person1.getId(), testSite.getSiteId(), false, false); return expectedActivities; } }, person1.getId(), network1.getId()); int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems, expectedActivities.size(), null); Map<String, String> params = createParams(paging, null); params.put("siteId", testSite.getSiteId()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); ListResponse<Activity> response = peopleProxy.getActivities(person1.getId(), params); checkList(expectedActivities.subList(skipCount, skipCount + paging.getExpectedPaging().getCount()), paging.getExpectedPaging(), response); } // all activities with siteId exclusion, unknown site id try { int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems); Map<String, String> params = createParams(paging, null); params.put("siteId", GUID.generate()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.getActivities(person1.getId(), params); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // unknown person id try { int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems); Map<String, String> params = createParams(paging, null); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.getActivities(GUID.generate(), params); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // invalid who parameter try { int skipCount = 0; int maxItems = 2; Paging paging = getPaging(skipCount, maxItems); Map<String, String> params = createParams(paging, null); params.put("who", GUID.generate()); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.getActivities(person1.getId(), params); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); } // Test Case cloud-1970 // Not allowed methods // try // { // publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); // peopleProxy.create("people", person1.getId(), "activities", null, null, "Unable to POST to person activities"); // fail(""); // } // catch(PublicApiException e) // { // assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); // } // // try // { // publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); // peopleProxy.update("people", person1.getId(), "activities", null, null, "Unable to PUT person activities"); // fail(""); // } // catch(PublicApiException e) // { // assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); // } // // try // { // publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); // peopleProxy.remove("people", person1.getId(), "activities", null, "Unable to DELETE person activities"); // fail(""); // } // catch(PublicApiException e) // { // assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); // } // // try // { // List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() // { // @Override // public List<Activity> doWork() throws Exception // { // List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); // return activities; // } // }, person1.getId(), network1.getId()); // assertTrue(activities.size() > 0); // Activity activity = activities.get(0); // // publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); // peopleProxy.create("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to POST to a person activity"); // fail(""); // } // catch(PublicApiException e) // { // assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); // } // // try // { // List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() // { // @Override // public List<Activity> doWork() throws Exception // { // List<Activity> activities = repoService.getActivities(person1.getId(), null, false, true); // return activities; // } // }, person1.getId(), network1.getId()); // assertTrue(activities.size() > 0); // Activity activity = activities.get(0); // // publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); // peopleProxy.update("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to PUT a person activity"); // fail(""); // } // catch(PublicApiException e) // { // assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); // } // Test Case cloud-1970 // not allowed methods { List<Activity> activities = TenantUtil.runAsUserTenant(new TenantRunAsWork<List<Activity>>() { @Override public List<Activity> doWork() throws Exception { List<Activity> activities = repoService.getActivities(person1.getId(), null, false, false); return activities; } }, person1.getId(), network1.getId()); assertTrue(activities.size() > 0); Activity activity = activities.get(0); try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.create("people", person1.getId(), "activities", null, null, "Unable to POST to activities"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.create("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to POST to an activity"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.update("people", person1.getId(), "activities", null, null, "Unable to PUT activities"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.update("people", person1.getId(), "activities", String.valueOf(activity.getId()), null, "Unable to PUT an activity"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.remove("people", person1.getId(), "activities", null, "Unable to DELETE activities"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person1.getId())); peopleProxy.remove("people", person1.getId(), "activities", String.valueOf(activity.getId()), "Unable to DELETE an activity"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } } }
From source file:org.alfresco.rest.api.tests.TestCMIS.java
public void testInvalidMethods() throws Exception { final TestNetwork network1 = getTestFixture().getRandomNetwork(); Iterator<String> personIt = network1.getPersonIds().iterator(); final String person = personIt.next(); assertNotNull(person);//from w w w .j av a2 s . co m try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person)); publicApiClient.post(Binding.atom, CMIS_VERSION_10, null, null); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person)); publicApiClient.head(Binding.atom, CMIS_VERSION_10, null, null); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person)); publicApiClient.options(Binding.atom, CMIS_VERSION_10, null, null); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person)); publicApiClient.trace(Binding.atom, CMIS_VERSION_10, null, null); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person)); publicApiClient.patch(Binding.atom, CMIS_VERSION_10, null, null); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } }
From source file:org.alfresco.rest.api.tests.TestFavourites.java
private void updateFavourite(String networkId, String runAsUserId, String personId, TARGET_TYPE type) throws Exception { {// w w w. ja v a2 s . c om int size = 0; try { // get a favourite id ListResponse<Favourite> resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); List<Favourite> favourites = resp.getList(); size = favourites.size(); assertTrue(size > 0); Favourite favourite = favourites.get(0); favouritesProxy.update("people", personId, "favorites", favourite.getTargetGuid(), favourite.toJSON().toString(), "Unable to update favourite"); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } // check nothing has changed ListResponse<Favourite> resp = getFavourites(networkId, runAsUserId, personId, 0, Integer.MAX_VALUE, null, null, type); List<Favourite> favourites = resp.getList(); assertEquals(size, favourites.size()); } }
From source file:org.alfresco.rest.api.tests.TestFavourites.java
@Test public void testInvalidRequests() throws Exception { try {/*from www . java 2 s . c om*/ publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); Favourite favourite = makeSiteFavourite(person1PublicSites.get(0)); Favourite ret = favouritesProxy.createFavourite(person11Id, favourite); favourite.expected(ret); fail(); } catch (PublicApiException e) { // Note: un-authorized comes back as 404 assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // cloud-2468 // invalid type // NOTE: The test below has swapped to attempt to favorite a comment rather than a // a wiki page as the WikiService has moved to the Share Services AMP in 5.1 try { log("cloud-2468"); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); final NodeRef document = personDocs.get(0); final NodeRef comment = TenantUtil.runAsUserTenant(new TenantRunAsWork<NodeRef>() { @Override public NodeRef doWork() throws Exception { NodeRef comment = repoService.createComment(document, new Comment("Title", "Content")); return comment; } }, person10Id, network1.getId()); final String guid = comment.getId(); JSONAble commentJSON = new JSONAble() { @SuppressWarnings("unchecked") @Override public JSONObject toJSON() { JSONObject json = new JSONObject(); json.put("guid", guid); return json; } }; FavouritesTarget target = new InvalidFavouriteTarget("comment", commentJSON, guid); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); } try { log("cloud-2468"); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); Site site = person1PublicSites.get(0); FavouritesTarget target = new InvalidFavouriteTarget(GUID.generate(), site, site.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); } // type = file, target is a site try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); String siteGuid = person1PublicSites.get(0).getGuid(); FavouriteDocument document = new FavouriteDocument(siteGuid); Favourite favourite = makeFileFavourite(document.getGuid()); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); favourite.expected(ret); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // type = folder, target is a site try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); String siteGuid = person1PublicSites.get(0).getGuid(); FavouriteFolder folder = new FavouriteFolder(siteGuid); Favourite favourite = makeFolderFavourite(folder.getGuid()); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); favourite.expected(ret); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // type = folder, target is a file try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouriteFolder folder = new FavouriteFolder(person1PublicDocs.get(0).getId()); Favourite favourite = makeFolderFavourite(folder.getGuid()); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); favourite.expected(ret); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // type = file, target is a folder try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouriteDocument document = new FavouriteDocument(person1PublicFolders.get(0).getId()); Favourite favourite = makeFileFavourite(document.getGuid()); Favourite ret = favouritesProxy.createFavourite(person10Id, favourite); favourite.expected(ret); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // make sure that a user can't favourite on behalf of another user // 2471 { log("cloud-2471"); try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); Favourite favourite = makeFileFavourite(document.getGuid()); favouritesProxy.createFavourite(person11Id, favourite); fail(); } catch (PublicApiException e) { // Note: un-authorized comes back as 404 assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // person1 should have no favourites publicApiClient.setRequestContext(new RequestContext(network1.getId(), person11Id)); ListResponse<Favourite> response = favouritesProxy.getFavourites(person11Id, createParams(null, null)); assertEquals(0, response.getList().size()); } // invalid/non-existent user // 2469 try { log("cloud-2469"); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); Favourite favourite = makeSiteFavourite(personSites.get(0)); Favourite ret = favouritesProxy.createFavourite(GUID.generate(), favourite); favourite.expected(ret); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // make sure that a user can't see other user's favourites. // 2465 try { log("cloud-2465"); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); favouritesProxy.getFavourites(person11Id, null); fail(); } catch (PublicApiException e) { // Note: un-authorized comes back as 404 assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // 2464, unknown user try { log("cloud-2464"); publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); favouritesProxy.getFavourites(GUID.generate(), null); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } // non-existent entity for a given type // 2480 { log("cloud-2480"); try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); SiteImpl site = new SiteImpl(); site.setGuid(GUID.generate()); Favourite favourite = makeSiteFavourite((Site) site); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); assertEquals(0, response.getList().size()); } { try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouriteDocument document = new FavouriteDocument(GUID.generate()); Favourite favourite = makeFileFavourite(document.getGuid()); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); assertEquals(0, response.getList().size()); } { try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouriteFolder folder = new FavouriteFolder(GUID.generate()); Favourite favourite = makeFolderFavourite(folder.getGuid()); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); assertEquals(0, response.getList().size()); } // 2470 // incorrect type for a given favourite target { log("cloud-2470"); try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); Site site = person1PublicSites.get(0); FavouritesTarget target = new InvalidFavouriteTarget("folder", site, site.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); Site site = person1PublicSites.get(0); FavouritesTarget target = new InvalidFavouriteTarget("file", site, site.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_BAD_REQUEST, e.getHttpResponse().getStatusCode()); } FavouriteDocument document = new FavouriteDocument(person1PublicDocs.get(0).getId()); try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouritesTarget target = new InvalidFavouriteTarget("site", document, document.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouritesTarget target = new InvalidFavouriteTarget("folder", document, document.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } FavouriteFolder folder = new FavouriteFolder(person1PublicFolders.get(0).getId()); try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouritesTarget target = new InvalidFavouriteTarget("site", folder, folder.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } try { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); FavouritesTarget target = new InvalidFavouriteTarget("file", folder, folder.getGuid()); Favourite favourite = new Favourite(target); favouritesProxy.createFavourite(person10Id, favourite); fail(); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_NOT_FOUND, e.getHttpResponse().getStatusCode()); } publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); // none of these POSTs should have resulted in favourites being created... ListResponse<Favourite> response = favouritesProxy.getFavourites(person10Id, createParams(null, null)); assertEquals(0, response.getList().size()); } // invalid methods { publicApiClient.setRequestContext(new RequestContext(network1.getId(), person10Id)); try { Favourite favourite = new Favourite(null); favouritesProxy.update("people", "-me-", "favorites", null, favourite.toJSON().toString(), "Unable to PUT favourites"); } catch (PublicApiException e) { assertEquals(HttpStatus.SC_METHOD_NOT_ALLOWED, e.getHttpResponse().getStatusCode()); } } }