AnsweredAssumed Answered

Accessing webscripts from ColdFusion, tickets not working

Question asked by ejholmgren on Aug 27, 2008
Latest reply on Feb 8, 2011 by prignony
I am using the following ColdFusion code to access a webscript I have written:


<cffunction name="getTicket" returntype="string">
   <cftry>
      <cfhttp url="#APPLICATION.alfrescoRoot#/service/api/login?u=#APPLICATION.alfrescoUsername&pw=#APPLICATION.alfrescoPassword" method="GET">
      <cfdump var="#XmlParse(Trim(cfhttp.FileContent))#">
      <cfscript>
         xmlTicketResponse = XmlParse(Trim(cfhttp.FileContent));
         ticket = xmlTicketResponse.ticket.xmlText;
         return ticket;
      </cfscript>
      <cfcatch type="any">
      <cfset message = "components.titlemanager.alfresco.getTicket() failed.">
      <cflog application="false" file="#APPLICATION.logfile#" type="error" text="#message#">
      </cfcatch>
   </cftry>
</cffunction>

<cffunction name="createPublisher">
   <cfargument name="publisher_name" type="string">
   <cfargument name="publisher_id" type="Numeric">
   <cftry>
      <cfset ticket = getTicket()>
<cfoutput>#APPLICATION.alfrescoRoot#/service/createPublisher?publisherName=#URLEncodedFormat(ARGUMENTS.publisher_name)#&publisher_id=#ARGUMENTS.publisher_id#&ticket=#ticket#</cfoutput>
      <cfhttp url="#APPLICATION.alfrescoRoot#/service/createPublisher?publisherName=#URLEncodedFormat(ARGUMENTS.publisher_name)#&publisher_id=#ARGUMENTS.publisher_id#&ticket=#ticket#"
            method="GET">
      <cfdump var="#cfhttp.FileContent#">
      <cfcatch type="any">
      <cfset message = "components.titlemanager.alfresco.createPublisher failed. publisher_name: #ARGUMENTS.publisher_name#, publisher_id: #ARGUMENTS.publisher_id#">
      <cflog application="false" file="#APPLICATION.logfile#" type="error" text="#message#">
      </cfcatch>
   </cftry>
</cffunction>

The response I receive is always "This request requires HTTP authentication ()." When I try and paste the link with the ticket directly into the browser, I get the typical http basic authentication window asking for a username and password.

My desc file contains the following:


<webscript>
    <shortname>Create publisher</shortname>
    <description>Create publisher folder</description>
    <url>/createPublisher?publisherName={publisherNameArgument}&amp;publisherId={publisherIdArgument}</url>
    <url>/createPublisher.xml?publisherName={publisherNameArgument}&amp;publisherId={publisherIdArgument}</url>
    <format default="xml">argument</format>
    <authentication>user</authentication>
    <transaction>required</transaction>
</webscript>

What exactly am I doing wrong here?

Outcomes