Quantcast
Viewing all articles
Browse latest Browse all 2504

Access Denied (3 Comments)

Topic by priyanka jaiswal

Content

I am using Connect Web Service : Java . Tried using the sample code which was given . But I am getting access denied when I run the code

 

import java.io.PrintWriter;
import java.rmi.RemoteException;
import java.util.Calendar;

import javax.activation.DataHandler;

import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.impl.OMNamespaceImpl;
import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
import org.apache.ws.security.WSConstants;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.ServiceClient;
import org.apache.ws.security.WSConstants;

import com.rightnow.ws.base.ActionEnum;
import com.rightnow.ws.base.ID;
import com.rightnow.ws.base.NamedID;
import com.rightnow.ws.base.NamedIDWithParent;
import com.rightnow.ws.base.RNObject;
import com.rightnow.ws.generic.RNObjectType;
import com.rightnow.ws.messages.BatchRequestItem;
import com.rightnow.ws.messages.BatchResponseItem;
import com.rightnow.ws.messages.ClientInfoHeader;
import com.rightnow.ws.messages.CreateProcessingOptions;
import com.rightnow.ws.messages.DestroyProcessingOptions;
import com.rightnow.ws.messages.DestroyResponseMsg;
import com.rightnow.ws.messages.ExecuteMarketingFlowResponseMsg;
import com.rightnow.ws.messages.GetProcessingOptions;
import com.rightnow.ws.messages.QueryCSVResponseMsg;
import com.rightnow.ws.messages.QueryResultData;
import com.rightnow.ws.messages.RNObjectsResult;
import com.rightnow.ws.messages.ResetContactPasswordResponseMsg;
import com.rightnow.ws.messages.RunAnalyticsReportResponseMsg;
import com.rightnow.ws.messages.SendMailingToContactResponseMsg;
import com.rightnow.ws.messages.TransferSubObjectsResponseMsg;
import com.rightnow.ws.messages.UpdateProcessingOptions;
import com.rightnow.ws.messages.UpdateResponseMsg;
import com.rightnow.ws.metadata.MetaDataClass;
import com.rightnow.ws.objects.AnalyticsReport;
import com.rightnow.ws.objects.Answer;
import com.rightnow.ws.objects.Contact;
import com.rightnow.ws.objects.Email;
import com.rightnow.ws.objects.EmailList;
import com.rightnow.ws.objects.PersonName;
import com.rightnow.ws.wsdl.RequestErrorFault;
import com.rightnow.ws.wsdl.RightNowSyncService;
import com.rightnow.ws.wsdl.RightNowSyncServiceCallbackHandler;
import com.rightnow.ws.wsdl.RightNowSyncServiceStub;
import com.rightnow.ws.wsdl.ServerErrorFault;
import com.rightnow.ws.wsdl.UnexpectedErrorFault;

public class SampleClient {
     RightNowSyncService _service;
    
     public SampleClient() throws AxisFault
     {
      _service = new RightNowSyncServiceStub();  
      ServiceClient serviceclient = ((org.apache.axis2.client.Stub)_service)._getServiceClient();
      serviceclient.addHeader(createSecurityHeader("admin",""));
     }
    
     private OMElement createSecurityHeader(String username, String password)
        {
            // Set up the security header.
            OMFactory factory = new SOAP11Factory();
            OMNamespace wsseNS = factory.createOMNamespace(WSConstants.WSSE_NS, WSConstants.WSSE_PREFIX);

            // create the Security header block
            OMElement securityHeader = factory.createOMElement("Security", wsseNS);
            securityHeader.addAttribute("mustUnderstand", "1", null);

            // nest the UsernameToken in the Security header
            OMElement usernameTokenElement = factory.createOMElement(WSConstants.USERNAME_TOKEN_LN, wsseNS, securityHeader);

            // nest the Username and Password elements
            OMElement usernameElement = factory.createOMElement(WSConstants.USERNAME_LN, wsseNS, usernameTokenElement);
            usernameElement.setText(username);
            OMElement passwordElement = factory.createOMElement(WSConstants.PASSWORD_LN, wsseNS, usernameTokenElement);
            passwordElement.setText(password);
            passwordElement.addAttribute(WSConstants.PASSWORD_TYPE_ATTR, WSConstants.PASSWORD_TEXT, null);
            
            return securityHeader;        
        }
     private Contact populateContactInfo()
     {
             Contact newContact = new Contact();
             
             PersonName personName = new PersonName();
             personName.setFirst("Christopher");
             personName.setLast("Omland");
             newContact.setName(personName);
             
             EmailList emailList = new EmailList();
             Email[] emailArray = new Email[1];
             emailArray[0] = new Email();
             emailArray[0].setAction(ActionEnum.add);
             emailArray[0].setAddress("chris.omland@rightnow.com");
             
             NamedID addressType = new NamedID();
             ID addressTypeID = new ID();
             addressTypeID.setId(1);
             addressType.setID(addressTypeID);
             
             emailArray[0].setAddressType(addressType);
             emailArray[0].setInvalid(false);
             
             emailList.setEmailList(emailArray);
             newContact.setEmails(emailList);
             return newContact;
     }  
     public long createContact() throws RemoteException, ServerErrorFault, RequestErrorFault, UnexpectedErrorFault
        {
            Contact newContact = populateContactInfo();
            
            //Set the application ID in the client info header.
            ClientInfoHeader clientInfoHeader = new ClientInfoHeader();
            clientInfoHeader.setAppID("Axis2 Getting Started");
            
            //Set the create processing options, allow external events and rules to execute
            CreateProcessingOptions createProcessingOptions = new CreateProcessingOptions();
            createProcessingOptions.setSuppressExternalEvents(false);
            createProcessingOptions.setSuppressRules(false);
            
            RNObject[] createObjects = new RNObject[] { newContact };
            
            //Invoke the create operation on the RightNow server
            RNObjectsResult createResults = _service.create(createObjects, createProcessingOptions, clientInfoHeader);
            
            //We only created a single contact, this will be at index 0 of the results
            RNObject[] rnObjects = createResults.getRNObjects();
            newContact = (Contact)rnObjects[0];
            
            return newContact.getID().getId();
        }
    
    
    
    
     public static void main (String[] args)
     {
      try
      {
       SampleClient sampleclient = new SampleClient();
       long newContactID = sampleclient.createContact();
       System.out.println("New contact created with contact id : " +newContactID);
      }
      catch (AxisFault e)
      {
       System.out.println(e.getMessage());
       //e.printStackTrace();
       System.exit(1);
      }catch (RemoteException e)
      {
       System.out.println(e.getMessage());
       System.exit(1);
      }catch (ServerErrorFault e)
      {
       System.out.println(e.getMessage());
       System.exit(1);
      }catch (RequestErrorFault e)
      {
       System.out.println(e.getMessage());
       System.exit(1);
      }catch (UnexpectedErrorFault e)
      {
       System.out.println(e.getMessage());
       System.exit(1);
      }
      
     }

    }

This is what I get in output console :

 

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisOperation).
log4j:WARN Please initialize the log4j system properly.
Access Denied

 

Version

14.11

Viewing all articles
Browse latest Browse all 2504

Trending Articles