I have followed the question Enable CORS in vespa and have written and build a new custom "filter-bundle" package with RequestFilter and ResponseFilter that adds headers enabling CORS. This is my pom.xml file for building the bundle
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yahoo.bundle</groupId>
<artifactId>filter-bundle</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.yahoo.vespa</groupId>
<artifactId>container</artifactId>
<version>6.297.80</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.yahoo.vespa</groupId>
<artifactId>vespa-application-maven-plugin</artifactId>
<!-- Zip the application package -->
<version>6.297.80</version>
<executions>
<execution>
<goals>
<goal>packageApplication</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.yahoo.vespa</groupId>
<artifactId>bundle-plugin</artifactId>
<version>6.297.80</version>
<extensions>true</extensions>
<configuration>
<attachBundleArtifact>true</attachBundleArtifact>
<bundleSymbolicName>filter-bundle</bundleSymbolicName>
<bundleVersion>1.0.2</bundleVersion>
</configuration>
</plugin>
</plugins>
</build>
</project>
I added the built jar bundle to the /components directory of my "main" application package and made the suggested changes in my services.xml file following the link https://docs.vespa.ai/documentation/jdisc/http-server-and-filters.html I added the following HTTP tag to my services.xml file.
<http>
<filtering>
<filter id='request-filter' class='com.yahoo.bundle.MyRequestFilter' bundle="filter-bundle" />
<filter id='response-filter' class='com.yahoo.bundle.MyResponseFilter' bundle="filter-bundle" />
<request-chain id='request-chain'>
<filter id='request-filter' />
<binding>http://*/*</binding>
</request-chain>
<response-chain id='response-chain'>
<filter id='response-filter' />
<binding>http://*/*</binding>
</response-chain>
</filtering>
<server port="8080" id="main-server" />
</http>
Here "MyRequestFilter" and "MyResponseFilter" are the class names in my filter-bundle (Inside the built filter-bundle jar placed in the application/components directory).
Following these steps gave me an error that a few headers like "Bundle-SymbolicName", "Bundle-ManifestVersion" were missing in my MANIFEST.MF file in the filter-bundle's jar file. So I edited the MANIFEST.MF file to add the required headers following https://docs.vespa.ai/documentation/bundle-plugin.html Edit-1: Adding "container-plugin" line correctly generated the MANIFEST.MF file
But, after successfully building my application with the above changes in the jar file, I am still not able to see the added headers in my Request or Response to/from Vespa, and still getting an error that the CORS is disabled on Vespa.