Examples of RestAPI


Examples of org.drools.guvnor.server.files.RestAPI

        ByteArrayInputStream in = new ByteArrayInputStream("abc".getBytes());
        asset2.updateBinaryContentAttachment(in);
        asset2.updateFormat("xls");
        asset2.checkin("");

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        Thread.sleep(42);
        api.put("packages/testRestPut/asset1.drl", Calendar.getInstance(), new ByteArrayInputStream("qaz".getBytes()), "a new comment");

        AssetItem asset1_ = pkg.loadAsset("asset1");
        assertEquals("qaz", asset1_.getContent());
        assertEquals("a new comment", asset1_.getCheckinComment());
        assertTrue(asset1_.getLastModified().after(cd));

        api.put("packages/testRestPut/asset2.xls", Calendar.getInstance(), new ByteArrayInputStream("def".getBytes()), "a new comment");
        AssetItem asset2_ = pkg.loadAsset("asset2");
        assertEquals("def", new String(asset2_.getBinaryContentAsBytes()));
        assertEquals("a new comment", asset2_.getCheckinComment());
        assertTrue(asset2_.getLastModified().after(cd));

        //now check updating the package header
        api.put("packages/testRestPut/.package", Calendar.getInstance(), new ByteArrayInputStream("whee".getBytes()), "hey");
        pkg = repo.loadModule("testRestPut");
        assertEquals("whee", pkg.getStringProperty(ModuleItem.HEADER_PROPERTY_NAME));

        try {
            api.put("packages/testRestPut/asset1.drl", cd, new ByteArrayInputStream("qaz".getBytes()), "a new comment");
            fail("should not be able to do this as it is stale timestamp.");
        } catch (Exception e) {
            assertNotNull(e.getMessage());
        }

        try {
            api.put("packages/testRestPut/.package", cd, new ByteArrayInputStream("whee".getBytes()), "hey");
            fail("should not be able to do this as it is stale timestamp.");
        } catch (Exception e) {
            assertNotNull(e.getMessage());
        }
View Full Code Here

Examples of org.drools.guvnor.server.files.RestAPI

        AssetItem asset1 = pkg.addAsset("asset1", "");
        asset1.updateContent("this is content");
        asset1.updateFormat("drl");
        asset1.checkin("");

        RestAPI api = new RestAPI(repo);
        api.setAssetValidator(new AssetValidator());
        api.delete("packages/testRestDelete/asset1.drl");

        List l = RulesRepositoryTest.iteratorToList(pkg.listAssetsByFormat(new String[] {"drl"}));
        assertEquals(0, l.size());

        l = RulesRepositoryTest.iteratorToList(pkg.listArchivedAssets());
        assertEquals(1, l.size());


        //now test it back from the dead
        api.post("packages/testRestDelete/asset1.drl", new ByteArrayInputStream("123".getBytes()), "new comment");
        AssetItem ass = pkg.loadAsset("asset1");
        assertEquals("123", ass.getContent());
        assertEquals("new comment", ass.getCheckinComment());
        assertFalse(ass.isArchived());
        l = RulesRepositoryTest.iteratorToList(pkg.listAssetsByFormat(new String[] {"drl"}));
        assertEquals(1, l.size());

        try {
            api.post("packages/testRestDelete/asset1.drl", new ByteArrayInputStream("123".getBytes())"new comment");
            fail("this should be rejected as its not archived.");
        } catch (RulesRepositoryException e) {
            assertNotNull(e.getMessage());
        }
View Full Code Here

Examples of org.drools.guvnor.server.files.RestAPI

    }

    @Test
    public void testSplit() throws Exception {
        RestAPI a = new RestAPI(null);
        String[] x = a.split("packages/foo/bar");
        assertEquals(3, x.length);
        assertEquals("packages", x[0]);
        assertEquals("foo", x[1]);
        assertEquals("bar", x[2]);

        x = a.split("/packages/foo/bar");
        assertEquals(3, x.length);
        assertEquals("packages", x[0]);
        assertEquals("foo", x[1]);
        assertEquals("bar", x[2]);

        String p = URLEncoder.encode("some package", "UTF-8");
        String asset = URLEncoder.encode("some asset", "UTF-8");
        x = a.split("packages/" + p + "/" + asset);
        assertEquals("packages", x[0]);
        assertEquals("some package", x[1]);
        assertEquals("some asset", x[2]);


        x = a.split("http://localhost:8080/guvnor-webapp/org.dooby.doo.X.html/api/packages/foo/bar.drl");
        assertEquals(3, x.length);
        assertEquals("packages", x[0]);
        assertEquals("foo", x[1]);
        assertEquals("bar.drl", x[2]);
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        res.setContentType("text/html");
                        RestAPI api = getAPI();
                        String comment = req.getHeader("Checkin-Comment");
                        api.post(req.getRequestURI(),
                                req.getInputStream(),
                                (comment != null) ? comment : "");
                        res.getWriter().write("OK");
                    }
                });
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

            IOException {
        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        RestAPI api = getAPI();
                        String qString = req.getQueryString();
                        String ur = req.getRequestURI();
                        if (qString != null && qString.length() > 0) {
                            ur = ur + '?' + qString;
                        }
                        Response apiRes = api.get(ur);
                        res.setContentType("application/x-download");
                        res.setHeader("Content-Disposition",
                                "attachment; filename=data;");
                        apiRes.writeData(res.getOutputStream());
                        res.getOutputStream().flush();
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        res.setContentType("text/html");
                        RestAPI api = getAPI();
                        String comment = req.getHeader("Checkin-Comment");
                        Calendar lastMod = getModified(req.getHeader("Last-Modified"));
                        api.put(req.getRequestURI(),
                                lastMod,
                                req.getInputStream(),
                                (comment != null) ? comment : "");
                        res.getWriter().write("OK");
                    }
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

        doAuthorizedAction(req,
                res,
                new Command() {
                    public void execute() throws Exception {
                        res.setContentType("text/html");
                        RestAPI api = getAPI();
                        api.delete(req.getRequestURI());
                        res.getWriter().write("OK");
                    }
                });
    }
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

                    }
                });
    }

    RestAPI getAPI() {
        return new RestAPI(rulesRepository);
    }
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

                          final HttpServletResponse res) throws ServletException,
                                                       IOException {
        doAuthorizedAction(req, res, new A() {
      public void a() throws Exception {
          res.setContentType( "text/html" );
          RestAPI api = getAPI();
          String comment = req.getHeader("Checkin-Comment");
          api.post(req.getRequestURI(), req.getInputStream(), (comment != null)? comment : "");
          res.getWriter().write( "OK" );
      }
        });
    }
View Full Code Here

Examples of org.drools.repository.remoteapi.RestAPI

    protected void doGet(final HttpServletRequest req,
                         final HttpServletResponse res) throws ServletException,
                                                 IOException {
        doAuthorizedAction(req, res, new A() {
      public void a() throws Exception {
          RestAPI api = getAPI();
          String qString = req.getQueryString();
          String ur = req.getRequestURI();
          if (qString != null && qString.length() > 0) {
            ur = ur + '?' + qString;
          }
          Response apiRes = api.get(ur);
              res.setContentType( "application/x-download" );
              res.setHeader( "Content-Disposition",
                             "attachment; filename=data;");
          apiRes.writeData(res.getOutputStream());
          res.getOutputStream().flush();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.