Showing posts with label SDL. Show all posts
Showing posts with label SDL. Show all posts

Tuesday, December 29, 2015

How to connect to the SDL Tridion 2011 core services client using JAVA?

  1. Create a new folder under your source project
  2. Open a terminal window and go to the JDK\bin folder
  3. Type the following ws-import command:
    wsimport -extension -keep -Xnocompile -d {location of the source folder} {Webservice URL}

  4. Create the authenticator class:
    import java.net.Authenticator;
    import java.net.PasswordAuthentication;

    public class BasicHttpAuthenticator extends Authenticator {

       private String user;
       private String password;

       public BasicHttpAuthenticator(String user, String password) {
          this.user = user;
          this.password = password;
       }

       @Override
       protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(user, password.toCharArray());
       }
    }

  5. Create the web service client class:
    import java.net.Authenticator;
    import java.net.URL;

    import javax.xml.namespace.QName;

    import com.sdltridion.contentmanager.coreservice._2011.CoreService2011;
    import com.sdltridion.contentmanager.coreservice._2011.ICoreService;
    import com.sdltridion.contentmanager.r6.UserData;

    public class Main {
       private static final QName Q_NAME = new QName("http://www.sdltridion.com/ContentManager/CoreService/2011", "CoreService2011");

       public static void main(String[] args) throws Exception {
          BasicHttpAuthenticator basicHttpAuthenticator = new BasicHttpAuthenticator({user}, {password});
          Authenticator.setDefault(basicHttpAuthenticator);

          URL url = new URL({Webservice URL});
          CoreService2011 service = new CoreService2011(url, Q_NAME);
          ICoreService client = service.getBasicHttp();

          UserData currentUser = client.getCurrentUser();
          System.out.println(String.format("'%s' %s",
          currentUser.getTitle().getValue(), currentUser.getId()));
    }
{user} is an account with access to the CMS
{password} is the account password
{Webservice URL} is the core service URL

Example:

Java version used for this project is Java 1.8.0_66-b17

{user}: administrator
{password}: h}S<77Sn
{Webservice URL}: http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl
{location of the source folder}
     Windows: C:\source\CoreService2011\src
     Linux: /source/CoreService2011/src
JDK\bin folder: the default locations are
     Windows 64-bits: C:\Program Files\Java\jdk1.8.0_66\bin
     Linux: /usr/lib/jvm/java-8-oracle/bin

Structure of the project:
src
+--- BasicHttpAuthenticator.java
+--- Main.java

wsimport -extension -keep -Xnocompile -d /source/CoreService2011/src http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl

import java.net.Authenticator;
import java.net.PasswordAuthentication;

public class BasicHttpAuthenticator extends Authenticator {

   private String user;
   private String password;

   public BasicHttpAuthenticator(String user, String password) {
      this.user = user;
      this.password = password;
   }

   @Override
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication(user, password.toCharArray());
   }
}

import java.net.Authenticator;
import java.net.URL;

import javax.xml.namespace.QName;

import com.sdltridion.contentmanager.coreservice._2011.CoreService2011;
import com.sdltridion.contentmanager.coreservice._2011.ICoreService;
import com.sdltridion.contentmanager.r6.UserData;

public class Main {
   private static final QName Q_NAME = new QName("http://www.sdltridion.com/ContentManager/CoreService/2011", "CoreService2011");

   public static void main(String[] args) throws Exception {
      BasicHttpAuthenticator basicHttpAuthenticator = new BasicHttpAuthenticator("administrator", "h}S<77Sn");
      Authenticator.setDefault(basicHttpAuthenticator);

      URL url = new URL("http://www.blogger.com/webservices/CoreService2011.svc?singleWsdl");
      CoreService2011 service = new CoreService2011(url, Q_NAME);
      ICoreService client = service.getBasicHttp();

      UserData currentUser = client.getCurrentUser();
      System.out.println(String.format("'%s' %s", currentUser.getTitle().getValue(), currentUser.getId()));
   }
}

Source: http://yatb.mitza.net/2012/12/a-core-service-java-client.html

Saturday, October 17, 2015

How to connect to the SDL Tridion 2011 core services client?

var binding = new WSHttpBinding {
     TransactionFlow = true,
     MaxReceivedMessageSize = 83886080,
     ReaderQuotas = { MaxStringContentLength = 83886080 },
     OpenTimeout = TimeSpan.FromMinutes(5),
     ReceiveTimeout = TimeSpan.FromMinutes(5),
     CloseTimeout = TimeSpan.FromMinutes(5),
     SendTimeout = TimeSpan.FromMinutes(5)
};

var address = new EndpointAddress("http://{domain}/webservices/CoreService2011.svc/wsHttp");

SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient(binding, address);

{domain} is the domain where the CMS Administration GUI is installed

Example: 

List all publications of where luizcgjr.blogspot.com is the domain that hosts the CMS Administration GUI

var  binding = new WSHttpBinding {
     TransactionFlow = true,
     MaxReceivedMessageSize = 83886080,
     ReaderQuotas = { MaxStringContentLength = 83886080 },
     OpenTimeout = TimeSpan.FromMinutes(5),    
     ReceiveTimeout = TimeSpan.FromMinutes(5),    
     CloseTimeout = TimeSpan.FromMinutes(5),    
     SendTimeout = TimeSpan.FromMinutes(5)
};

var address = new EndpointAddress("http://luizcgjr.blogspot.com/webservices/CoreService2011.svc/wsHttp");

using (SessionAwareCoreServiceClient client = new SessionAwareCoreServiceClient(binding, address)) {
     var publications = _client.GetSystemWideList(new PublicationsFilterData());    

     foreach (var publication in publications) {
          Console.WriteLine(publication.Title);
     }
}

How the item types in Tridion are organized?


  1. Publication
    1. Folder
      1. Folder
      2. Schema
      3. Component
      4. ComponentTemplate
      5. PageTemplate
      6. TargetGroup
      7. TemplateBuildingBlock
      8. VirtualFolder
    2. Structure Group
      1. StructureGroup
      2. Page
    3. Category
      1. Category
      2. Keyword