Connect Tridion sites Core service with Java


Introduction

Coreservice is used to perform operation on cms i.e. connect to cms, create content, create workflow etc.
To work with Coreservice with java we have to setup code which consume coreservice as wsdl soap client.

Repository

To check reference implementation please checkout
Here we have used maven to build application

Implementation 

Setup module to generate library from soap url.
1.          Setup build information on pom
<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxws-maven-plugin</artifactId>
            <version>2.4.1</version>
            <executions>
                <execution>
                    <id>wsdltoJava</id>
                    <goals>
                        <goal>wsimport</goal>
                    </goals>
                    <configuration>
                        <wsdlUrls>
        <wsdlUrl>http://localhost:91/webservices/CoreService201701.svc?wsdl</wsdlUrl>
                        </wsdlUrls>
                        <vmArgs>
                            <vmArg>-Djavax.xml.accessExternalSchema=all</vmArg>
                        </vmArgs>
                        <keep>true</keep>
                        <sourceDestDir>src/main/resources/wsdl</sourceDestDir>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
2.         Run the maven command “mvn clean install”.
3.         You will have jar file generated on .m2 repository directory.

Once the library is generated add them to dependency and build path of application where we need to write coreservice operations
Sample code to connect application with Tridion coreservice.
QName qName = new QName(Q_NAME_URI, Q_NAME_LOCAL_PART);

Service service = CoreService201701.create(new URL(CMS_WSDL_URL), qName);

ICoreService iCoreService = service.getPort(ICoreService.class);

Authenticator myAuth = new Authenticator() {

    @Override

    protected PasswordAuthentication getPasswordAuthentication() {

        return new PasswordAuthentication(username, password.toCharArray());

    }

};

Authenticator.setDefault(myAuth);

Where parameters are
private static final String CMS_WSDL_URL = getPropertyValue("wsdlUrl");

private static final String Q_NAME_URI = getPropertyValue("qNameUri");

private static final String Q_NAME_LOCAL_PART = getPropertyValue("qNameLocalPart");

And parameters configured on application.properties are
wsdlUrl=http://localhost:91/webservices/CoreService201701.svc?wsdl

qNameUri=http://www.sdltridion.com/ContentManager/CoreService

qNameLocalPart=CoreService201701

After connection have made then we will have iCoreService object which will help us to perform coreservice operations

For example to get CMS version
iCoreService.getApiVersion();


Please go through repository for example.

Comments