cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing webscripts from ColdFusion, tickets not working

ejholmgren
Champ in-the-making
Champ in-the-making
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?
3 REPLIES 3

mitchrose
Champ in-the-making
Champ in-the-making
You are not using the CFHTTP tag correctly. check the docs.

ejholmgren
Champ in-the-making
Champ in-the-making
I had forgotten about this post. Looking back, the only thing wrong with that code is that the correct url argument is "alf_ticket" for webscripts, not "ticket."

prignony
Champ on-the-rise
Champ on-the-rise
Yep and this too

<cfhttp url="#APPLICATION.alfrescoRoot#/service/api/login?u=#APPLICATION.alfrescoUsername#&pw=#APPLICATION.alfrescoPassword#" method="GET">