How to configure Glassfish 4 to include certain headers for a simple static website without writing java code? - http-headers

I have a simple static website (a single index.html page and some css files) being served by a Glassfish 4 server. I am required to include the following headers:
- Cache-control: no-store
- Pragma: no-cache
- List item
- X-XSS-Protection
- content-security-policy
Googling only seems to provide answers which instruct me to open bla.java and extend catalina whatchamacallit response wrapper or creating a time-space continuum filter or cooking a pot of beans or other some-such. As I said above, I don't have a single java file in the entire website. Just plain old html and css.
Isn't there something I can add to the glassfish-web.xml to tell glassfish to include those headers?
As far as I can see, for other types of server it's just a simple matter of configuring the server:
IIS: add the headers and values from IIS panel
nginx: modify nginx.conf
Apache: modify httpd.conf
Do I really have to write java code to achieve this with glassfish?
This is what the directory tree of the entire project looks like:
├MyProject
├───pom.xml
├───src
│ └───main
│ ├───frontend
│ │ ├───index.html
│ │ ├───index.css
│ │ └───index.js
│ └───webapp
│ └───WEB-INF
│ ├───glassfish-web.xml
│ └───web.xml
└───target
├───MyProject.war
├───MyProject
│ ├───index.html
│ ├───index.css
│ └───index.js
└───maven-archiver
└───pom.properties
As one can see, no java file in sight. This question is therefore not a duplicate since the answers to similar questions is not aplicable to my question.
For completenes, here are the contents of the various XMLs:
pom.xml:
<?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.some.project</groupId>
<artifactId>com.some.project</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<name>MyProject</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<finalName>MyProject</finalName>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>src/main/frontend</workingDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<!-- Add frontend folder to war package -->
<webResources>
<resource>
<directory>src/main/frontend</directory>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
glassfish-web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
<context-root>/</context-root>
</glassfish-web-app>
web.xml:
<!-- <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.4//EN" "http://java.sun.com/dtd/web-app_2_4.dtd"> -->
<web-app>
<display-name>MyProject</display-name>
</web-app>

Normally in big companies Glassfish is used together with Apache. So my idea would be to add the header information on the Apache side. But nonetheless found this page about Glassfish Server Tuning that might be useful.
Glassfish admin console
Tuning the GlassFish Server->File Cache Settings
You may find this information useful about Glassfish caching

Related

remote deployment to wildfly using cargo fails

I am trying to deploy an application to a remote wildfly 8.1.0.Final using the cargo maven plugin and it fails with error Operation failed: Could not connect to remote://10.0.0.165:9990 in 5000ms.
The application is the default application generated by the maven archetype cargo-archetype-remote-deployment. This application can be successfully deployed to jboss 7.1.1.Final without modification to the pom. I have added the following profile to the pom
<profile>
<id>wildfly8x</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>wildfly8x</containerId>
</container>
<properties>
<!--<cargo.jboss.management-native.port>9999</cargo.jboss.management-native.port>-->
<cargo.jboss.management-http.port>9990</cargo.jboss.management-http.port>
</properties>
</configuration>
<!--
The JBoss remote deployer requires some additional dependencies. Read more on:
http://cargo.codehaus.org/JBoss+Remote+Deployer
-->
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-controller-client</artifactId>
<version>7.0.2.Final</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
which is a copy of the jboss7x profile with the changes for wildfly.
The properties at the beginning have been changed to correct hostname and username and passwords. I can log into the 10.0.0.165:9990 using http and access the web interface I can also us the jboss-cli interface to login to 10.0.0.165:9990 and deploy the application to the server using the command line. I have also increased the time out as recommended but without success.
It would appear that the remote:// protocol is not available in wildfly or the name is incorrect and cargo is expecting to be able to connect using it.
I have had problems with wildfly and the changes made to interfaces in the past when I connected Netbeans 8 to it. I did eventually find the solution to that by adding back the native management interface which was removed in one of the beta versions.
Does anybody have any knowledge on how to get this working? A copy of a pom from a working example would be good. Before replying please make sure that your reply is relevant to the versions specified as jboss/redhat make changes between dot point releases with very little documentation.
Hy,
I just have the same issue, i gues you copy the example from:
http://cargo.codehaus.org/JBoss+Remote+Deployer
And I found that the example is for JBOSS 7...
For Wildfly this is what worked for me:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.12</version>
<configuration>
<container>
<containerId>wildfly8x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.remote.username>consoleUser</cargo.remote.username>
<cargo.remote.password>consolePassword</cargo.remote.password>
<cargo.hostname>IP_ADDRESS</cargo.hostname>
<cargo.jboss.management-http.port>9990</cargo.jboss.management-http.port>
</properties>
</configuration>
</configuration>
<dependencies>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-controller-client</artifactId>
<version>8.2.0.Final</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
The shame on this is the documentation and that no java people community have answer this post... have to be a .NET guy... what a shame....

Maven copy src/main/resources/services folder to /META-INF

EDIT
Ok I can be now more specific:
I have in my scr/main/resources a folder META-INF who contains services/javax.annotation.processing.Processor
My pom is still the same (with commented).
If I do "mvn clean install", the output jar will contains only the META-INF folder.
But if I rename the folder services, the output jar contains my classes and the META-INF folder with the new renamed folder and his content.
I have - I suppose - a easy question for regular maven2 users.
I have this simple pom for a simple subproject
<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>aida</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>aida-annotationProcessors</artifactId>
<packaging>jar</packaging>
<name>AIDA Annotation Processors</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<!-- <resources> -->
<!-- <resource> -->
<!-- <directory>src/main/resources/services</directory> -->
<!-- <targetPath>META-INF/services</targetPath> -->
<!-- </resource> -->
<!-- </resources> -->
</build>
<dependencies>
</dependencies>
</project>
My goal is simple:
I just want to copy my src/main/resources/services/javax.annotation.processing.Processor file in the {root}/META-INF/services folder of my generated jar.
But if I uncomment the resource part, my jar will contains only a META-INF folder without class!
Could you help me?
This is a bug/feature in the maven compiler plugin..
http://jira.codehaus.org/browse/MCOMPILER-97
A workaround is to disable annotation processing for the project containing the processor, -proc:none.
A more flexible solution would be to use an annotation processor for generating the services/javax.annotation.processing.Processor file, that way the classes are left intact and no extra work is required if the project depends on additional annotation processors.
META-INF/services generator is in main repo:
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
Annotate the processors with #MetaInfServices - note that I had to manually supply the annotation with Processor.class, otherwise it generated META-INF/services/javax.annotation.processing.AbstractProcessor
import org.kohsuke.MetaInfServices;
#MetaInfServices(javax.annotation.processing.Processor.class)
public class SoapPropertyProcessor extends AbstractProcessor
Here are the instructions from Apache for how to do that, but it appears that you're doing it correctly. Take a look at that page and make sure you're not making some small error.

how to generate download-site using maven

I am new to Maven and trying to accomplish a simple task:
build jar package and web site [DONE]
deploy them to remote server via scp [DONE]
the site should contain download page with links to the deployed jar files [MISSING]
I do not want to use archiva or similar tools. I just want to have a (static, generated) page on the web site with the links to all the built jars (or only to the latest build).
I tried:
put <item name="Downloads" href="download.html"/> into the site.xml
mvn commons:download-page
mvn deploy site:deploy
What I get:
these commands copies the jar file to remote server:
{deploy-dir}/com.acme.etc/ArtifactID/0.0.2-SNAPSHOT/ArtifactID-0.0.2-SNAPSHOT.jar
the generated download page points to
{deploy-dir}/target/site/[preferred]/commons/ArtifactID/binaries/ArtifactID-bin.tar.gz
Also there are some labels in the generated download page, like [if-any logo][end]. I suppose server should execute the script instead of displaying html. However, I can not do this as the server does not belong to me.
I guess there is a simple way (maybe totally different) to accomplish this task, could you please point out how to do it in the most simple, but automated way.
Thank you.
After deployment has started, the project metadata contains the final version. Here is a pom excerpt with a groovy script that builds a link page based upon this metadata and deploys it afterwards using deploy:deploy-file
<properties>
<!-- The base URL of your repository -->
<linkpage.repobaseurl>http://www.my.maven.repo/public</linkpage.repobaseurl>
<!-- The download page file -->
<linkpage.file>${project.build.directory}/downloadpage.html</linkpage.file>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>build-links</id>
<phase>deploy</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
<![CDATA[
def uniqueVersion = null;
pom.artifact.metadataList.each{
if(it.class.simpleName=='ProjectArtifactMetadata'){
def afi = it.class.superclass.getDeclaredField('artifact');
afi.accessible = true;
// this is the final version we need for the URLs
uniqueVersion = it.artifact.version;
}
};
def repoBase = pom.properties['linkpage.repobaseurl'];
def downloadPage = new File(pom.properties['linkpage.file']);
// build list of artifacts
def listOfArtifacts = [];
// main artifact
listOfArtifacts.add(pom.artifact);
// attached artifacts like sources, javadocs etc
listOfArtifacts.addAll(pom.attachedArtifacts);
def str = '';
listOfArtifacts.each{
def cls = it.classifier != null ? '-' + it.classifier : '';
def vers = (uniqueVersion != null ? uniqueVersion : it.version);
def parentPath = "${repoBase}/${ pom.groupId.replace( '.' , '/' )}/${pom.artifactId}/${pom.version}/"
def path = "${parentPath}${pom.artifactId}-${vers}${cls}.${it.type}"
// build the link using a here document
str += """
${it}<br />
"""
}
// now build the page using a here document
downloadPage.text="""
<html>
<head>
<title>Download page for ${project.artifact}</title>
</head>
<body>
<h1>Downloads</h1>
${str}
</body>
</html>
""";
]]>
</source>
</configuration>
</execution>
</executions>
</plugin>
<!-- now we need to manually deploy the download page using deploy:deploy-file -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>deploy</phase>
<id>deploy-downloadpage</id>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<file>${linkpage.file}</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>download</classifier>
<packaging>html</packaging>
<uniqueVersion>false</uniqueVersion>
<url>${project.distributionManagement.repository.url}</url>
<repositoryId>${project.distributionManagement.repository.id}</repositoryId>
</configuration>
</execution>
</executions>
<configuration>
</configuration>
</plugin>
</plugins>
</build>
(...) the site should contain download page with links to the deployed jar files [MISSING]
To my knowledge, this is not supported out of the box and I'm not aware of any plugin doing this (the commons-build-plugin is a specific plugin for Apache Commons builds).
You're best best is to add a custom page including Maven expression to the Maven site and to filter it to generate links to the latests version of artifacts. This is actually what the Maven site itself is doing. From the Creating Content documentation:
Filtering
Note: This feature is available in version 2.0-beta-6 or later of the
Site Plugin.
To filter properties into any
supported documentation format, add a
.vm extension to the filename.
For example, the module for the Maven
website contains a
src/site/apt/download.apt.vm
file, which uses the expression
${currentVersion} to filter in a
property set in the POM
Note: Velocity is used to apply the filtering. Because Velocity uses a
dot-notation internally you can not
use dots in your properties.
If you declare these properties in
your POM
<properties>
<!-- This will not work because the name of the property has a dot in it -->
<my.property>My value</my.property>
<!-- This will work because the name of the property has no dot in it -->
<myProperty>My other value</myProperty>
</properties>
and then use the expression
${my.property} in your document, it
will not work. If you instead use the
expression ${myProperty} it will
work just fine.

Tool for downloading eclipse plugins from update sites

I need to install an eclipse plugin to a machine not connected to the Internet and I cannot find a dist to use for a local install.
Is there a tool for downloading a plugin from an update site and create a local installation archive (or a local update site)? Rumors says you can do this with eclipse, but I cant find any info on how to do it.
You can use P2 mirror tool (or P2 mirror in Galileo documentation) to mirror remote metadata and artifacts repository.
Here is sample command to mirror Galileo artifacts repository locally:
eclipse\eclipsec.exe -nosplash -verbose
-application org.eclipse.equinox.p2.metadata.repository.mirrorApplication
-source http://download.eclipse.org/releases/galileo
-destination file:d:/temp/galileo/
eclipse\eclipsec.exe -nosplash -verbose
-application org.eclipse.equinox.p2.artifact.repository.mirrorApplication
-source http://download.eclipse.org/releases/galileo
-destination file:d:/temp/galileo/
(First command mirrors metadata, second mirrors artifacts. Command should be on one line in windows)
After you run these commands, you can use file:d:/temp/galileo as a local mirror.
Alternatively, you can use P2 Mirror Ant Task, which lets you specify installable units (plugins or features) to mirror. Note: when specifying feature, don't forget to use .feature.group suffix)
Now there is also a support for p2 sites mirroring in maven using tycho plugins: http://wiki.eclipse.org/Tycho/Additional_Tools
One of the advantage is that you can very precisely specify what installable unites you want to mirror, for which os/ws/arch, ...
For instance to mirror Eclipse Indigo you can use following pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>mirroring</groupId>
<artifactId>indigo-mirror</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<tycho.version>0.16.0</tycho.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${tycho.version}</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.tycho.extras</groupId>
<artifactId>tycho-p2-extras-plugin</artifactId>
<version>${tycho.version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>mirror</goal>
</goals>
</execution>
</executions>
<configuration>
<source>
<!-- source repositories to mirror from -->
<repository>
<url>http://ftp.sh.cvut.cz/MIRRORS/eclipse/releases/indigo/</url>
<layout>p2</layout>
<!-- supported layouts are "p2-metadata", "p2-artifacts", and "p2" (for joint repositories; default) -->
</repository>
</source>
<!-- The destination directory to mirror to. -->
<destination>${project.build.directory}/repository</destination>
<!-- Whether only strict dependencies should be followed. -->
<!-- "strict" means perfect version match -->
<followStrictOnly>false</followStrictOnly>
<!-- Whether or not to follow optional requirements. -->
<includeOptional>true</includeOptional>
<!-- Whether or not to follow non-greedy requirements. -->
<includeNonGreedy>true</includeNonGreedy>
<!-- include the latest version of each IU -->
<latestVersionOnly>false</latestVersionOnly>
<!-- don't mirror artifacts, only metadata -->
<mirrorMetadataOnly>false</mirrorMetadataOnly>
<!-- whether to compress the content.xml/artifacts.xml -->
<compress>true</compress>
<!-- whether to append to the target repository content -->
<append>true</append>
<!-- whether to mirror pack200 artifacts also. Available since tycho-extras 0.17.0 -->
<verbose>true</verbose>
<includePacked>true</includePacked>
</configuration>
</plugin>
</plugins>
</build>
</project>
You might find Building a custom Eclipse package helpful, although it's probably a bit more heavyweight that what you need.

Cargo not working over proxy integrated with maven 2

I have integrated Cargo plugin in my maven 2 project POM.xml.
During hot deployment I am unable to connect to my Tomcat container that is available across a proxy. My maven settings.xml already contain proxy setting but cargo is not picking it up.
I tried defining proxy settings for Cargo plugin expilicitly but that too didn't worked.
My plugin xml for Cargo is as:
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<!--<version>1.0.1-alpha-1</version>-->
<version>1.0-beta-1</version>
<configuration>
<container>
<containerId>tomcat6x</containerId>
<type>remote</type>
</container>
<configuration>
<type>runtime</type>
<properties>
<cargo.proxy.host>xxx.xxx.xxx.xxx</cargo.proxy.host>
<cargo.proxy.port>xxxx</cargo.proxy.port>
<cargo.hostname>xxx.xxx.xxx.xxx</cargo.hostname>
<cargo.protocol>http</cargo.protocol>
<cargo.servlet.port>80</cargo.servlet.port>
<cargo.tomcat.manager.url>http://xxx.xxx.xxx.xxx/manager</cargo.tomcat.manager.url>
<cargo.remote.username>xxxxxxx</cargo.remote.username>
<cargo.remote.password>xxxxxxx</cargo.remote.password>
</properties>
</configuration>
<deployer>
<type>remote</type>
<deployables>
<deployable>
<groupId>Test</groupId>
<artifactId>Test</artifactId>
<type>war</type>
<!--
<properties> <context>optional root context</context>
</properties> <pingURL>optional url to ping to know if deployable
is done or not</pingURL> <pingTimeout>optional timeout to ping
(default 20000 milliseconds)</pingTimeout>
-->
</deployable>
</deployables>
</deployer>
</configuration>
</plugin>
Please help.
Thanks in advance.
Ashish
I may be wrong but I don't think Cargo support this. But, as the remote deployer for Tomcat uses the manager application and thus HTTP, try to set proxy settings at the JVM level by passing properties on the command line when invoking maven:
mvn cargo:deploy -Dhttp.proxyHost=<hostname> -Dhttp.proxyPort=<port>
Or use the environment variable MAVEN_OPTS:
export MAVEN_OPTS="-Dhttp.proxyHost=<hostname> -Dhttp.proxyPort=<port>"
Hopefully this issue with proxy will be fixed in Cargo 1.1.0