Utilizar una biblioteca de cliente

Se utiliza una biblioteca de cliente para crear una solicitud de servicio web a HCL Commerce. Puede utilizar una biblioteca de cliente de servicios HCL Commerce (por ejemplo, MemberFacadeClient) en una aplicación Java estándar.

Antes de empezar

Por qué y cuándo se efectúa esta tarea

El uso de una biblioteca de cliente depende de cómo se invoque:
  • Uso de la etiqueta GetData para realizar una petición de servicio; por ejemplo, crear una petición Get mediante un JSP, aplicable al Centro de gestión y a los clientes de la tienda.
  • Uso de ComponentServiceAction; por ejemplo, crear una solicitud de cambio/procesamiento desde la tienda.
  • Uso directo de la biblioteca de cliente; por ejemplo, una aplicación J2SE.

Para utilizar una biblioteca de cliente:

Procedimiento

  1. Añada la vía de acceso al archivo JAR de la biblioteca de cliente a la vía de construcción de su aplicación Java.
  2. Inicialice la biblioteca de cliente, como puede verse en el ejemplo de código siguiente:
    private  MemberFacadeClient iClient = null;
    
    /**
     * Sets the initializes the client based on the <code>CallbackHandler</code>
     * @param aCallbackHandler {@link CallbackHandler}
     */
    private void initializeClient(CallbackHandler aCallbackHandler) {
      iClient = new MemberFacadeClient(iBusinessContext, aCallbackHandler);
    }
    
  3. Utilice la biblioteca de cliente, como puede verse en el ejemplo de código siguiente para una llamada al servicio Get:
    //Initialize the client with site admin user permissions
    initializeClient(new SampleCallbackHandlerImpl(SITE_ADMIN_LOGON_ID, SITE_ADMIN_PWD));
    
    //Create the BOD                
    GetType getType = AbstractBusinessObjectDocumentFacadeClient.createGetVerb(
      SelectionCriteriaHelper.STR_XPATH_LANG, 
      "{" + MemberFacadeConstants.SELF + "=true;" + SelectionCriteriaHelper.STR_ACCESS_PROFILE_PARAMETER 
      + "=" + MemberFacadeConstants.ACCESS_PROFILE_SUMMARY_INFORMATION + "}/Person");
    
    //Use the client library to call the Get Person Web service
    
    ShowPersonDataAreaType showPersonDAT = iClient.getPerson(getType);
    
    // Get the PersonType from the response and use the printPerson() method to display the response data
    PersonType person = (PersonType) showPersonDAT.getPerson().get(0);
    
    // Output the logon ID
    System.out.println(person.getCredential().getLogonID());
    
    Puede ver un ejemplo para llamar a un servicio Process o Change en el ejemplo de código siguiente:
    
    //Initialize the client to run as a guest user - use null as the
    callback handler
    initializeClient(null);
    Map parameters = new HashMap();
            
    parameters.put("logonId", new String[]{ "myLogonId" } );
    parameters.put("logonPassword", new String[]{ "myPassw0rd" });
    parameters.put("lastName", new String[]{"myLastName"});
    parameters.put("city",        new String[]{"Toronto"});
    
    try{
            Map result = iClient.registerPerson(parameters);
            String [] strUserId = (String[]) result.get("userId");
            System.out.println("========= New userId: " +
    strUserId[0]);
    } catch (PersonException e) {
            List listErrors = e.getClientErrors();
            if (listErrors != null) {
                    for (int i=0; i < listErrors.size(); i++) {
                            ClientError clientError = (ClientError)
    listErrors.get(i);
                            System.out.println("Message: " +
    clientError.getLocalizedMessage(Locale.ENGLISH));
                            System.out.println("Error key: " +
    clientError.getErrorKey());
                            System.out.println("Error code: " +
    clientError.getErrorCode());
                    }
            }
    }
    
  4. Procese la respuesta según sea apropiado para la aplicación Java.