Skip to content

Instantly share code, notes, and snippets.

View pmedcraft's full-sized avatar

Phil Medcraft pmedcraft

View GitHub Profile
@pmedcraft
pmedcraft / WorldServerUploadCustomization.java
Last active November 15, 2017 18:15
Uploads customization package to WorldServer by posting to the "management_customization" servlet
/**
* Uploads customization package to WorldServer by posting to the "management_customization" servlet.
*
* @param wsBaseUrl
* @param token
* @param customizationFile
* @throws IOException
*/
private void uploadCustomization(String wsBaseUrl, String token, File customizationFile) throws IOException {
String postActionUrl = wsBaseUrl + "/ws-legacy/management_customization?action=add&token=" + token;
@pmedcraft
pmedcraft / WorldServerRestLogin.java
Last active November 14, 2020 22:32
Connects to SDL WorldServer via invoking the /login REST API call
/**
* Connects to SDL WorldServer via invoking the /login REST API call.
*
* @param wsBaseUrl
* @param username
* @param password
* @return a security token.
* @throws IOException
*/
private String login(String wsBaseUrl, String username, String password) throws IOException {
@pmedcraft
pmedcraft / ProjectInfo.java
Last active May 16, 2017 18:16
Custom Servlet for SDL WorldServer
package com.worldservertraining;
import com.idiominc.wssdk.WSContext;
import com.idiominc.wssdk.WSVersion;
import com.idiominc.wssdk.component.servlet.WSHttpServlet;
import com.idiominc.wssdk.user.WSClient;
import com.idiominc.wssdk.workflow.WSProject;
import com.idiominc.wssdk.workflow.WSTask;
import javax.servlet.http.HttpServletRequest;
@pmedcraft
pmedcraft / AkamaiPurgeResponse.java
Last active April 28, 2017 20:59
SDL Web Deployer Extension for sending Purge requests to Akamai
package com.tridion.ps.akamai;
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown = true)
public class AkamaiPurgeResponse {
private Integer httpStatus;
private Integer estimatedSeconds;
private Integer pingAfterSeconds;
@pmedcraft
pmedcraft / App.config
Last active March 23, 2017 17:43
Extracts of an App.config file from an application connecting to SDL Media Manager
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="IssuerName" value="http://localhost:89/IWSTrust13" />
<add key="MediaManagerWebServiceAddress" value="https://TENANTNAME.sdlmedia.com/WebServices/MediaManager2011.svc" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.serviceModel>
<bindings>
<ws2007FederationHttpBinding>
@pmedcraft
pmedcraft / MediaManagerHelper.cs
Created March 8, 2017 12:12
C# helper class for connecting to SDL Media Manager
using Migration.MediaManager;
using System.ServiceModel;
using System.IdentityModel.Tokens;
using System.Configuration;
using System.ServiceModel.Security;
using System.IdentityModel.Protocols.WSTrust;
namespace Migration.Helpers
{
public class MediaManagerHelper
@pmedcraft
pmedcraft / update-where-using-components-with-ecl-stub-relationship.cs
Created March 3, 2017 18:50
C# code to replace the relationship between a provided SDL Web (Tridion) component and all its "where using" components with a reference (stub) to an asset originating from SDL Media Manager
private static void UpdateWhereUsingComponents(ICoreService coreServiceClient, SessionAwareEclServiceClient eclClient, ComponentData componentData, Dictionary<string, object> uploadInfo)
{
Dictionary<string, string> stubInfo = null;
try
{
stubInfo = eclClient.CreateOrGetStubUris(new List<string> { "ecl:5-mm-" + uploadInfo["distributionId"] + "-dist-file" });
}
catch(Exception exception)
{
log.Error("Error generating stub for image " + componentData.Id);
@pmedcraft
pmedcraft / ecl-binary-endpoint.xml
Created March 3, 2017 18:20
SDL Web (Tridion) endpoint for the SessionAwareEclServiceClient
<client>
<endpoint name="EclBinaryEndpoint"
address="net.tcp://localhost:2660/ExternalContentLibrary/2012/netTcp"
binding="netTcpBinding"
bindingConfiguration="EclNetTcpBinding"
contract="Tridion.ExternalContentLibrary.Service.Client.ISessionAwareEclService"/>
</client>
@pmedcraft
pmedcraft / ecl-net-tcp-binding.xml
Created March 3, 2017 18:16
SDL Web (Tridion) netTcpBinding for the SessionAwareEclServiceClient
<netTcpBinding>
<binding name="EclNetTcpBinding" maxReceivedMessageSize="2147483647" receiveTimeout="00:10:00" sendTimeout="00:10:00">
<readerQuotas maxArrayLength="2147483647" maxStringContentLength="2147483647" />
</binding>
</netTcpBinding>
@pmedcraft
pmedcraft / UploadToMediaManager.cs
Created March 3, 2017 12:51
C# methods for uploading a multimedia asset to SDL Media Manager
private static Dictionary<string, object> UploadToMediaManager(IMediaManager2011 mediaManagerClient,
Dictionary<string, string> downloadInfo, long mediaManagerFolderId, long assetTypeId,
long outletId, long[] tags)
{
// Upload to Media Manager
UploadInfoData uploadInfoData = new UploadInfoData
{
Author = "Migration Upload Tool",
MakeAvailableForWebPublishing = true,
ProgramCreation = ProgramCreationOptions.OneProgramPerItem,