Examples of PublishingEndPoint


Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

   * We descrypt the auth_key in this case.
   *
   * Oct 30, 2012 - 11:21:23 AM
   */
  public static PublishingEndPoint getObjectByMap(Map<String, Object> row){
    PublishingEndPoint pep = new PublishingEndPoint();
    pep.setId(row.get("id").toString());
    if(row.get("group_id") != null){
      pep.setGroupId(row.get("group_id").toString());
    }
    pep.setAddress(row.get("address").toString());
    pep.setPort(row.get("port").toString());
    pep.setProtocol(row.get("protocol").toString());
    pep.setServerName(new StringBuilder(row.get("server_name").toString()));
    pep.setAuthKey(new StringBuilder(row.get("auth_key").toString()));

    if(row.get("sending").toString().equals("1") || row.get("sending").toString().equalsIgnoreCase("true")){
      pep.setSending(true);
    }else{
      pep.setSending(false);
    }

    if(row.get("enabled").toString().equals("1") || row.get("enabled").toString().equalsIgnoreCase("true")){
      pep.setEnabled(true);
    }else{
      pep.setEnabled(false);
    }

    return pep;
  }
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

            editEndpoint(request, response);
            return;
          }

          String serverName = request.getParameter("serverName");
          PublishingEndPoint existingServer = APILocator.getPublisherEndPointAPI().findEndPointByName(serverName);

          if(existingServer!=null) {

            Logger.info(getClass(), "Can't save EndPoint. An Endpoint with the given name already exists. ");
            User user = getUser();
          response.getWriter().println("FAILURE: " + LanguageUtil.get(user, "publisher_Endpoint_name_exists"));
          return;
          }

          PublishingEndPoint endpoint = new PublishingEndPoint();
          endpoint.setServerName(new StringBuilder(serverName));
          endpoint.setAddress(request.getParameter("address"));
          endpoint.setPort(request.getParameter("port"));
          endpoint.setProtocol(request.getParameter("protocol"));
          endpoint.setAuthKey(new StringBuilder(PublicEncryptionFactory.encryptString(request.getParameter("authKey"))));
          endpoint.setEnabled(null!=request.getParameter("enabled"));
          String sending = request.getParameter("sending");
          endpoint.setSending("true".equals(sending));
          endpoint.setGroupId(request.getParameter("environmentId"));
          //Save the endpoint.
          PublishingEndPointAPI peAPI = APILocator.getPublisherEndPointAPI();
          peAPI.saveEndPoint(endpoint);

View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

  public void editEndpoint(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, LanguageException {
    try {

      String serverName = request.getParameter("serverName");
      String id = request.getParameter("identifier");
          PublishingEndPoint existingServer = APILocator.getPublisherEndPointAPI().findEndPointByName(serverName);

          if(existingServer!=null && !id.equals(existingServer.getId())) {

            Logger.info(getClass(), "Can't save EndPoint. An Endpoint with the given name already exists. ");
            User user = getUser();
          response.getWriter().println("FAILURE: " + LanguageUtil.get(user, "publisher_Endpoint_name_exists"));
          return;
          }


      PublishingEndPoint endpoint = new PublishingEndPoint();
          endpoint.setId(id);
      endpoint.setServerName(new StringBuilder(request.getParameter("serverName")));
      endpoint.setAddress(request.getParameter("address"));
      endpoint.setPort(request.getParameter("port"));
      endpoint.setProtocol(request.getParameter("protocol"));
      endpoint.setAuthKey(new StringBuilder(PublicEncryptionFactory.encryptString(request.getParameter("authKey"))));
      endpoint.setEnabled(null!=request.getParameter("enabled"));
      endpoint.setSending("true".equals(request.getParameter("sending")));
      endpoint.setGroupId(request.getParameter("environmentId"));
      //Update the endpoint.
      PublishingEndPointAPI peAPI = APILocator.getPublisherEndPointAPI();
      peAPI.updateEndPoint(endpoint);

    } catch (DotDataException e) {
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

              EndpointDetail localDetail = endpointsGroup.get(endpointId);

              if(localDetail.getStatus() != PublishAuditStatus.Status.SUCCESS.getCode() &&
                localDetail.getStatus() != PublishAuditStatus.Status.FAILED_TO_PUBLISH.getCode()) {

                PublishingEndPoint target = endpointAPI.findEndPointById(endpointId);

                if(target != null && !target.isSending()) {
                  webResource = client.resource(target.toURL()+"/api/auditPublishing");

                  try {
                    PublishAuditHistory remoteHistory =
                        PublishAuditHistory.getObjectFromString(
                        webResource
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

    //Create a environment
    environmentAPI.saveEnvironment( environment, permissions );

    //Now we need to create the end point
    PublishingEndPoint endpoint = new PublishingEndPoint();
    endpoint.setServerName( new StringBuilder( "TestEndPoint" + String.valueOf( new Date().getTime() ) ) );
    endpoint.setAddress( "127.0.0.1" );
    endpoint.setPort( "999" );
    endpoint.setProtocol( "http" );
    endpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    endpoint.setEnabled( true );
    endpoint.setSending( false );//TODO: Shouldn't this be true as we are creating this end point to send bundles to another server..?
    endpoint.setGroupId( environment.getId() );
    //Save the endpoint.
    publisherEndPointAPI.saveEndPoint( endpoint );

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //++++++++++++++++++++++++++++++PUBLISH++++++++++++++++++++++++++++

    //Getting test data
    List<Contentlet> contentlets = contentletAPI.findAllContent( 0, 1 );
    //Validations
    assertNotNull( contentlets );
    assertEquals( contentlets.size(), 1 );

    //Preparing the url in order to push content
    SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
    SimpleDateFormat timeFormat = new SimpleDateFormat( "H-m" );
    String publishDate = dateFormat.format( new Date() );
    String publishTime = timeFormat.format( new Date() );

    String baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/publish/u/admin@dotcms.com/p/admin";
    String completeURL = baseURL +
        "?remotePublishDate=" + UtilMethods.encodeURIComponent( publishDate ) +
        "&remotePublishTime=" + UtilMethods.encodeURIComponent( publishTime ) +
        "&remotePublishExpireDate=" +
        "&remotePublishExpireTime=" +
        "&iWantTo=" + RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH +
        "&whoToSend=" + UtilMethods.encodeURIComponent( environment.getId() ) +
        "&forcePush=false" +
        "&assetIdentifier=" + UtilMethods.encodeURIComponent( contentlets.get( 0 ).getIdentifier() );

    //Execute the call
    URL publishUrl = new URL( completeURL );
    String response = IOUtils.toString( publishUrl.openStream(), "UTF-8" );
    //Validations
    JSONObject jsonResponse = new JSONObject( response );
    assertNotNull( contentlets );
    assertEquals( jsonResponse.getInt( "errors" ), 0 );
    assertEquals( jsonResponse.getInt( "total" ), 1 );
    assertNotNull( jsonResponse.get( "bundleId" ) );

    //Now that we have a bundle id
    String bundleId = jsonResponse.getString( "bundleId" );
    //First we need to verify if this bundle is in the queue job
    List<PublishQueueElement> foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertNotNull( foundBundles );
    assertTrue( !foundBundles.isEmpty() );

    /*
         Now lets wait until it finished, by the way, we are expecting it to fail to publish as the end point does not exist.
         Keep in mind the queue will try 3 times before to marked as failed to publish, so we have to wait a bit here....
     */
    int x = 0;
    do {
      Thread.sleep( 3000 );
      //Verify if it continues in the queue job
      foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
      x++;
    } while ( (foundBundles != null && !foundBundles.isEmpty()) && x < 200 );
    //At this points should not be here anymore
    foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertTrue( foundBundles == null || foundBundles.isEmpty() );

    //Get the audit records related to this bundle
    PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
    //We will be able to retry failed and successfully bundles
    assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail

    //Get current status dates
    Date initialCreationDate = status.getCreateDate();
    Date initialUpdateDate = status.getStatusUpdated();

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //++++++++++++++++++++++++++++++RETRY++++++++++++++++++++++++++++++
    //Now we can try the retry
    req = ServletTestRunner.localRequest.get();
    baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/retry/u/admin@dotcms.com/p/admin";
    completeURL = baseURL + "?bundlesIds=" + UtilMethods.encodeURIComponent( bundleId );

    //Execute the call
    URL retryUrl = new URL( completeURL );
    response = IOUtils.toString( retryUrl.openStream(), "UTF-8" );//We can expect something like "Bundle id: <strong>1193e3eb-3ccd-496e-8995-29a9fcc48cbd</strong> added successfully to Publishing Queue."
    //Validations
    assertNotNull( response );
    assertTrue( response.contains( bundleId ) );
    assertTrue( response.contains( "added successfully to" ) );

    //And should be back to the queue job
    foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertNotNull( foundBundles );
    assertTrue( !foundBundles.isEmpty() );

    //Get current status dates
    status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );//Get the audit records related to this bundle
    Date latestCreationDate = status.getCreateDate();
    Date latestUpdateDate = status.getStatusUpdated();
    //Validations
    assertNotSame( initialCreationDate, latestCreationDate );
    assertNotSame( initialUpdateDate, latestUpdateDate );
    assertTrue( initialCreationDate.before( latestCreationDate ) );
    assertTrue( initialUpdateDate.before( latestUpdateDate ) );

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    //++++++++++++++++++++SIMULATE AN END POINT++++++++++++++++++++++++
    /*
         And finally lets try to simulate a end point sending directly an already created bundle file to
         the api/bundlePublisher/publish service
     */

    //Create a receiving end point
    PublishingEndPoint receivingFromEndpoint = new PublishingEndPoint();
    receivingFromEndpoint.setServerName( new StringBuilder( "TestReceivingEndPoint" + String.valueOf( new Date().getTime() ) ) );
    receivingFromEndpoint.setAddress( req.getServerName() );
    receivingFromEndpoint.setPort( String.valueOf( req.getServerPort() ) );
    receivingFromEndpoint.setProtocol( "http" );
    receivingFromEndpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    receivingFromEndpoint.setEnabled( true );
    receivingFromEndpoint.setSending( true );//TODO: Shouldn't this be false as we are creating this end point to receive bundles from another server..?
    receivingFromEndpoint.setGroupId( environment.getId() );
    //Save the endpoint.
    publisherEndPointAPI.saveEndPoint( receivingFromEndpoint );

    //Find the bundle
    Bundle bundle = APILocator.getBundleAPI().getBundleById( bundleId );
    PublisherConfig basicConfig = new PublisherConfig();
    basicConfig.setId( bundleId );
    File bundleRoot = BundlerUtil.getBundleRoot( basicConfig );
    File bundleFile = new File( bundleRoot + File.separator + ".." + File.separator + bundle.getId() + ".tar.gz" );
   
    //lets wait one minute
    Thread.sleep( 60000 );
   
    assertTrue( bundleFile.exists() );

    //Rename the bundle file
    String newBundleId = UUID.randomUUID().toString();
    File newBundleFile = new File( bundleRoot + File.separator + ".." + File.separator + newBundleId + ".tar.gz" );
    Boolean success = bundleFile.renameTo( newBundleFile );
    assertTrue( success );
    assertTrue( newBundleFile.exists() );

    //Prepare the post request
    ClientConfig cc = new DefaultClientConfig();
    Client client = Client.create( cc );

    FormDataMultiPart form = new FormDataMultiPart();
    form.field( "AUTH_TOKEN", PublicEncryptionFactory.encryptString( (PublicEncryptionFactory.decryptString( receivingFromEndpoint.getAuthKey().toString() )) ) );
    form.field( "GROUP_ID", UtilMethods.isSet( receivingFromEndpoint.getGroupId() ) ? receivingFromEndpoint.getGroupId() : receivingFromEndpoint.getId() );
    form.field( "BUNDLE_NAME", bundle.getName() );
    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
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

    environmentAPI.saveEnvironment( environment, permissions );

    /*
     * Now we need to create the end point
     */
    PublishingEndPoint endpoint = new PublishingEndPoint();
    endpoint.setServerName( new StringBuilder( "TestEndPoint" + String.valueOf( new Date().getTime() ) ) );
    endpoint.setAddress( "127.0.0.1" );
    endpoint.setPort( "999" );
    endpoint.setProtocol( "http" );
    endpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    endpoint.setEnabled( true );
    endpoint.setSending( false );//TODO: Shouldn't this be true as we are creating this end point to send bundles to another server..?
    endpoint.setGroupId( environment.getId() );
    /*
     * Save the endpoint.
     */
    publisherEndPointAPI.saveEndPoint( endpoint );
    SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
    SimpleDateFormat timeFormat = new SimpleDateFormat( "H-m" );
    String publishDate = dateFormat.format( new Date() );
    String publishTime = timeFormat.format( new Date() );

    String baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/publish/u/admin@dotcms.com/p/admin";
    String completeURL = baseURL +
        "?remotePublishDate=" + UtilMethods.encodeURIComponent( publishDate ) +
        "&remotePublishTime=" + UtilMethods.encodeURIComponent( publishTime ) +
        "&remotePublishExpireDate=" +
        "&remotePublishExpireTime=" +
        "&iWantTo=" + RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH +
        "&whoToSend=" + UtilMethods.encodeURIComponent( environment.getId() ) +
        "&forcePush=false" +
        "&assetIdentifier=" + UtilMethods.encodeURIComponent( folder.getInode() );

    /*
     * Execute the call
     */
    URL publishUrl = new URL( completeURL );
    String response = IOUtils.toString( publishUrl.openStream(), "UTF-8" );
    /*
     * Validations
     */
    JSONObject jsonResponse = new JSONObject( response );
    assertEquals( jsonResponse.getInt( "errors" ), 0 );
    assertEquals( jsonResponse.getInt( "total" ), 1 );
    assertNotNull( jsonResponse.get( "bundleId" ) );

    /*
     * Now that we have a bundle id
     */
    String bundleId = jsonResponse.getString( "bundleId" );
    /*
     * First we need to verify if this bundle is in the queue job
     */
    List<PublishQueueElement> foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertNotNull( foundBundles );
    assertTrue( !foundBundles.isEmpty() );

    /*
     *        Now lets wait until it finished, by the way, we are expecting it to fail to publish as the end point does not exist.
     *        Keep in mind the queue will try 3 times before to marked as failed to publish, so we have to wait a bit here....
     */
    int x = 0;
    do {
      Thread.sleep( 3000 );
      /*
       * Verify if it continues in the queue job
       */
      foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
      x++;
    } while ( (foundBundles != null && !foundBundles.isEmpty()) && x < 200 );
    /*
     * At this points should not be here anymore
     */
    //foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    //assertTrue( foundBundles == null || foundBundles.isEmpty() );

    /*
     * Get the audit records related to this bundle
     */
    PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
    /*
     * We will be able to retry failed and successfully bundles
     */
    assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail

    /*
     * deleting folder, pages and content, to create the receiving endpoint environment
     */
    APILocator.getContentletAPI().delete(contentlet, systemUser, false, true);
    WebAssetFactory.unPublishAsset(workinghtmlPageAsset, systemUser.getUserId(), folder);
    WebAssetFactory.archiveAsset(workinghtmlPageAsset);
    APILocator.getHTMLPageAPI().delete(workinghtmlPageAsset, systemUser, true);
    APILocator.getHTMLPageAPI().delete(workinghtmlPageAsset2, systemUser, true);
    APILocator.getFolderAPI().delete(folder, systemUser, false);
   
    Assert.assertEquals(0,MultiTreeFactory.getMultiTree(workinghtmlPageAsset).size());
    Assert.assertEquals(0,MultiTreeFactory.getMultiTree(workinghtmlPageAsset2).size());
    Assert.assertEquals(0,MultiTreeFactory.getMultiTreeByChild(contentlet.getIdentifier()).size());

    folder = APILocator.getFolderAPI().findFolderByPath(folderPath, host, systemUser, false);
    assertTrue(!UtilMethods.isSet(folder.getInode()));

    /*
     * Find the bundle
     * SIMULATE AN END POINT
     *
     * And finally lets try to simulate a end point sending directly an already created bundle file to
     * the api/bundlePublisher/publish service
     */

    /*
     * Create a receiving end point
     */
    PublishingEndPoint receivingFromEndpoint = new PublishingEndPoint();
    receivingFromEndpoint.setServerName( new StringBuilder( "TestReceivingEndPoint" + String.valueOf( new Date().getTime() ) ) );
    receivingFromEndpoint.setAddress( req.getServerName() );
    receivingFromEndpoint.setPort( String.valueOf( req.getServerPort() ) );
    receivingFromEndpoint.setProtocol( "http" );
    receivingFromEndpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    receivingFromEndpoint.setEnabled( true );
    receivingFromEndpoint.setSending( true );//TODO: Shouldn't this be false as we are creating this end point to receive bundles from another server..?
    receivingFromEndpoint.setGroupId( environment.getId() );
    /*
     * Save the endpoint.
     */
    publisherEndPointAPI.saveEndPoint( receivingFromEndpoint );

View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

    environmentAPI.saveEnvironment( environment, permissions );

    /*
     * Now we need to create the end point
     */
    PublishingEndPoint endpoint = new PublishingEndPoint();
    endpoint.setServerName( new StringBuilder( "TestEndPoint" + String.valueOf( new Date().getTime() ) ) );
    endpoint.setAddress( "127.0.0.1" );
    endpoint.setPort( "9999" );
    endpoint.setProtocol( "http" );
    endpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    endpoint.setEnabled( true );
    endpoint.setSending( false );//TODO: Shouldn't this be true as we are creating this end point to send bundles to another server..?
    endpoint.setGroupId( environment.getId() );
    /*
     * Save the endpoint.
     */
    publisherEndPointAPI.saveEndPoint( endpoint );
    SimpleDateFormat dateFormat = new SimpleDateFormat( "yyyy-MM-dd" );
    SimpleDateFormat timeFormat = new SimpleDateFormat( "H-m" );
    String publishDate = dateFormat.format( new Date() );
    String publishTime = timeFormat.format( new Date() );

    String baseURL = "http://" + req.getServerName() + ":" + req.getServerPort() + "/DotAjaxDirector/com.dotcms.publisher.ajax.RemotePublishAjaxAction/cmd/publish/u/admin@dotcms.com/p/admin";
    String completeURL = baseURL +
        "?remotePublishDate=" + UtilMethods.encodeURIComponent( publishDate ) +
        "&remotePublishTime=" + UtilMethods.encodeURIComponent( publishTime ) +
        "&remotePublishExpireDate=" +
        "&remotePublishExpireTime=" +
        "&iWantTo=" + RemotePublishAjaxAction.DIALOG_ACTION_PUBLISH +
        "&whoToSend=" + UtilMethods.encodeURIComponent( environment.getId() ) +
        "&forcePush=false" +
        "&assetIdentifier=" + UtilMethods.encodeURIComponent( folder.getInode() );

    /*
     * Execute the call
     */
    URL publishUrl = new URL( completeURL );
    String response = IOUtils.toString( publishUrl.openStream(), "UTF-8" );
    /*
     * Validations
     */
    JSONObject jsonResponse = new JSONObject( response );
    assertEquals( jsonResponse.getInt( "errors" ), 0 );
    assertEquals( jsonResponse.getInt( "total" ), 1 );
    assertNotNull( jsonResponse.get( "bundleId" ) );

    /*
     * Now that we have a bundle id
     */
    String bundleId = jsonResponse.getString( "bundleId" );
    /*
     * First we need to verify if this bundle is in the queue job
     */
    List<PublishQueueElement> foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
    assertNotNull( foundBundles );
    assertTrue( !foundBundles.isEmpty() );

    /*
     *        Now lets wait until it finished, by the way, we are expecting it to fail to publish as the end point does not exist.
     *        Keep in mind the queue will try 3 times before to marked as failed to publish, so we have to wait a bit here....
     */
    int x = 0;
    do {
      Thread.sleep( 3000 );
      /*
       * Verify if it continues in the queue job
       */
      foundBundles = publisherAPI.getQueueElementsByBundleId( bundleId );
      x++;
    } while ( (foundBundles != null && !foundBundles.isEmpty()) && x < 200 );
    /*
     * At this points should not be here anymore
     */


    /*
     * Get the audit records related to this bundle
     */
    PublishAuditStatus status = PublishAuditAPI.getInstance().getPublishAuditStatus( bundleId );
    /*
     * We will be able to retry failed and successfully bundles
     */
    assertEquals( status.getStatus(), PublishAuditStatus.Status.FAILED_TO_PUBLISH ); //Remember, we are expecting this to fail

    /*
     * deleting folder, pages and contents, to create the receiving endpoint environment
     */
    APILocator.getContentletAPI().delete(contentlet1, systemUser, false, true);
    APILocator.getContentletAPI().delete(contentlet2, systemUser, false, true);
    APILocator.getContentletAPI().delete(contentlet3, systemUser, false, true);
    WebAssetFactory.unPublishAsset(workinghtmlPageAsset, systemUser.getUserId(), folder);
    WebAssetFactory.archiveAsset(workinghtmlPageAsset);
    APILocator.getHTMLPageAPI().delete(workinghtmlPageAsset, systemUser, true);
    APILocator.getFolderAPI().delete(folder, systemUser, false);

    folder = APILocator.getFolderAPI().findFolderByPath(folderPath, host, systemUser, false);
    assertTrue(!UtilMethods.isSet(folder.getInode()));

    /*
     * Find the bundle
     * SIMULATE AN END POINT
     *
     * And finally lets try to simulate a end point sending directly an already created bundle file to
     * the api/bundlePublisher/publish service
     */

    /*
     * Create a receiving end point
     */
    PublishingEndPoint receivingFromEndpoint = new PublishingEndPoint();
    receivingFromEndpoint.setServerName( new StringBuilder( "TestReceivingEndPoint" + String.valueOf( new Date().getTime() ) ) );
    receivingFromEndpoint.setAddress( req.getServerName() );
    receivingFromEndpoint.setPort( String.valueOf( req.getServerPort() ) );
    receivingFromEndpoint.setProtocol( "http" );
    receivingFromEndpoint.setAuthKey( new StringBuilder( PublicEncryptionFactory.encryptString( "1111" ) ) );
    receivingFromEndpoint.setEnabled( true );
    receivingFromEndpoint.setSending( true );//TODO: Shouldn't this be false as we are creating this end point to receive bundles from another server..?
    receivingFromEndpoint.setGroupId( environment.getId() );
    /*
     * Save the endpoint.
     */
    publisherEndPointAPI.saveEndPoint( receivingFromEndpoint );

    /*
     * Find the bundle
     */
    Bundle bundle = APILocator.getBundleAPI().getBundleById( bundleId );
    PublisherConfig basicConfig = new PublisherConfig();
    basicConfig.setId( bundleId );
    File bundleRoot = BundlerUtil.getBundleRoot( basicConfig );
    File bundleFile = new File( bundleRoot + File.separator + ".." + File.separator + bundle.getId() + ".tar.gz" );
    assertTrue( bundleFile.exists() );

    /*
     * Rename the bundle file
     */
    String newBundleId = UUID.randomUUID().toString();
    File newBundleFile = new File( bundleRoot + File.separator + ".." + File.separator + newBundleId + ".tar.gz" );
    Boolean success = bundleFile.renameTo( newBundleFile );
    assertTrue( success );
    assertTrue( newBundleFile.exists() );

    /*
     * Prepare the post request
     */
    ClientConfig cc = new DefaultClientConfig();
    Client client = Client.create( cc );

    FormDataMultiPart form = new FormDataMultiPart();
    form.field( "AUTH_TOKEN", PublicEncryptionFactory.encryptString( (PublicEncryptionFactory.decryptString( receivingFromEndpoint.getAuthKey().toString() )) ) );
    form.field( "GROUP_ID", UtilMethods.isSet( receivingFromEndpoint.getGroupId() ) ? receivingFromEndpoint.getGroupId() : receivingFromEndpoint.getId() );
    form.field( "BUNDLE_NAME", bundle.getName() );
    form.field( "ENDPOINT_ID", receivingFromEndpoint.getId() );
    form.bodyPart( new FileDataBodyPart( "bundle", newBundleFile, MediaType.MULTIPART_FORM_DATA_TYPE ) );

    /* TODO: We have the improve this test because of the new license updates
     *
    //Sending bundle to endpoint
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

        }

        try {
            PublishingEndPointAPI pepAPI = APILocator.getPublisherEndPointAPI();

            PublishingEndPoint pep = pepAPI.findEndPointById(endPoint);
            String environmentId = pep.getGroupId();

            //Delete the end point
            pepAPI.deleteEndPointById( endPoint );

            // if the environment is now empty, lets remove it from session
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

            remoteIP = request.getRemoteHost();
            if(!UtilMethods.isSet(remoteIP))
                remoteIP = request.getRemoteAddr();

            PublishingEndPointAPI endpointAPI = APILocator.getPublisherEndPointAPI();
            final PublishingEndPoint requesterEndPoint = endpointAPI.findEnabledSendingEndPointByAddress(remoteIP);

            if(!BundlePublisherResource.isValidToken(auth_token, remoteIP, requesterEndPoint)) {
                return Response.status(HttpStatus.SC_UNAUTHORIZED).build();
            }
View Full Code Here

Examples of com.dotcms.publisher.endpoint.bean.PublishingEndPoint

            remoteIP = request.getRemoteHost();
            if(!UtilMethods.isSet(remoteIP))
                remoteIP = request.getRemoteAddr();

            PublishingEndPointAPI endpointAPI = APILocator.getPublisherEndPointAPI();
            final PublishingEndPoint requesterEndPoint = endpointAPI.findEnabledSendingEndPointByAddress(remoteIP);

            if(!BundlePublisherResource.isValidToken(auth_token, remoteIP, requesterEndPoint) || !UtilMethods.isSet(requestId)) {
                return Response.status(HttpStatus.SC_UNAUTHORIZED).build();
            }

            ServletContext servletContext = request.getSession().getServletContext();
            if(!UtilMethods.isSet(servletContext.getAttribute("integrityDataRequestID"))
                    || !((String) servletContext.getAttribute("integrityDataRequestID")).equals(requestId)) {
                return Response.status(HttpStatus.SC_UNAUTHORIZED).build();
            }

            ProcessStatus integrityDataGeneratorStatus = (ProcessStatus) servletContext.getAttribute("integrityDataGenerationStatus");

            if(UtilMethods.isSet( integrityDataGeneratorStatus )) {
                switch (integrityDataGeneratorStatus) {
                    case PROCESSING:
                        return Response.status(HttpStatus.SC_PROCESSING).build();
                    case FINISHED:
                        StreamingOutput output = new StreamingOutput() {
                            public void write(OutputStream output) throws IOException, WebApplicationException {
                                InputStream is = new FileInputStream(ConfigUtils.getIntegrityPath() + File.separator + requesterEndPoint.getId() + File.separator + INTEGRITY_DATA_TO_CHECK_ZIP_FILE_NAME);

                                byte[] buffer = new byte[1024];
                                int bytesRead;
                                //read from is to buffer
                                while((bytesRead = is.read(buffer)) !=-1){
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.