Skip to content

DEV, Interfaces

Tamás Kőhegyi edited this page Sep 16, 2022 · 2 revisions

Several interfaces are defined in Wilma to make the possibility of extending its functionality.

Condition Checker Interface

package com.epam.wilma.domain.stubconfig.dialog.condition.checker;

import com.epam.wilma.domain.http.WilmaHttpRequest;
import com.epam.wilma.domain.stubconfig.parameter.ParameterList;

public interface ConditionChecker {

    /**
     * Evaluates a condition defined in the stub configuration.
     * @param request the request message that will be checked
     * @param parameters the parameter list the condition checker needs
     * @return true if condition is true, false otherwise
     */
    boolean checkCondition(WilmaHttpRequest request, final ParameterList parameters);
}

Template Generator Interface

package com.epam.wilma.domain.stubconfig.dialog.response.template;

public interface TemplateGenerator {

    /**
     * Generates a stub response template, which can be use for response generation in stub module of Wilma.
     * @return with the generated template as byte array
     */
    byte[] generateTemplate();
}

Please note that the Template in Wilma shall be considered as "static", always. When a template is generated, it is generated only one time: when the JSON configuration is loaded and validated by Wilma. Once the template is generated, it cannot be changed.

In order to modify an existing (a generated or loaded) template, to create the response dynamically, the template shall be formatted, always. See Response Formatter interface below.

Response Formatter Interface (in version >2.0)

Note: In earlier versions of Wilma, the "Template Formatter" interface has been used for the same purpose.

package com.epam.wilma.domain.stubconfig.dialog.response;

import com.epam.wilma.domain.http.WilmaHttpRequest;
import com.epam.wilma.domain.stubconfig.parameter.ParameterList;
import javax.servlet.http.HttpServletResponse;

/**
 * Interface for stub response's formatter mechanism. All of the response formatters need to implement this interface.
 */
public interface ResponseFormatter {

    /**
     * Formats a response with the given parameters.
     * @param wilmaRequest     is a specific object, which contains the request headers and the uncompressed request body.
     * @param resp             is the HttpServletResponse itself, offering the possibility of setting response attributes directly
     * @param responseResource is the specified response which will be modified by the formatter
     * @param params           is the necessary parameters of the response formatter class
     * @return with the formatted response resource
     * @throws Exception if error occurs, it will be caught by the stub mechanism
     */
    byte[] formatResponse(WilmaHttpRequest wilmaRequest, final HttpServletResponse resp,
                          byte[] responseResource, final ParameterList params) throws Exception;
}

Request Interceptor Interface

package com.epam.wilma.domain.stubconfig.interceptor;

import com.epam.wilma.domain.http.WilmaHttpRequest;
import com.epam.wilma.domain.stubconfig.parameter.ParameterList;

public interface RequestInterceptor {

    /**
     * Intercepts and processes an incoming WilmaHttpRequest.
     * @param request the request to be processed
     * @param parameters the list of parameters configured from the stub configuration
     */
    void onRequestReceive(WilmaHttpRequest request, ParameterList parameters);
}

Response Interceptor Interface

package com.epam.wilma.domain.stubconfig.interceptor;

import com.epam.wilma.domain.http.WilmaHttpResponse;
import com.epam.wilma.domain.stubconfig.parameter.ParameterList;

public interface ResponseInterceptor {

    /**
     * Intercepts and processes an incoming WilmaHttpResponse.
     * @param response the request to be processed
     * @param parameters the list of parameters configured from the stub configuration
     */
    void onResponseReceive(WilmaHttpResponse response, ParameterList parameters);
}

Sequence Handler Interface

package com.epam.wilma.domain.stubconfig.sequence.handler;
import java.util.Map;

import com.epam.wilma.domain.http.WilmaHttpRequest;
import com.epam.wilma.domain.stubconfig.parameter.ParameterList;
import com.epam.wilma.domain.stubconfig.sequence.WilmaSequence;

/**
 * Handle a group of sequences based on a given logic. A group means those sequence objects which comes from the same sequence type.
 */
public interface SequenceHandler {

    /**
     * This method tries to find a WilmaSequence which belongs to the given request. If the request doesn't belong to any sequence, it will return with null.
     * @param request will be handled
     * @param store contains the collection of existing sequences.
     * @param parameters the parameter list the sequence handler needs
     * @return with the key of searched sequence. It could be null!
     */
    String getExistingSequence(final WilmaHttpRequest request, final Map<String, WilmaSequence> store, final ParameterList parameters);

    /**
     * Create a new key which is unique in a type of sequences.
     * @param request will be handled
     * @param parameters the parameter list the sequence handler needs
     * @return with a new key.
     */
    String generateNewSequenceKey(final WilmaHttpRequest request, final ParameterList parameters);
}

Service Endpoint Extension Interface

package com.epam.wilma.webapp.service.external;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Set;

/**
 * Interface that should be implemented by the Wilma external classes. Can be used to extend the REST services of Wilma.
 */
public interface ExternalWilmaService {
    /**
     * Method that will be invoked, when the response is asked to be created.
     *
     * @param req              is the original request servlet
     * @param requestedService is the requested REST service part
     * @param resp             is the response servlet
     * @return with the body of the response, or null, if no response is provided.
     */
    String handleRequest(final HttpServletRequest req, final String requestedService, HttpServletResponse resp);

    /**
     * Get the list of REST services (Strings) when Wilma will call the handleRequest method.
     *
     * @return with the list of services provided by the class.
     */
    Set<String> getHandlers();
}
Clone this wiki locally