We have camel based application.
Camel Context file is
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camel="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="CamelContext" xmlns="http://camel.apache.org/schema/spring" autoStartup="true">
<properties>
<property key="http.keepAlive" value="true"/>
</properties>
<threadPoolProfile id="profile"
defaultProfile="true"
keepAliveTime="30"
maxPoolSize="1500"
rejectedPolicy="DiscardOldest"
poolSize="1000"></threadPoolProfile>
<onException>
<exception>com.fasterxml.jackson.databind.exc.InvalidFormatException</exception>
<redeliveryPolicy maximumRedeliveries="0"/>
<handled>
<constant>true</constant>
</handled>
<to uri="bean:jacksonMappingExceptionHandler" />
<process ref="httpResponseTransformer"/>
</onException>
<restConfiguration component="jetty" bindingMode="json" contextPath="/app" port="9886" apiContextPath="/v1/api-doc" enableCORS="true">
<dataFormatProperty key="include" value="NON_NULL"></dataFormatProperty>
<apiProperty key="api.title" value="Application Service"/>
<apiProperty key="api.version" value="1.0.0"/>
<apiProperty key="cors" value="true"/>
</restConfiguration>
<!-- defines the rest services using the context-path /api -->
<rest path="/v1/abc" consumes="application/json" produces="application/json">
<description>Abc</description>
<post type="com.Request" outType="com.Response">
<to uri="direct-vm:JettyHttp"/>
</post>
</rest>
<rest path="/api/status" produces="application/json">
<description>Application Status</description>
<get outType="com.StatusResponse">
<description>Get Status</description>
<to uri="direct-vm:status"/>
</get>
</rest>
</camelContext>
</beans>
Some of the configuration are getting loaded from DB. Due to security, I won't be able to post full code over here.
We have written automation scripts to check validations on request.
In single specifications, we have more then 200 scenarios.
Issue: After certain amount of http request to uri, applications stops responding. I have added keepAlive property, as well as threadpool configuration in CamelContext.
However none this is working.
Kindly suggest me some work around.
Thanks in Advance.
Related
I'm using Elastic Search for my project activities in which I communicated to the backend ES cluster through the spring utility
spring-data-elastic-search
Following are the spring-repository descriptions for the webapp.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<elasticsearch:transport-client id="client" cluster-nodes="localhost:9300" />
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client" />
</bean>
<elasticsearch:repositories
base-package="com.customer.repositories" />
</beans>
Here I've specified the cluster node configuration as cluster-nodes="localhost:9300" and it is working fine with my local testing.
In production server we've a full functional cluster setup with host IP say (192.xx.xx.xx). So my problem is that, we have specified the cluster host in a yml file in /etc/project/es.yml file in the production server. So I need to tweak my application to take the cluster configuration from this custom location.
Since the above spring-repository xml initialized by the spring container, we are unable to override the behaviour. Is there any way to achieve it with spring-data-elastic-search ?
Finally I resolved my issue and sharing it here, so that it may be useful to some one else.
Changed YML idea to property file (es.props)
spring repository descriptions should be as follows
<?xml version="1.0" encoding="UTF-8"?>co
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:elasticsearch="http://www.springframework.org/schema/data/elasticsearch"
xsi:schemaLocation="http://www.springframework.org/schema/data/elasticsearch
http://www.springframework.org/schema/data/elasticsearch/spring-elasticsearch-1.0.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:property-placeholder location="file:/etc/project/es.props" />
<elasticsearch:transport-client id="client" cluster-nodes="${es-host}:9300""/>
<bean name="elasticsearchTemplate"
class="org.springframework.data.elasticsearch.core.ElasticsearchTemplate">
<constructor-arg name="client" ref="client" />
</bean>
<elasticsearch:repositories
base-package="com.customer.repositories" />
</beans>
Which used Spring PropertySourcePlaceHolder modification mechanism in 3.1+.
So it will look up for es.host in /etc/project/es.props. Local testers can override this property by starting the server with -Des.host=custom-cluser-host
Actually Mohsin(Spring-data-elastic-search developer) gave hints to arrive at this solution. Thanks Mohsin.
0 and have problem where to put public files
I tried Where to place images/CSS in spring-mvc app? this soluion but its not working for me
I have tried to place my public folder every where in WEB-INF directory outside but still nothing
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<display-name>s-mvc</display-name>
<servlet>
<servlet-name>frontController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<mvc:resources mapping="/css/**" location="/css/"/>
</web-app>
frontcontroller-servlet.xml
<mvc:annotation-driven/>
<context:component-scan base-package="pl.skowronline.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
and that how I call css file
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet" />
I think you are getting confused with the web.xml and the application-context.xml.
The web.xml should contain the webapp xsd declarations like this, and the mapping for the Dispatcher Servlet.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>s-mvc</display-name>
<servlet>
<servlet-name>frontController</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Where as the application-context.xml contains the spring-framework xsd declarations like below
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:annotation-driven />
<context:component-scan base-package="pl.skowronline.controller" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
the answer from JB Nizet is correct. However, it seems the problem of your application is more than just a place to put css/js file. For Spring MVC, you must put all configuration right, or it will not work.
For simplicity, just put the css folder right in the WEB-INF folder (/WEB-INF/css), so that you can access it like this in your page:
<a href="<c:url value='/css/bootstrap.css'/>"
That link should take you directly to the css file. If it works, you can change the <a> tag into the <link> tag for CSS styling.
If it doesn't work, there are a few things to check:
1) Spring Security constraints that forbid you to access the files
2) The affect of various filters/ interceptors that can hinder your file access
3) Servlet Configuration in web.xml. Make sure that no dispatcher intercept your access to the CSS file.
Often, <mvc:resources> will do all the above things for you. But just in case it failed, you may want to have a look.
For the <mvc:resources> error:
The matching wildcard is strict, but no declaration can be found for
element 'mvc:resources'.
It looks like you haven't declared the right schema yet. For example, you should add the following lines in the beginning of your file:
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
UPDATE:
As your response, the problem seems to be here:
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
You should change it to:
<servlet-mapping>
<servlet-name>frontController</servlet-name>
<url-pattern>/*.html</url-pattern>
</servlet-mapping>
This will save the URL for the css/images files from conflicting with the URL mapping of controller (your servlet), and it let mvc:resources do it magic. Of course, you can use what ever extension you want for "html" part. For a beautiful URL, we may use a library like Turkey URL rewrite to solve the problem
This is described in the following section of the documentation. Follow the instructions given there, and then change your href: /css/bootstrap.css means: In the folder css right under the root of the server. So, unless your application is deployed as the root application, it won't work, because you need to prepend the context path of your app:
href="<c:url value='/css/bootstrap.css'/>"
And this will thus mean: in the css folder, right under the root of the webapp. If the context path of your webapp is /myFirstWebApp, the generated href will thus be
href="/myFirstWebApp/css/bootstrap.css"
You can try using context path to locate resource files.
<link type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css" rel="stylesheet" />
Read this to know more.
I too had the same problem.Please perform below steps to get it work which worked well for me and my teammates as well.
Step1 :- Create a folder in Web-INF with name "resources"
Step2 :- Upload your bootstrap,css and js if you already do have or in case if you want to write it write inside this folder
Step3 :- Now Update your dispatcher servlet xml as below
Add Below code within beans tag
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
Add below code to xsi:schemaLocation at top of this xml
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
step 4:- now you can use css,bootstrap resouces in your code as below
<header class="custem_header_bg"><img src="resources/img/product_banner.png" class="img-responsive"> </header>
You can only set base on JSP as following steps. Then you don't need to set mvc:resources in web.xml.
Just set base as following. Also we can use header file to set this value. Then we can include that header.jsp in to any page we are using in application. Then we dont need to set this value in every JSP.
You need to set <base/> as following...
<c:set var="req" value="${pageContext.request}" />
<c:set var="url"> ${req.requestURL} </c:set>
<c:set var="uri" value="${req.requestURI}" />
<head>
<title></title>
<base href="${fn:substring(url, 0, fn:length(url) - fn:length(uri))}${req.contextPath}/" />
Then You can Import any JS or CSS like below..
<script src="assets/js/angular/angular.js"></script>
Can someone please tell me how to configure JNDI name in SPRING MVC? I am using jboss version7.1.1 and DB is oracle 11g. I have defined the JNDI in jBoss server. How to mention the JNDI name in spring-servlet.xml? I have tried many options its not working. I am keep getting Name Not found exception.
<jee:jndi-lookup id="dataSource"
jndi-name="java:jboss/datasources/ExampleDS"
expected-type="javax.sql.DataSource" />
Where the value of jndi-name matches what you have configured in JBoss. You need to register jee namespace something like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd">
I'm developing a software based upon Spring and ICEFaces.
I have a file at <project directory>/src/main/webapp/WEB-INF/views/<filename>.xhtml, that is correctly reached using the following URL: http://<hostname>/<projectname>/<filename>.xhtml
The file contains a <h:form id="formId"> which is rendered as a <form action="/<projectname>/WEB-INF/views/<filename>.xhtml" [.. some other stuff ..]>
It means that, when I click on the input submit contained in the form, the browser tries to open the URL http://<hostname>/<projectname>/WEB-INF/views/<filename>.xhtml and, as I said in the title, it shows an error 404 page.
I'd like that the file .xhtml could be reached using the "longer" URL, too. I'm pretty sure that I'm currently unable to achieve that due to a configuration error.
This is my web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<web-app>
<display-name>SIGLO</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
This is the applicationContext.xml referenced in the previous file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd" >
<context:component-scan base-package="com.infoone.siglo" />
<!--
map all requests to /resources/** to the container default servlet
(ie, don't let Spring handle them)
-->
<bean id="defaultServletHttpRequestHandler" class="org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler" />
<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" >
<property name="urlMap" >
<map>
<entry key="/resources/**" value-ref="defaultServletHttpRequestHandler" />
</map>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" />
<mvc:annotation-driven />
<!-- JSF for representation layer. All JSF files under /WEB-INF/views directory -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name="cache" value="false" />
<property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="icefacesResourceHandler" class="org.springframework.faces.webflow.JsfResourceRequestHandler" />
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="order" value="0" />
<property name="mappings">
<value>
/javax.faces.resource/**=icefacesResourceHandler
</value>
</property>
</bean>
</beans>
And, in the end, this is my faces-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd">
<application>
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
<locale-config></locale-config>
<resource-bundle>
<base-name>MessageResources</base-name>
<var>msg</var>
</resource-bundle>
</application>
</faces-config>
Let me point out that this configuration still does not allow me to open successfully the shorter URL. Indeed, I have to create a proper controller or, better, a proper #RequestMapping inside a #Controller:
#RequestMapping(value = "<filename>", method = RequestMethod.GET)
public String creaBlocco()
{
return "<filename>";
}
#RequestMapping(value = "<filename>", method = RequestMethod.POST)
public String creaBlocco([.. parameters ..]) {
[.. stuff ..]
return "<filename>";
}
Yes, the value of the #RequestMapping is "<filename>", without the .xhtml extension. I already made sure, by trial and error, that such mapping is necessary for the GET to be successful. On the other hand, I realize that such configuration is really fragile. What should I change in my config files, in order to make <filename>.xhtml reachable using also the longer URL?
Thanks in advance for your attention.
After some research, I came up with the conclusion that I wasn't using those technologies in the way they're meant to be used. If you're facing my same problem, within the same context, you are probably making my same error, therefore you have to slightly modify your application architecture to solve it. Indeed, it seems that using JSF/ICEFaces and Spring MVC in conjunction with Spring WebFlow is the most comfortable and straightforward approach.
I'll try to explain the rationale.
Your site/user home page is filled up with links to the use cases (or, better, flows) that can be activated with his/her privileges. Those links look like http://<page-url>?<flow-id>. A flow in Spring WebFlow is defined as a graph of states, within an xml file. The transitions between states are labeled by strings, named actions, or conditions. Some states are view-state s, meaning that there's something to show to the user when such a state is reached. Therefore, for each view-state named <state-id>, there shall be an .xhtml file named <state-id>.xhtml.
The buttons provided by JSF and ICEFaces will always be rendered as <input type="submit" [..]> and the action of the containing form will always point to the same URL as the containing page (i.e. http://<page-url>?<flow-id>). That's a fact.
The difference is that, in this case, such URL is not backed by a real file (like in my question) but, if the app is properly configured, a flow-handler will answer and manage all the states and the transitions defined in the xml file, choosing the proper view to show.
Beside that, the buttons provided by JSF and ICEFaces have an action attribute. As you can imagine, they correspond to the actions defined in the flow definition file: therefore, a click on a button with a certain value of the action attribute will trigger the transition from the current state labeled exactly with that string.
Speaking more concretely, if you click on the button, the browser sends a POST request to http://<page-url>?<flow-id> whose body contains all the necessary parameters. The flow handler receives that POST request and computes the next state, possibly choosing which view has to be shown to the user.
If you're still reading this answer, I guess you need a concrete example to refer to. I'll provide you with the one I used to learn all the things I wrote here: http://wiki.icesoft.org/display/ICE/Spring+Web+Flow+2.3.1 It's an awesome starting point, because it's easy but exhaustive.
I have created a login page using a nice guide that I found about Java EE6 and GlassFish3 using netbeans.
After deploying the project when I try to reach the login page I get 'HTTP Status 403 - Access to the requested resource has been denied' from GlassFish3 server.
The url I am using is : http://localhost:9999/simplewebapp/admin/admin.jsp
The guide says that I should automatically be redirected to the login page I have created.
Instead I am receiving the above error.
Looking at the glassfish3 log I am getting these two lines when I am entering the above url.
INFO: JACC Policy Provider:Failed Permission Check: context (" simplewebapp/simplewebapp ") , permission (" (javax.security.jacc.WebUserDataPermission /admin/login.jsp GET) ")
INFO: JACC Policy Provider:Failed Permission Check: context (" simplewebapp/simplewebapp ") , permission (" (javax.security.jacc.WebUserDataPermission /admin/login.jsp GET:CONFIDENTIAL) ")
Some more details :
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Administrative Pages</web-resource-name>
<description/>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>admin</description>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrators</description>
<role-name>admin</role-name>
</security-role>
<security-role>
<description>Users</description>
<role-name>user</role-name>
</security-role>
</web-app>
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="">
<security-role-mapping>
<role-name>admin</role-name>
<group-name>appadmin</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
What am I doing wrong here?
Thank you.
Problem solved.I had to add principal names in glassfish-web.xml and a role-name in web.xml.
Correct files :
web-xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Admin Pages</display-name>
<web-resource-collection>
<web-resource-name>Administrative Pages</web-resource-name>
<description/>
<url-pattern>/admin/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>admin</description>
<role-name>AdminRole</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/loginerror.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrators</description>
<role-name>AdminRole</role-name>
</security-role>
<security-role>
<description>Users</description>
<role-name>UserRole</role-name>
</security-role>
</web-app>
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="">
<security-role-mapping>
<role-name>AdminRole</role-name>
<principal-name>admin</principal-name>
<group-name>appadmin</group-name>
</security-role-mapping>
<security-role-mapping>
<role-name>UserRole</role-name>
<principal-name>user</principal-name>
<group-name>appuser</group-name>
</security-role-mapping>
<class-loader delegate="true"/>
<jsp-config>
<property name="keepgenerated" value="true">
<description>Keep a copy of the generated servlet class' java code.</description>
</property>
</jsp-config>
</glassfish-web-app>
Using glassfish Admin Console this worked for me:
Select ‘server-config’ listed under Configurations and access the Security page. On that page
you need to enable the ‘Default Principal to Role Mapping’ option. The benefit of enabling this option is that it enables us to use roles defined for users shortly automatically without
requiring us to make formal XML declarations in a glassfish configuration file for our project.
For keeping it "standard" I think this is the better option, because if you're using just a web container (eg. tomcat), you're not gonna have to configure nothing else that just a realm. In my case, I was using Eclipse and had to undeploy the project and redeploy it.
Thank you very much.