HttpServletRequest request = (HttpServletRequest) FacesContext .getCurrentInstance().getExternalContext().getRequest();
HttpServletRequest request = (HttpServletRequest) FacesContext .getCurrentInstance().getExternalContext().getRequest();
The main responsibility of class loaders is to find and load the classes[1]. What do we get to do with this. First I’d like to explain the first terms. In class loading we have;
How does this help us? Well if you are using different jar stack than IBM provides, like JSF library in my case, then you will have some troubles with it. In our project our stack was JSF 2.2 Mojarra and Primefaces 6.0 with JDK 1.8. This option can be found All Applications > APPLICATION > Class loader.
However, this option is global setting. If your project EAR, contains multiple WAR files and context and some of them shall be excluded from this operation. Well you can also set class loading separately on the WAS console
All Applications > APPLICATION > Manage Modules > MODULE.war
I assume that the disadvantage of setting the class loading on the console is not permanent, every time you need to make this setting. However, there is an alternative way to set the class loading in a class way during the deployment. In my example I’ll show an EAR having 2 modules, one of them the JSF project will have the class loading set as PARENT_LAST and the other project as a default setting will have the PARENT_FIRST option. The target project is a maven multiple module project [2] [3]. We will succeed this operation by using a deployment.xml file in the EAR project.
Parent pom.xml
The version of the jsf project is kept here, I’ll explain the main reason further.
<properties> <supporttool.version>1.0.0</supporttool.version> </properties>
Ear project pom.xml
<?xml version="1.0"?> <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> <parent> <artifactId>WINS</artifactId> <groupId>PACKAGENAME</groupId> <version>18.0-SNAPSHOT</version> </parent> <artifactId>WinsEar</artifactId> <packaging>ear</packaging> <name>WinsEar</name> <build> <plugins> <plugin> <artifactId>maven-ear-plugin</artifactId> <version>2.5</version> <configuration> <generateApplicationXml>true</generateApplicationXml> <version>5</version> <modules> <webModule> <groupId>PACKAGENAME</groupId> <artifactId>WebClient</artifactId> <contextRoot>/wins</contextRoot> </webModule> <webModule> <groupId>PACKAGENAME</groupId> <artifactId>WINSSupportToolWeb</artifactId> <contextRoot>/supporttool</contextRoot> </webModule> </modules> </configuration> </plugin> </plugins> </build> <dependencies> <dependency> <groupId>PACKAGENAME</groupId> <artifactId>WebClient</artifactId> <version>18.0-SNAPSHOT</version> <type>war</type> </dependency> <dependency> <groupId>PACKAGENAME</groupId> <artifactId>WINSSupportToolWeb</artifactId> <version>${supporttool.version}</version> <type>war</type> </dependency> </dependencies> </project>
Here you don’t have to create an explicit application xml file that has the settings for each project. In the ear pom, the <generateApplicationXml> tag will create one for you.
Creating path for deployment.xml file
Now this is the very tricky part. You have to create the following path in your EAR project accordingly;
EARPROJECT\src\main\application\META-INF\ibmconfig\cells\defaultCell\applications\defaultApp\deployments\defaultApp
deployment.xml
Now after we are sure that the above folders are created successfully, then we can create our file
<?xml version="1.0" encoding="UTF-8"?> <appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1495796489455"> <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1495796489455" startingWeight="100"> <modules xmi:type="appdeployment:WebModuleDeployment" startingWeight="10000" uri="WINSSupportToolWeb-1.0.0.war" classloaderMode="PARENT_LAST"/> <!-- To set the classloading level as "PARENT_LAST" for the whole modules, remove the above line and commment out the below line --> <!--<classloader xmi:id="Classloader_1297859327856" mode="PARENT_LAST"/>--> </deployedObject> </appdeployment:Deployment>
you need to ensure that maven will create the project as it is defined in the detployment.xml file, otherwise it will not work out.
References
This is issue recently occurred at work while I was working on the migration to IBM WAS 8.5. The migration was from WAS 7.0 and JDK 1.6 to WAS 8.5 JDK1.8. The issue rises if you compile the project with a different(in my case lower) JDK version that the installed on the server. To resolve this issue compile the project with the proper java version.
if an older version of java is set as your java home then;
open the file “visualvm.conf” in %VISUALVMROOT% etc folder
uncomment and change the line:
visualvm_jdkhome="C:\jdk1.8.0_75"
I’ve tested this in the Primefaces 6.0 and JSF 2.2 configuration
https://www.primefaces.org/showcase/ui/misc/fa.xhtml
http://fontawesome.io/cheatsheet/
Before
After
web.xml
<context-param> <param-name>primefaces.FONT_AWESOME</param-name> <param-value>true</param-value> </context-param> <mime-mapping> <extension>woff2</extension> <mime-type>application/x-font-woff2</mime-type> </mime-mapping>
jsf page
<p:column headerText="Actions"> <p:commandButton type="button" value="Edit" icon="fa fa-fw fa-edit"/> <p:commandButton type="button" value="Delete" icon="fa fa-fw fa-remove"/> </p:column>
Spring is a very powerful framework, its security framework offers a splendid mechanism and security. It also integrates with other frameworks well too. In this post I’ll share an example of how you can show the content of a page depending on user’s role. I am assuming that you already have a spring security setup with spring security expressions are enabled in the config file. Now let’s start out;
1. create a file called “springsecurity.taglib.xml” underneath WEB-INF folder,
<?xml version="1.0"?> <!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/facelet-taglib_1_0.dtd"> <facelet-taglib> <namespace>http://www.springframework.org/security/tags</namespace> <tag> <tag-name>authorize</tag-name> <handler-class>org.springframework.faces.security.FaceletsAuthorizeTagHandler</handler-class> </tag> <function> <function-name>areAllGranted</function-name> <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class> <function-signature>boolean areAllGranted(java.lang.String)</function-signature> </function> <function> <function-name>areAnyGranted</function-name> <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class> <function-signature>boolean areAnyGranted(java.lang.String)</function-signature> </function> <function> <function-name>areNotGranted</function-name> <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class> <function-signature>boolean areNotGranted(java.lang.String)</function-signature> </function> <function> <function-name>isAllowed</function-name> <function-class>org.springframework.faces.security.FaceletsAuthorizeTagUtils</function-class> <function-signature>boolean isAllowed(java.lang.String, java.lang.String)</function-signature> </function> </facelet-taglib>
2. Register the taglib file in the web.xml file,
<context-param> <param-name>javax.faces.FACELETS_LIBRARIES</param-name> <param-value>/WEB-INF/springsecurity.taglib.xml</param-value> </context-param>
3. Include required dependencies,
<properties> <spring-security.version>3.1.2.RELEASE</spring-security.version> <spring-faces.version>2.4.1.RELEASE</spring-faces.version> </properties> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> <version>${spring-security.version}</version> <scope>compile</scope> </dependency> <dependency> <groupId>org.springframework.webflow</groupId> <artifactId>spring-faces</artifactId> <version>${spring-faces.version}</version> <scope>compile</scope> </dependency>
Now up to this point we are all set to use the implementation. From now on we can use this solution for;
a)Showing a nested content conditionally depending on roles and some other metrics;
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:sec="http://www.springframework.org/security/tags"> <sec:authorize ifAllGranted="ROLE_FOO, ROLE_BAR"> Lorem ipsum dolor sit amet </sec:authorize> <sec:authorize ifNotGranted="ROLE_FOO, ROLE_BAR"> Lorem ipsum dolor sit amet </sec:authorize> <sec:authorize ifAnyGranted="ROLE_FOO, ROLE_BAR"> Lorem ipsum dolor sit amet </sec:authorize> </ui:composition>
b)Using the role as a metric to hide/show some components depending on the role;
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:sec="http://www.springframework.org/security/tags"> <!-- Rendered only if user has all of the listed roles --> <h:outputText value="Lorem ipsum dolor sit amet" rendered="#{sec:areAllGranted('ROLE_FOO, ROLE_BAR')}"/> <!-- Rendered only if user does not have any of the listed roles --> <h:outputText value="Lorem ipsum dolor sit amet" rendered="#{sec:areNotGranted('ROLE_FOO, ROLE_BAR')}"/> <!-- Rendered only if user has any of the listed roles --> <h:outputText value="Lorem ipsum dolor sit amet" rendered="#{sec:areAnyGranted('ROLE_FOO, ROLE_BAR')}"/> <!-- Rendered only if user has access to given HTTP method/URL as defined in Spring Security configuration --> <h:outputText value="Lorem ipsum dolor sit amet" rendered="#{sec:isAllowed('/secured/foo', 'POST')}"/> </ui:composition>
References
https://docs.spring.io/spring-webflow/docs/current/reference/html/spring-faces.html
http://docs.spring.io/autorepo/docs/webflow/2.3.x/reference/html/spring-faces.html#spring-faces-security-taglib
https://stackoverflow.com/a/15378140/1958683
http://keylesson.com/index.php/2015/06/18/spring-security-authorize-tag-example-1993/
This has been tested in JDK 7. Please download 7Zip application. WinRAR does not assist along this process
1.Download a desired JDK version from prior downloads at http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
2.Create a folder in where you want to keep the jdk,
3.Copy the downloaded .exe file in here,
4.Right click on exe and 7-Zip>>Extract Here,
5.Right click on tools.zip >> 7-Zip >> Extract Here,
6.Open a command line and issue the command in the folder, this code will convert files to jar
[code]
for /r %x in (*.pack) do .\bin\unpack200 -r “%x” “%~dx%~px%~nx.jar”
[/code]
7.remove the tools.zip and the .exe file
8. issue java -version to test the result
[code]
pg_dump –host HOSTADDR&nbsp;–port 5432 –username “wins_qa” –format plain –encoding UTF8 –schema-only –no-owner –file %HOME%”\Desktop\create_query.sql” –schema “wins_qa” “gwinsq01”
[/code]
this query will;
For more information consult the PostgreSQL Documentation at https://www.postgresql.org/docs/current/static/app-pgdump.html
[code]
psql -h localhost -d databasename -U username -f file.sql
[/code]
this query will restore the data from the sql query into the selected database
For more information consult the PostgreSQL Documentation at https://www.postgresql.org/docs/current/static/app-psql.html
css file
[code]
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.clearfix:after{
content: “”;
display: table;
clear: both;
}
body {
font-size: 18px;
font-family: Helvetica Neue, Arial;
}
h1,
h2 {
color: #019801;
}
h1 {
font-size: 40px;
margin-bottom: 20px;
}
h2 {
font-size: 25px;
margin-bottom: 10px;
}
.main-text {
text-align: justify;
margin-bottom: 20px;
}
#author-text {
font-size: 22px;
}
.container {
width: 1140px;
margin-left: auto;
margin-right: auto;
}
.blog-post{
background-color: #000ff0;
width: 75%;
float: left;
}
.other-posts{
background-color: #00ff00;
width: 25%;
float: left;
}
.author-box{
background-color: #ffff00;
}
[/code]
html file
[code]
<div class=”container”>
<div class=”blog-post”>
<h1>My first blog post</h1>
<h2>This is my first blog post</h2>
<p class=”main-text”>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<img src=”logo.jpg” alt=”This is HTML5 logo”>
<a href=”http://www.udemy.com” target=”_blank”>Link to Udemy</a>
<a href=”logo.jpg” target=”_blank”>HTML logo</a>
<h2>HTML is amazing</h2>
<p class=”main-text”>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</div>
<div class=”other-posts”>
Dummy text
</div>
<div class=”clearfix”></div>
<div class=”author-box”>
<img src=”author.jpg” alt=”Author Photo”>
<p class=”main-text”> Florence Smith</p>
</div>
</div>
[/code]
[code]
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”utf-8″>
<meta http-equiv=”X-UA-Compatible” content=”IE=edge”>
<meta name=”viewport” content=”width=device-width, initial-scale=1″>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css” integrity=”sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp” crossorigin=”anonymous”>
<link rel=”stylesheet” href=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css” integrity=”sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u” crossorigin=”anonymous”>
<style type=”text/css”>
body {
background: #eee !important;
}
.page-header{
margin-top: 0 !important;
}
.panel-body{
padding-top: 0;
}
.featuredImg{
margin-bottom: 15px;
}
</style>
<!– HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries –>
<!– WARNING: Respond.js doesn’t work if you view the page via file:// –>
<!–[if lt IE 9]>
<script src=”https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js”></script>
<script src=”https://oss.maxcdn.com/respond/1.4.2/respond.min.js”></script>
<![endif]–>
</head>
<body>
<div class=”container”>
<div class=”row”>
<div class=”col-lg-9″>
<div class=”panel panel-default”>
<div class=”panel-body”>
<div class=”page-header”>
<h3>Page Header Section</h3>
</div>
<img class=”featuredImg” src=”https://cnet3.cbsistatic.com/img/syklRsrXJcU4HS4I9FxtIikHa-k=/770×433/2014/10/13/0ea985b4-9f3a-43d0-9a47-21154c864996/samsung-galaxy-note-4-9024.jpg” width=”100%”>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
<h4>Another heading</h4>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum</p>
</div>
</div>
</div>
<div class=”col-lg-3″>
<div class=”list-group”>
<a href=”#” class=”list-group-item active”>
<h4 class=”list-group-item-heading”>Article 1</h4>
<p class=”list-group-item-text”>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</p>
</a>
<a href=”#” class=”list-group-item”>
<h4 class=”list-group-item-heading”>Article 2</h4>
<p class=”list-group-item-text”>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</p>
</a>
<a href=”#” class=”list-group-item”>
<h4 class=”list-group-item-heading”>Article 3</h4>
<p class=”list-group-item-text”>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</p>
</a>
<a href=”#” class=”list-group-item”>
<h4 class=”list-group-item-heading”>Article 4</h4>
<p class=”list-group-item-text”>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium</p>
</a>
</div>
</div>
</div>
</div>
<script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js”></script>
<script src=”https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js” integrity=”sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa” crossorigin=”anonymous”></script>
</body>
</html>
[/code]