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.
It shouldn't be necessary to edit the bundle manifest manually, as it's generated by the bundle-plugin. You're currently building an ordinary jar and not a bundle. Please add the following to your pom right below the version tag:
<packaging>container-plugin</packaging>
Now it will be built as a bundle, and the manifest will be generated correctly.
You can remove the vespa-application-maven-plugin, as that is only needed to create the application package with services.xml etc. If you like, you can put the filter classes into the main application along with any other java classes you may have, and skip the extra bundle completely.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With