ColdFusion RESTful web service

Viewed 1642

i have written a web service which takes input parameters (json) from other application. i am just authenticating those values and returning the "http status codes and response" (using cfheader). For that I am trying the "RESTClient" in firefox extension. My problem is - It is running the "GET" method successfully but not the POST method.I guess the request is not even going to the server in POST method. See the screen shot below of both the request: 1. GET request enter image description here

  1. POST request enter image description here

This is my CFC:

<cfcomponent rest="true" restpath="/AimsWeb"> <!--- REST Service--->

<cffunction name="AuthenticateUser" access="remote" httpmethod="POST"  returntype="void">

<!---- Defining Arguments--->
    <cfargument name="Username" type="string" required="Yes">
    <cfargument name="Password" type="string" required="Yes">
    <cfargument name="CustomerID" type="numeric" required="Yes">

<!---- Setting the Form Values (which we will get from AW+) and setting it to arguments passed--->
    <cfset Form.CustomerID = arguments.CustomerID>
    <cfset Form.Username = arguments.Username>
    <cfset Form.Password = arguments.Password>

<!--- Take input json, parse it and set in in a variable --->
<cfscript>
  record=deserializeJSON(
'{
"customerId": #Form.CustomerID#,
"userName": "#Form.userName#",
"password": "#Form.Password#"
}'
);

this.customerid = record.customerId;
this.userName = record.userName;
this.password = record.password;
 </cfscript>

   <cfquery name="AllUsers" datasource="#Application.GomDatasource#">
        SELECT u.UserTypeID, u.UserID, u.CustomerID, u.UserName, u.Password, u.active, u.locked
        FROM tblUsers u
        WHERE  u.CustomerID =  <cfqueryparam cfsqltype="cf_sql_integer" value="#this.customerid#">
        AND  u.username =  <cfqueryparam cfsqltype="cf_sql_varchar" value="#this.username#">
        AND u.password = <cfqueryparam cfsqltype="cf_sql_varchar" value="#this.password#">
   </cfquery>

<!--- This is to check whether provided parameters are valid by checking the same in the database--->
<cfset local.StatusStruct = StructNew()>

    <cfif AllUsers.RecordCount AND (AllUsers.Active EQ 0 OR AllUsers.locked EQ 1)>
        <cfheader statuscode="401" statustext="User Account is locked">
    <cfelse>

        <cfif this.customerid EQ "" OR this.username EQ "" OR this.password EQ "">
            <cfheader statuscode="400" statustext="Insufficient Input. Please provide Customer ID, UserName and Password">
        <cfelseif AllUsers.RecordCount AND this.CustomerId EQ AllUsers.CustomerID AND this.username EQ AllUsers.UserName AND this.password EQ AllUsers.Password>
            <cfheader statuscode="200" statustext="Success">
        <cfelseif AllUsers.CustomerID NEQ this.CustomerID>
            <cfheader statuscode="400" statustext="Customer Id doesn't exist">
        <cfelseif AllUsers.UserName NEQ this.UserName>
            <cfheader statuscode="400" statustext="User not found">
        <cfelseif AllUsers.Password NEQ this.password>
            <cfheader statuscode="400" statustext="Invalid Password">
        </cfif>
    </cfif>
  </cffunction>
</cfcomponent>
1 Answers
Related