You need to sign in to do that
Don't have an account?
CloudGeek
Apex Callout Error : Status = Forbidden 403 , Access Denied
Hi,
I am trying to make a callout to a Siebel Web Service to send the account created.
Here is what I did so far :
1. Generated the Classes from WSDL received from Siebel
2. Remote Site Setting Maintained with the URL ( http://192.168.XX.XX/SOME_PATH)
3. Created sample VF page for account Creation
4. Controller is implemented to perform call out with a @future Method
5. In the @future method, which is doing the callout actually, I have provided the access parameters for auth in the header like shown in the below code :
Still I am wondering why would this callout failed ?
Please suggest me what would have been missed or any workaround to get this resolved ?
Code of Controller :
public with sharing class calloutAccount {
public Account account { get; private set; }
public calloutAccount(ApexPages.StandardController controller)
{
Id id = ApexPages.currentPage().getParameters().get('id');
account = (id == null)? new Account() : [SELECT Name, AccountNumber, Account_Status__c FROM Account WHERE Id = :id];
}
public PageReference saveAccount()
{
try
{
upsert(account);
}
catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}
// After successful Save, navigate to the default view page
PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
DoCallout(account.Id,account.Account_Status__c);
return (redirectSuccess);
}
public PageReference cancelAccount()
{
// After Cancel, navigate to the default view page
PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
return (redirectSuccess);
}
@future(callout=true)
private static void DoCallout(Id actID,String actStatus)
{
Account account = [SELECT Name,AccountNumber,Account_Status__c FROM Account WHERE Id =: actID]; //Query for the inserted account ABOVE
System.debug(' @@@ acccount ID from FUTURE menthos() = '+ account.Id);
string UName = 'username';
string Passwd = 'password';
string SoapXMLBody;
SoapXMLBody = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:acc="http://www.siebel.com/xml/Account%20Interface"> <soapenv:Header> <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext"> http://schemas.xmlsoap.org/ws/2002/07/secext <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"> <wsse:Username>'+ UName + '</wsse:Username> <wsse:Password Type="wsse:PasswordText">' + Passwd + '</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <asi:SiebelAccountSynchronize_Input> <acc:ListOfAccountInterface> <!--Zero or more repetitions:--> <acc:Account operation="insert"> <!--Optional:--> <acc:AccountId>' + account.AccountNumber + '</acc:AccountId> <acc:AccountStatus>' + account.Account_Status__c + '</acc:AccountStatus> <acc:Name>' + account.name + '</acc:Name> </acc:Account> </acc:ListOfAccountInterface> </asi:SiebelAccountSynchronize_Input> </soapenv:Body> </soapenv:Envelope>' ;
System.debug('@@@ SoapXMLBody = '+SoapXMLBody);
string SoapXML;
SoapXML = SoapXMLBody;
Integer ContentLength = 0;
ContentLength = SoapXML.length();
Http h = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setMethod('POST');
req.setEndPoint('http://192.XXX.XX.XX/eautomotive_enu/start.swe?');
req.setHeader('Content-type','text/xml');
req.setHeader('Content-Length',ContentLength.format());
req.setHeader('SoapAction','http://192.XXX.XX.XX/eautomotive_enu/start.swe?');
req.setBody(SoapXML);
System.Debug('@@@ req.getHeader'+req.getHeader('req.getHeader; '+'Content-Length'));
System.Debug('@@@ req: '+req);
System.Debug('@@@ req.getBody'+req.getBody());
res = h.send(req);
System.Debug('@@@ res: === '+res);
String auth = res.getBody();
System.Debug('@@@ Debug(auth:'+auth);
}
}
I am trying to make a callout to a Siebel Web Service to send the account created.
Here is what I did so far :
1. Generated the Classes from WSDL received from Siebel
2. Remote Site Setting Maintained with the URL ( http://192.168.XX.XX/SOME_PATH)
3. Created sample VF page for account Creation
4. Controller is implemented to perform call out with a @future Method
5. In the @future method, which is doing the callout actually, I have provided the access parameters for auth in the header like shown in the below code :
Still I am wondering why would this callout failed ?
Please suggest me what would have been missed or any workaround to get this resolved ?
Code of Controller :
public with sharing class calloutAccount {
public Account account { get; private set; }
public calloutAccount(ApexPages.StandardController controller)
{
Id id = ApexPages.currentPage().getParameters().get('id');
account = (id == null)? new Account() : [SELECT Name, AccountNumber, Account_Status__c FROM Account WHERE Id = :id];
}
public PageReference saveAccount()
{
try
{
upsert(account);
}
catch(System.DMLException e)
{
ApexPages.addMessages(e);
return null;
}
// After successful Save, navigate to the default view page
PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
DoCallout(account.Id,account.Account_Status__c);
return (redirectSuccess);
}
public PageReference cancelAccount()
{
// After Cancel, navigate to the default view page
PageReference redirectSuccess = new ApexPages.StandardController(Account).view();
return (redirectSuccess);
}
@future(callout=true)
private static void DoCallout(Id actID,String actStatus)
{
Account account = [SELECT Name,AccountNumber,Account_Status__c FROM Account WHERE Id =: actID]; //Query for the inserted account ABOVE
System.debug(' @@@ acccount ID from FUTURE menthos() = '+ account.Id);
string UName = 'username';
string Passwd = 'password';
string SoapXMLBody;
SoapXMLBody = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:asi="http://siebel.com/asi/" xmlns:acc="http://www.siebel.com/xml/Account%20Interface"> <soapenv:Header> <wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext"> http://schemas.xmlsoap.org/ws/2002/07/secext <wsse:UsernameToken xmlns:wsu="http://schemas.xmlsoap.org/ws/2002/07/utility"> <wsse:Username>'+ UName + '</wsse:Username> <wsse:Password Type="wsse:PasswordText">' + Passwd + '</wsse:Password> </wsse:UsernameToken> </wsse:Security> </soapenv:Header> <soapenv:Body> <asi:SiebelAccountSynchronize_Input> <acc:ListOfAccountInterface> <!--Zero or more repetitions:--> <acc:Account operation="insert"> <!--Optional:--> <acc:AccountId>' + account.AccountNumber + '</acc:AccountId> <acc:AccountStatus>' + account.Account_Status__c + '</acc:AccountStatus> <acc:Name>' + account.name + '</acc:Name> </acc:Account> </acc:ListOfAccountInterface> </asi:SiebelAccountSynchronize_Input> </soapenv:Body> </soapenv:Envelope>' ;
System.debug('@@@ SoapXMLBody = '+SoapXMLBody);
string SoapXML;
SoapXML = SoapXMLBody;
Integer ContentLength = 0;
ContentLength = SoapXML.length();
Http h = new Http();
HttpRequest req = new HttpRequest();
HttpResponse res = new HttpResponse();
req.setMethod('POST');
req.setEndPoint('http://192.XXX.XX.XX/eautomotive_enu/start.swe?');
req.setHeader('Content-type','text/xml');
req.setHeader('Content-Length',ContentLength.format());
req.setHeader('SoapAction','http://192.XXX.XX.XX/eautomotive_enu/start.swe?');
req.setBody(SoapXML);
System.Debug('@@@ req.getHeader'+req.getHeader('req.getHeader; '+'Content-Length'));
System.Debug('@@@ req: '+req);
System.Debug('@@@ req.getBody'+req.getBody());
res = h.send(req);
System.Debug('@@@ res: === '+res);
String auth = res.getBody();
System.Debug('@@@ Debug(auth:'+auth);
}
}
to begin with, it seems as if you're mixing both RESTful and SOAP.
Usually, when you login via SOAP (i.e. your SOAP body), you get a session Id from the login() method and then you use this session id in the method you want to call.
You mentioned that you generated the WSDL from Siebel. Why don't you just cal the method you need from this class?
For example: If you can provide the wsdl, we can guide you and tell you which methods you need to call.
If you still want to continue modifying your current code, then you may need to set the authorization headers:
Here is my WSDL :
Please suggest me how should I do the callout ?