Double check your description file. and check which level of authentication you want to provide while web script development.
In webscript desc.xml file, authentication (optional) is the required level of authentication; valid values are:
- none: specifies that no authentication is required at all
- guest: specifies that at least guest authentication is required
- user: specifies that at least named user authentication is required
- admin: specifies that at least a named admin authentication is required
Note: if not specified, the default value is none
Note: The optional runas attribute can be used to force the execution of a web script as a specific user. This can only be specified for web scripts that are stored in the Java Class path.
refer the following link for more details: http://wiki.alfresco.com/wiki/Web_Scripts
Or else if you want to keep your web script for only authenticated users, then you need to pass required authentication details for the user who is accessing the web script from struts. But make sure that the user must exists in alfresco.
So, add following code in your fetchComplainInfo method for basic authentication:
String basic_auth = new String(Base64.encodeBase64((YOUR_USER_NAME+":"+YOUR_PASSWORD).getBytes()));
httpPost.addHeader("Authorization", "Basic " + basic_auth);
So, your method will be like this:
public class ComplainMasterDaoImpl implements ComplainMasterDao
{
@Override
public ComplainMaster fetchComplainInfo(String orderId, String user) throws Exception
{
// TODO Auto-generated method stub
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://localhost:8383/alfresco/service/get-order- info");
String basic_auth = new String(Base64.encodeBase64((YOUR_USER_NAME+":"+YOUR_PASSWORD).getBytes()));
httpPost.addHeader("Authorization", "Basic " + basic_auth);
List<NameValuePair> formParams = new ArrayList<NameValuePair>();
formParams.add(new BasicNameValuePair("orderId", orderId));
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(formParams, "UTF-8");
httpPost.setEntity(formEntity);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
String responseString = IOUtils.toString(httpEntity.getContent(), "UTF-8");
JSONObject jsonObject = (JSONObject) new JSONParser().parse(responseString);
JSONObject resultJson = (JSONObject) jsonObject.get("result");
System.out.println(resultJson.toString());
return null;
}
}