Terminating Further Processing for Unavailable Header

Checking for Header

  1. Get the headers from either HttpClientRequest or HTTPServerRequest of an event.
  2. Check the header.
  3. If the header is not present or value is not proper then you can terminate the request and Local Edition would not send the request to target server.
  4. You would be able to set the status code and status message in case of termination of call in pre/post processing.
    private void doPreProcessEvent(PreProcessEvent event) throws IOException {
        MutableHTTPHeaders headers = event.getClientRequest().getHeaders();
        String custHeader = headers.get("X-Custom-Header");
        if(null == custHeader || !custHeader.equals("Allowed")){
            event.getCallContext().getResponse().getHTTPResponse().setStatusCode(HttpURLConnection.HTTP_BAD_REQUEST);
            event.getCallContext().getResponse().getHTTPResponse().setStatusMessage("Custom Header is not set in the client request");
            event.getCallContext().getResponse().setComplete();
        }
    }

Checking Parameter

  1. Get CallContext from event.
  2. From CallContext get ApplicationRequest.
  3. You can check for any parameter passed in the QueryData of ApplicationRequest.
  4. If the parameter is missing then user/developer can terminate the request and Local Edition would not sent the request to target server. You can terminate the process and set the status code and status message.
    private void doPreProcessEvent(PreProcessEvent event) {
        //Remove below line and implement code to pre process the call request
        String custParam = event.getCallContext().getRequest().getQueryData().get("customParam");
        if (custParam == null) {
            event.getCallContext().getResponse().getHTTPResponse().setStatusCode(HttpURLConnection.HTTP_BAD_REQUEST);
            event.getCallContext().getResponse().getHTTPResponse().setStatusMessage("Custom Header is not set in the client request");
            event.getCallContext().getResponse().setComplete();
        }
    }