private void addConfiguration()

in src/main/java/org/apache/sling/maven/bundlesupport/fsresource/FsMountHelper.java [132:169]


    private void addConfiguration(final URI consoleTargetUrl, FsResourceConfiguration cfg)
            throws MojoExecutionException {
        final URI postUrl = consoleTargetUrl.resolve("configMgr/" + FS_FACTORY);
        final HttpPost post = new HttpPost(postUrl);
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("apply", "true"));
        params.add(new BasicNameValuePair("factoryPid", FS_FACTORY));
        /*
         * The pid parameter is mandatory but is replaced with another value upon save() for factories
         * For that it must have the magic value from
         * https://github.com/apache/felix-dev/blob/6603d69977f4cea8b9b9dd2faf5d320906b43368/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigurationUtil.java#L36
         * This value is also used for performing a redirect and is no valid URI, therefore disable redirect handling
         */
        params.add(new BasicNameValuePair(
                "pid", "[Temporary PID replaced by real PID upon save]")); // this is replaced with a generated one,
        // upon save, still this is used for the
        // redirect
        Map<String, String> props = toMap(cfg);
        for (Map.Entry<String, String> entry : props.entrySet()) {
            params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
        }
        params.add(new BasicNameValuePair("propertylist", StringUtils.join(props.keySet(), ",")));
        post.setEntity(new UrlEncodedFormEntity(params));

        // do not follow redirects
        RequestConfig requestConfig =
                requestConfigBuilder.setRedirectsEnabled(false).build();
        HttpClientContext httpContext = HttpClientContext.create();
        httpContext.setRequestConfig(requestConfig);
        try {
            // accept also 302
            httpClient.execute(
                    post, httpContext, new ResponseCodeEnforcingResponseHandler(HttpStatus.SC_MOVED_TEMPORARILY));
            log.debug("New configuration created POST to " + postUrl);
        } catch (IOException ex) {
            throw new MojoExecutionException("Configuration on " + postUrl + " failed, cause: " + ex.getMessage(), ex);
        }
    }