Package com.dotcms.repackage.com.sun.jersey.api.client

Examples of com.dotcms.repackage.com.sun.jersey.api.client.ClientResponse



                //Sending bundle to endpoint
                WebResource resource = client.resource(endpoint.toURL()+"/api/bundlePublisher/publish");

                ClientResponse response =
                    resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);


                if(response.getClientResponseStatus().getStatusCode() == HttpStatus.SC_OK)
                {
                  detail.setStatus(PublishAuditStatus.Status.BUNDLE_SENT_SUCCESSFULLY.getCode());
                  detail.setInfo("Everything ok");
                } else {

                  if(currentStatusHistory.getNumTries()==PublisherQueueJob.MAX_NUM_TRIES) {
                    APILocator.getPushedAssetsAPI().deletePushedAssets(config.getId(), environment.getId());
                  }
                  detail.setStatus(PublishAuditStatus.Status.FAILED_TO_SENT.getCode());
                  detail.setInfo(
                      "Returned "+response.getClientResponseStatus().getStatusCode()+ " status code " +
                          "for the endpoint "+endpoint.getId()+ "with address "+endpoint.getAddress());
                  failedEnvironment |= true;

                }
              } catch(Exception e) {
View Full Code Here


    @Test
    public void multipartPUT() throws Exception {
        final String salt=Long.toString(System.currentTimeMillis());
        final User sysuser=APILocator.getUserAPI().getSystemUser();
       
        ClientResponse response = contRes.path("/publish/1").type(MediaType.MULTIPART_FORM_DATA_TYPE)
                                   .header(authheader, authvalue).put(ClientResponse.class,
                                           new MultiPart()
                                             .bodyPart(new BodyPart(
                                                     new JSONObject()
                                                        .put("hostFolder", "demo.dotcms.com:/resources")
                                                        .put("title", "newfile"+salt+".txt")
                                                        .put("fileName", "newfile"+salt+".txt")
                                                        .put("languageId", "1")
                                                        .put("stInode", StructureCache.getStructureByVelocityVarName("FileAsset").getInode())
                                                        .toString(), MediaType.APPLICATION_JSON_TYPE))
                                             .bodyPart(new StreamDataBodyPart(
                                                         "newfile"+salt+".txt",
                                                         new ByteArrayInputStream(("this is the salt "+salt).getBytes()),
                                                         "newfile"+salt+".txt",
                                                         MediaType.APPLICATION_OCTET_STREAM_TYPE)));
        Assert.assertEquals(200, response.getStatus());
        Contentlet cont=APILocator.getContentletAPI().find(response.getHeaders().getFirst("inode"),sysuser,false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
        Assert.assertTrue(response.getLocation().toString().endsWith("/api/content/inode/"+cont.getInode()));
        FileAsset file=APILocator.getFileAssetAPI().fromContentlet(cont);
        Assert.assertEquals("/resources/newfile"+salt+".txt",file.getURI());
        Assert.assertEquals("demo.dotcms.com", APILocator.getHostAPI().find(file.getHost(), sysuser, false).getHostname());
        Assert.assertEquals("this is the salt "+salt, IOUtils.toString(file.getFileInputStream()));
    }
View Full Code Here

    @Test
    public void categoryAndTagFields() throws Exception {
        User sysuser=APILocator.getUserAPI().getSystemUser();
        Structure st=StructureCache.getStructureByVelocityVarName("Blog");
        String salt=Long.toString(System.currentTimeMillis());
        ClientResponse response=contRes.path("/justsave/1").type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                        new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("host1", "demo.dotcms.com")
                                .put("title", "blog post "+salt)
                                .put("urlTitle", "blog-post-"+salt)
                                .put("author", "junit")
                                .put("sysPublishDate", new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss")
                                                          .format(Calendar.getInstance().getTime()))
                                .put("body","blog post content "+salt)
                                .put("topic", "investing,banking")
                                .put("tags", "junit,integration tests,jenkins")
                                .put("contentHost", "demo.dotcms.com:/home").toString());
        Assert.assertEquals(200, response.getStatus());
        String inode=response.getHeaders().getFirst("inode");
        Contentlet cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
       
        /////////////////////////
View Full Code Here

       
        // send the Rest api call
        User sysuser=APILocator.getUserAPI().getSystemUser();
        User bill=APILocator.getUserAPI().loadUserById("dotcms.org.2806");
        Role billrole=APILocator.getRoleAPI().getUserRole(bill);
        ClientResponse response=contRes.path("/Save%20and%20Assign/1/wfActionComments/please%20do%20this%20for%20me/wfActionAssign/"+billrole.getId())
            .type(MediaType.APPLICATION_JSON_TYPE)
            .header(authheader, authvalue).put(ClientResponse.class,
                new JSONObject()
                    .put("stInode", st.getInode())
                    .put("languageId", 1)
                    .put(field.getVelocityVarName(), "test title "+salt)
                    .toString());
        Assert.assertEquals(200, response.getStatus());
       
        Contentlet cont = APILocator.getContentletAPI().find(response.getHeaders().getFirst("inode"), sysuser, false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
       
        // must be in the first step
        Assert.assertEquals(step1.getId(), APILocator.getWorkflowAPI().findStepByContentlet(cont).getId());
View Full Code Here

        imga.setStringProperty(FileAssetAPI.TITLE_FIELD, "imgimg.jpg");
        imga.setBinary(FileAssetAPI.BINARY_FIELD, imgimg);
        imga.setLanguageId(1);
        imga = APILocator.getContentletAPI().checkin(imga, sysuser, false);
       
        ClientResponse response=contRes.path("/publish/1")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .header(authheader, authvalue).put(ClientResponse.class,
                new JSONObject()
                    .put("stName", st.getVelocityVarName())
                    .put(file.getVelocityVarName(),"//demo.dotcms.com/rest/"+salt+"/filefile.txt")
                    .put(image.getVelocityVarName(), "//demo.dotcms.com/rest/"+salt+"/imgimg.jpg")
                    .put(title.getVelocityVarName(), "a simple title")
                    .toString());
        Assert.assertEquals(200, response.getStatus());
       
        String inode=response.getHeaders().getFirst("inode");
        Contentlet cont = APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(filea.getIdentifier(),cont.getStringProperty(file.getVelocityVarName()));
        Assert.assertEquals(imga.getIdentifier(),cont.getStringProperty(image.getVelocityVarName()));
    }
View Full Code Here

        APILocator.getContentletAPI().isInodeIndexed(c2.getInode());
       
        Relationship rel=new Relationship(st1,st2,"st1"+salt,"st2"+salt,0,false,false);
        RelationshipFactory.saveRelationship(rel);
       
        ClientResponse response=contRes.path("/publish/1")
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                    new JSONObject()
                        .put("stName", st1.getVelocityVarName())
                        .put(title1.getVelocityVarName(), "a simple title")
                        .put(rel.getRelationTypeValue(), "+structureName:"+st2.getVelocityVarName())
                        .toString());
        Assert.assertEquals(200, response.getStatus());
       
        Thread.sleep(2000); // wait for relation fields update
       
        String inode=response.getHeaders().getFirst("inode");
        Contentlet cc=APILocator.getContentletAPI().find(inode, sysuser, false);
       
        List<Contentlet> relatedContent = APILocator.getContentletAPI().getRelatedContent(cc, rel, sysuser, false);
        Assert.assertEquals(2, relatedContent.size());
       
View Full Code Here

   
    @Test
    public void newVersion() throws Exception {
        final User sysuser=APILocator.getUserAPI().getSystemUser();
       
        ClientResponse response=contRes.path("/justSave/1")
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                    new JSONObject()
                        .put("stName", "webPageContent")
                        .put("contentHost", "demo.dotcms.com")
                        .put("title", "testing newVersion")
                        .put("body", "just testing")
                        .toString());
        Assert.assertEquals(200, response.getStatus());
       
        String inode=response.getHeaders().getFirst("inode");
       
       
        String identifier=response.getHeaders().getFirst("identifier");
       
        response=contRes.path("/justSave/1")
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                    new JSONObject()
                        .put("stName", "webPageContent")
                        .put("contentHost", "demo.dotcms.com")
                        .put("title", "testing newVersion 2")
                        .put("body", "just testing 2")
                        .put("identifier", identifier)
                        .toString());
        String inode2=response.getHeaders().getFirst("inode");
        String identifier2=response.getHeaders().getFirst("identifier");
       
        Assert.assertEquals(identifier, identifier2);
        Assert.assertNotSame(inode, inode2);
       
        Contentlet c1=APILocator.getContentletAPI().find(inode, sysuser, false);
View Full Code Here

    form.field( "ENDPOINT_ID", receivingFromEndpoint.getId() );
    form.bodyPart( new FileDataBodyPart( "bundle", newBundleFile, MediaType.MULTIPART_FORM_DATA_TYPE ) );

    //Sending bundle to endpoint
    WebResource resource = client.resource( receivingFromEndpoint.toURL() + "/api/bundlePublisher/publish" );
    ClientResponse clientResponse = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, form );
    //Validations
    assertEquals( clientResponse.getClientResponseStatus().getStatusCode(), HttpStatus.SC_OK );

    //Get current status dates
    status = PublishAuditAPI.getInstance().getPublishAuditStatus( newBundleId );//Get the audit records related to this new bundle
    Date finalCreationDate = status.getCreateDate();
    Date finalUpdateDate = status.getStatusUpdated();
View Full Code Here

    public void singlePUT() throws Exception {
        Structure st=StructureCache.getStructureByVelocityVarName("webPageContent");
        Host demo=APILocator.getHostAPI().findByName("demo.dotcms.com", APILocator.getUserAPI().getSystemUser(), false);
        User sysuser=APILocator.getUserAPI().getSystemUser();
        String demoId=demo.getIdentifier();
        ClientResponse response=
                contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
                       .header(authheader, authvalue).put(ClientResponse.class,
                                new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "Test content from ContentResourceTest")
                                .put("body", "this is an example text")
                                .put("contentHost", demoId).toString());
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
        String location=response.getLocation().toString();
        String inode=location.substring(location.lastIndexOf("/")+1);
        Contentlet cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
        Assert.assertEquals(demoId, cont.getHost());
        Assert.assertEquals(st.getInode(), cont.getStructureInode());
        Assert.assertEquals(1,cont.getLanguageId());
        Assert.assertEquals("Test content from ContentResourceTest",cont.getStringProperty("title"));
        Assert.assertEquals("this is an example text",cont.getStringProperty("body"));
        Assert.assertTrue(cont.isLive());
       
        // testing other host_or_folder formats: folderId
        Folder folder=APILocator.getFolderAPI().findFolderByPath("/home", demo, sysuser, false);
        response=contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
                       .header(authheader, authvalue).put(ClientResponse.class,
                                new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "test content with folderid")
                                .put("body", "this is an example text")
                                .put("contentHost", folder.getInode()).toString());
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(folder.getInode(), cont.getFolder());
        Assert.assertTrue(cont.isLive());
       
        // testing other host_or_folder formats: hostname
        response=contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                        new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "Test content from ContentResourceTest folderId")
                                .put("body", "this is an example text")
                                .put("contentHost", "demo.dotcms.com").toString());
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(demoId, cont.getHost());
        Assert.assertTrue(cont.isLive());
       
        // testing other host_or_folder formats: hostname:path
        response=contRes.path("/justsave/1").type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                        new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "Test content from ContentResourceTest folderId")
                                .put("body", "this is an example text")
                                .put("contentHost", "demo.dotcms.com:/home").toString());
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(folder.getInode(), cont.getFolder());
        Assert.assertFalse(cont.isLive());
       
       
        // testing XML
        response=contRes.path("/publish/1").type(MediaType.APPLICATION_XML_TYPE)
                       .header(authheader, authvalue).put(ClientResponse.class,
                            "<content>" +
                            "<stInode>" +st.getInode() + "</stInode>"+
                            "<languageId>1</languageId>"+
                            "<title>Test content from ContentResourceTest XML</title>"+
                            "<body>this is an example text XML</body>"+
                            "<contentHost>"+demoId+"</contentHost>"+
                            "</content>");
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
        Assert.assertEquals(demoId, cont.getHost());
        Assert.assertEquals(st.getInode(), cont.getStructureInode());
        Assert.assertEquals(1,cont.getLanguageId());
        Assert.assertEquals("Test content from ContentResourceTest XML",cont.getStringProperty("title"));
        Assert.assertEquals("this is an example text XML",cont.getStringProperty("body"));
        Assert.assertTrue(cont.isLive());
       
        // testing form-urlencoded
        String title="Test content from ContentResourceTest FORM "+UUIDGenerator.generateUuid();
        String body="this is an example text FORM "+UUIDGenerator.generateUuid();
        response=contRes.path("/publish/1").type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                     "stInode=" +st.getInode() + "&"+
                     "languageId=1&"+
                     "title="+URLEncoder.encode(title, "UTF-8")+"&"+
                     "body="+URLEncoder.encode(body, "UTF-8")+"&"+
                     "contentHost="+demoId);
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        Assert.assertEquals(inode, response.getHeaders().getFirst("inode")); // validate consistency of inode header
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
        Assert.assertEquals(cont.getIdentifier(), response.getHeaders().getFirst("identifier")); // consistency of identifier header
        Assert.assertEquals(demoId, cont.getHost());
        Assert.assertEquals(st.getInode(), cont.getStructureInode());
        Assert.assertEquals(1,cont.getLanguageId());
        Assert.assertEquals(title,cont.getStringProperty("title"));
        Assert.assertEquals(body,cont.getStringProperty("body"));
View Full Code Here

            //Sending bundle to endpoint
            String url = endpoint.toURL()+"/api/integrity/generateintegritydata/";
            com.dotcms.repackage.com.sun.jersey.api.client.WebResource resource = client.resource(url);

            ClientResponse response =
                    resource.type(MediaType.MULTIPART_FORM_DATA).post(ClientResponse.class, form);

            if(response.getClientResponseStatus().getStatusCode() == HttpStatus.SC_OK) {
                final String integrityDataRequestID = response.getEntity(String.class);

                Thread integrityDataRequestChecker = new Thread() {
                    public void run(){

                        FormDataMultiPart form = new FormDataMultiPart();
                        form.field("AUTH_TOKEN",authToken);
                        form.field("REQUEST_ID",integrityDataRequestID);

                        String url = endpoint.toURL()+"/api/integrity/getintegritydata/";
                        com.dotcms.repackage.com.sun.jersey.api.client.WebResource resource = client.resource(url);

                        boolean processing = true;

                        while(processing) {

                            ClientResponse response = resource.type( MediaType.MULTIPART_FORM_DATA ).post( ClientResponse.class, form );
                            if ( response.getClientResponseStatus() != null && response.getClientResponseStatus().getStatusCode() == HttpStatus.SC_OK ) {

                                processing = false;

                                InputStream zipFile = response.getEntityInputStream();
                                String outputDir = ConfigUtils.getIntegrityPath() + File.separator + endpoint.getId();

                                try {

                                    IntegrityUtil.unzipFile(zipFile, outputDir);

                                } catch(Exception e) {

                                    //Special handling if the thread was interrupted
                                    if ( e instanceof InterruptedException ) {
                                        //Setting the process status
                                        setStatus( session, endpointId, ProcessStatus.CANCELED, null );
                                        Logger.debug( IntegrityResource.class, "Requested interruption of the integrity checking process [unzipping Integrity Data] by the user.", e );
                                        throw new RuntimeException( "Requested interruption of the integrity checking process [unzipping Integrity Data] by the user.", e );
                                    }

                                    //Setting the process status
                                    setStatus( session, endpointId, ProcessStatus.ERROR, null );
                                    Logger.error(IntegrityResource.class, "Error while unzipping Integrity Data", e);
                                    throw new RuntimeException("Error while unzipping Integrity Data", e);
                                }

                                // set session variable
                                // call IntegrityChecker

                                Boolean foldersConflicts = false;
                                Boolean structuresConflicts = false;
                                Boolean schemesConflicts = false;

                                IntegrityUtil integrityUtil = new IntegrityUtil();
                                try {
                                    HibernateUtil.startTransaction();

                                    foldersConflicts = integrityUtil.checkFoldersIntegrity(endpointId);
                                    structuresConflicts = integrityUtil.checkStructuresIntegrity(endpointId);
                                    schemesConflicts = integrityUtil.checkWorkflowSchemesIntegrity(endpointId);

                                    HibernateUtil.commitTransaction();


                                } catch(Exception e) {

                                    try {
                                        HibernateUtil.rollbackTransaction();
                                    } catch (DotHibernateException e1) {
                                        Logger.error(IntegrityResource.class, "Error while rolling back transaction", e);
                                    }

                                    //Special handling if the thread was interrupted
                                    if ( e instanceof InterruptedException ) {
                                        //Setting the process status
                                        setStatus( session, endpointId, ProcessStatus.CANCELED, null );
                                        Logger.debug( IntegrityResource.class, "Requested interruption of the integrity checking process by the user.", e );
                                        throw new RuntimeException( "Requested interruption of the integrity checking process by the user.", e );
                                    }

                                    Logger.error(IntegrityResource.class, "Error checking integrity", e);

                                    //Setting the process status
                                    setStatus( session, endpointId, ProcessStatus.ERROR, null );
                                    throw new RuntimeException("Error checking integrity", e);
                                } finally {
                                    try {
                                        integrityUtil.dropTempTables(endpointId);
                                    } catch (DotDataException e) {
                                        Logger.error(IntegrityResource.class, "Error while deleting temp tables", e);
                                    }
                                }

                                if ( !foldersConflicts && !structuresConflicts && !schemesConflicts ) {
                                    String noConflictMessage;
                                    try {
                                        noConflictMessage = LanguageUtil.get( loggedUser.getLocale(), "push_publish_integrity_conflicts_not_found" );
                                    } catch ( LanguageException e ) {
                                        noConflictMessage = "No Integrity Conflicts found";
                                    }
                                    //Setting the process status
                                    setStatus( session, endpointId, ProcessStatus.NO_CONFLICTS, noConflictMessage );
                                } else {
                                    //Setting the process status
                                    setStatus( session, endpointId, ProcessStatus.FINISHED, null );
                                }

                            } else if ( response.getClientResponseStatus() == null && response.getStatus() == HttpStatus.SC_PROCESSING ) {
                                continue;
                            } else if ( response.getClientResponseStatus() == null && response.getStatus() == HttpStatus.SC_RESET_CONTENT ) {
                                processing = false;
                                //Setting the process status
                                setStatus( session, endpointId, ProcessStatus.CANCELED, null );
                            } else {
                                setStatus( session, endpointId, ProcessStatus.ERROR, null );
                                Logger.error( this.getClass(), "Response indicating a " + response.getClientResponseStatus().getReasonPhrase() + " (" + response.getClientResponseStatus().getStatusCode() + ") Error trying to retrieve the Integrity data from the Endpoint [" + endpointId + "]." );
                                processing = false;
                            }
                        }
                    }
                };

                //Start the integrity check
                integrityDataRequestChecker.start();
                addThreadToSession( session, integrityDataRequestChecker, endpointId, integrityDataRequestID );

            } else if ( response.getClientResponseStatus().getStatusCode() == HttpStatus.SC_UNAUTHORIZED ) {
                setStatus( session, endpointId, ProcessStatus.ERROR, null );
                Logger.error( this.getClass(), "Response indicating Not Authorized received from Endpoint. Please check Auth Token. Endpoint Id: " + endpointId );
                return response( "Response indicating Not Authorized received from Endpoint. Please check Auth Token. Endpoint Id:" + endpointId, true );
            } else {
                setStatus( session, endpointId, ProcessStatus.ERROR, null );
                Logger.error( this.getClass(), "Response indicating a " + response.getClientResponseStatus().getReasonPhrase() + " (" + response.getClientResponseStatus().getStatusCode() + ") Error trying to connect with the Integrity API on the Endpoint. Endpoint Id: " + endpointId );
                return response( "Response indicating a " + response.getClientResponseStatus().getReasonPhrase() + " (" + response.getClientResponseStatus().getStatusCode() + ") Error trying to connect with the Integrity API on the Endpoint. Endpoint Id: " + endpointId, true );
            }

            jsonResponse.put( "success", true );
            jsonResponse.put( "message", "Integrity Checking Initialized..." );
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.com.sun.jersey.api.client.ClientResponse

Copyright © 2018 www.massapicom. 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.