Allow G zip compression in wildfly-8.2.0.Final - maven

I am running my java project on wildfly-8.2.0.Final, and i want to enable G-zip compression for the web content (js, css ,jsp etc), how to achieve it.

I got it done, we need to change the standalone.xml like this
search for and then make the changes as below
<subsystem xmlns="urn:jboss:domain:undertow:1.2">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
**<filter-ref name="gzipFilter" predicate="regex[pattern='(?:application/javascript|text/css|text/html)(;.*)?', value=%{o,Content-Type}, full-match=true]"/>**
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="WildFly/8"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
**<gzip name="gzipFilter"/>**
</filters>
</subsystem>
(text in bold are the changes)

Related

How do I transform this element in my Web.config?

I've been googling for about half the day here and I'm still just as clueless as when I started on this.
Here's the relevant portion of my Web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.5.2"/>
</system.Web>
-->
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="DasExternalFileTransfer.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target name="logfile" xsi:type="File" fileName="" layout="${longdate} ${callsite} ${level} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile"/>
</rules>
</nlog>
I want to replace the fileName value under configuration/nlog/targets/target.
I have tried half a dozen different things in my Web.Dev.config. The latest would be
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<target xdt:Transform="Replace" xdt:Locator="XPath(/configuration/nlog/targets)" />
<target xdt:Transform="Replace" fileName="\\newlocation.ad\location1" />
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
To this point I have seen no effect when I preview my transform in Visual Studio.
I suspect that I am not defining the element in a way that the process can locate it, but I am not sure.
Could someone please help me figure out how to define the element properly so that I can replace the value with a new one? Or am I simply taking the wrong approach?
OK, THINK I'VE FIGURED IT OUT
It appears that the namespaces were tripping me up.
I modified this section of my Web.config
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target name="logfile" xsi:type="File" fileName="" layout="${longdate} ${callsite} ${level} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile"/>
</rules>
</nlog>
Note, I removed xmlns="http://www.nlog-project.org/schemas/NLog.xsd".
Then I modified my Web.Dev.config to
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target xdt:Transform="SetAttributes(fileName)" xdt:Locator="Match(name)" name="logfile" fileName="\\newlocation.ad\location1" />
</targets>
</nlog>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
Then, when I preview the transform, I see this as the result <target name="logfile" xsi:type="File" fileName="\\newlocation.ad\location1" layout="${longdate} ${callsite} ${level} ${message}"/>.
I just hope now that the removal of the namespace will not adversely affect NLog, but I'll be testing to determine that.
It appears that the namespaces were tripping me up.
I modified this section of my Web.config
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target name="logfile" xsi:type="File" fileName="" layout="${longdate} ${callsite} ${level} ${message}"/>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="logfile"/>
</rules>
</nlog>
Note, I removed xmlns="http://www.nlog-project.org/schemas/NLog.xsd".
Then I modified my Web.Dev.config to
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<nlog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target xdt:Transform="SetAttributes(fileName)" xdt:Locator="Match(name)" name="logfile" fileName="\\newlocation.ad\location1" />
</targets>
</nlog>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
Then, when I preview the transform, I see this as the result <target name="logfile" xsi:type="File" fileName="\\newlocation.ad\location1" layout="${longdate} ${callsite} ${level} ${message}"/>.
I just hope now that the removal of the namespace will not adversely affect NLog, but I'll be testing to determine that.

How to set default-encoding in undertow subsystem as utf-8 with a CLI script?

I'm running a WildFly10 Application Server. Now I noticed that as I changed the default encoding in the standalone.xml configuration file to utf-8, the change got erased as the server was rebooted.
Then I read up that I should use a CLI script. Now, how can I do that? What form of CLI script would add the attribute default-encoding="UTF-8" to the undertow subsystem as follows:
Here's the unmodified part of standalone.xml:
<subsystem xmlns="urn:jboss:domain:undertow:3.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="http"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
</server>
<servlet-container name="default">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="WildFly/10"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
</filters>
</subsystem>
And here it is modified, as I'd like it to be and remain in the standalone.xml:
<subsystem xmlns="urn:jboss:domain:undertow:3.0">
<buffer-cache name="default"/>
<server name="default-server">
<http-listener name="default" socket-binding="http" redirect-socket="https"/>
<host name="default-host" alias="localhost">
<location name="/" handler="welcome-content"/>
<filter-ref name="server-header"/>
<filter-ref name="x-powered-by-header"/>
</host>
</server>
<servlet-container name="default" default-encoding="UTF-8">
<jsp-config/>
<websockets/>
</servlet-container>
<handlers>
<file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>
</handlers>
<filters>
<response-header name="server-header" header-name="Server" header-value="WildFly/10"/>
<response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>
</filters>
</subsystem>
So the only thing changed here is the added default-encoding="utf-8" attribute in the <servlet-container> tag. How can I add it via a CLI script? Thank you.
run write-attribute operation on servlet-container resource
/subsystem=undertow/servlet-container=default:write-attribute(name="default-encoding", value="utf-8")

Redirect http to https is not working

I want to redirect Http to Https. So for that I created a certificate using 'keytool -genkey -alias mydomain -keyalg RSA -keystore keystore.jks -storepass password' this command.
pom.xml
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<warSourceDirectory>${webappDirectory}</warSourceDirectory>
<path>bigdata</path>
<stopPort>9966</stopPort>
<stopKey>foo</stopKey>
<httpsPort>8443</httpsPort>
<keystoreFile>/usr/local/Keystorefiles/keystore.jks</keystoreFile>
<keystorePass>arya123</keystorePass>
<password>arya123</password>
</configuration>
</plugin>
web.xml
<security-constraint>
<web-resource-collection>
<web-resource-name>securedapp</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
Server.xml
<?xml version="1.0" encoding="UTF-8"?>
<Server address="localhost" port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector address="dt" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
<!-- <Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000" redirectPort="8443" />-->
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/usr/local/Keystorefiles/keystore.jks"
keystorePass="arya123" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/>
<Engine defaultHost="dt" name="Catalina">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="dt" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t "%r" %s %b" prefix="localhost_access_log." suffix=".txt"/>
<Context docBase="HelloWeb" path="/HelloWeb" reloadable="true" source="org.eclipse.jst.jee.server:HelloWeb"/><Context docBase="SpringMVCExample" path="/SpringMVCExample" reloadable="true" source="org.eclipse.jst.jee.server:SpringMVCExample"/><Context docBase="TrialApp" path="/TrialApp" reloadable="true" source="org.eclipse.jst.jee.server:TrialApp"/><Context docBase="ABDFver3" path="/bigdata" reloadable="true" source="org.eclipse.jst.jee.server:ABDFver3"/></Host>
</Engine>
</Service>
</Server>
This much I did. But when I gave URL it doesn't redirect to Https. Could anyone help me?
I assume you don't want to manually do the 'redirect-thing'. Normally this is done by the server for you - and that's the reason why you don't just have to edit settings within your application but also on your server!
One of many tutorials for Tomcat can be found here: https://www.mulesoft.com/tcat/tomcat-ssl

Configure Data source error in JBOSS eAP 6 with oracle

Ia m using jboss 6eap .when i try to configure datasource for oracle DB i getting the below exception
JBAS014775: New missing/unsatisfied dependencies:
service jboss.jdbc-driver.oracle_jdbc_driver_OracleDriver (missing)
dependents: [service jboss.data-source.java:jboss/datasources/DefaultDS,
service jboss.driver-demander.java:jboss/datasources/DefaultDS]
config:
<module xmlns="urn:jboss:module:1.0" name="com.oracle.ojdbc6">
<resources>
<resource-root path="ojdbc6.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Here is my standalone.xml
<datasources>
<datasource enabled="true" jndi-name="java:jboss/datasources/ExampleDS"
pool-name="ExampleDS" use-java-context="true">
<connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE</connection-url>
<driver>h2</driver>
<security>
<user-name>sa</user-name>
<password>sa</password>
</security>
</datasource>
<datasource enabled="true" jndi-name="java:jboss/datasources/DefaultDS" jta="true"
pool-name="DefaultDS_pool" use-ccm="true" use-java-context="true">
<connection-url>jdbc:oracle:thin:#10.236.190.54:1521</connection-url>
<driver>oracle.jdbc.driver.OracleDriver</driver>
<pool>
<prefill>false</prefill>
<use-strict-min>false</use-strict-min>
<flush-strategy>FailingConnectionOnly</flush-strategy>
</pool>
<security>
<user-name>*</user-name>
<password>*</password>
</security>
</datasource>
<drivers>
<driver module="com.h2database.h2" name="h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
<driver module="com.oracle.ojdbc6" name="ojdbc6">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>
I tried out even stackoverflow .it seems to be everything is fine.
I think following things need to be checked on your side.
Copy your downloaded jar to following defined location or create a dir structure if not present.
JBOSS_HOME/modules/com/mysql/main
You can find a very good tutorial here : How to

Combining web.config files

Need some help combining these if you can, please.
One is to allow .html and .htm files to act like .asp files for some includes and the other is for custom 404 pages.
I've tried all sorts of variations, but everything apart from using the files separately gives me a '500 - Internal Server Error' message.
web.config 1:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="htmlinc" path="*.html" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
<add name="htminc" path="*.htm" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
</handlers>
</system.webServer>
</configuration>
web.config 2:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/404.htm" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.htm" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/404.htm" />
</customErrors>
</system.web>
</configuration>
This should work. Check parent web.config files and look for issues cause by inheritance.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.webServer>
<handlers>
<add name="htmlinc" path="*.html" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
<add name="htminc" path="*.htm" verb="*" modules="ServerSideIncludeModule" resourceType="Unspecified" />
</handlers>
<httpErrors errorMode="DetailedLocalOnly" defaultPath="/404.htm" defaultResponseMode="ExecuteURL">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" prefixLanguageFilePath="" path="/404.htm" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
<system.web>
<customErrors mode="On">
<error statusCode="404" redirect="/404.htm" />
</customErrors>
</system.web>
</configuration>

Resources