How to CORS enable in jasper-server for reactJS? - reactjs

I'm trying to consume API as a get request from jasper-server in my reactjs application. Unfortunately, I got error message "Cross-Origin Request Blocked".
I config web.xml file which is from jasperserver/webapp/web-inf and also config tomcat web.xml. Both are configured by using this filter.
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>http://10.11.200.42:3000</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST,HEAD,OPTIONS,PUT</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.headers</param-name>
<param-value>Content-Type,X-Requested-With,accept,Origin,Access-Control-Request-Method,Access-Control-Request-Headers</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>Access-Control-Allow-Origin,Access-Control-Allow-Credentials</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>1800</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Go to this location(jaspersoft\jasperreports-server\apache-tomcat\webapps\jasperserver\WEB-INF) where you install your jasperosft and configure web.xml file using below code.
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>com.jaspersoft.jasperserver.api.security.csrf.CorsFilter</filter-class>
<init-param>
<param-name>cors.allowed.origins</param-name>
<param-value>http://localhost:port</param-value>
</init-param>
<init-param>
<param-name>cors.allowed.methods</param-name>
<param-value>GET,POST</param-value>
</init-param>
<init-param>
<param-name>cors.exposed.headers</param-name>
<param-value>
Access-Control-Allow-Origin,Access-Control-Allow-Credentials
</param-value>
</init-param>
<init-param>
<param-name>cors.support.credentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.preflight.maxage</param-name>
<param-value>1800</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Related

Prerender io java wrong route

I am having a problem with prerender.io. It works just fine if I am using node/express on localhost, but when I am trying to make it work with java (https://github.com/greengerong/prerender-java/) on google app engine it re-routes automatically.
When I write this into my browser and hit enter,
http://www.example.com/?_escaped_fragment_=/browse/761238167868/
It redirects automatically to
http://www.example.com/?_escaped_fragment_=/browse/761238167868#!/browse
In app.js I have the following:
module.config(['$routeProvider','$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.when('/browse', {
templateUrl: 'views/browse.html'
//a lot of .when() ....
}).otherwise({redirectTo: '/browse'});
I believe it is a problem with the app engine server or the middleware installation, because it works just fine with node/express.
Do I need to rewrite something to make app engine handle hashbangs (#!) or something?
Here's my web.xml:
<filter>
<filter-name>prerender</filter-name>
<filter-class>com.github.greengerong.PreRenderSEOFilter</filter-class>
<init-param>
<param-name>crawlerUserAgents</param-name>
<param-value>FacebookExternalHit</param-value>
</init-param>
<init-param>
<param-name>crawlerUserAgents</param-name>
<param-value>facebookexternalhit</param-value>
</init-param>
<init-param>
<param-name>crawlerUserAgents</param-name>
<param-value>facebookexternalhit/1.0</param-value>
</init-param>
<init-param>
<param-name>crawlerUserAgents</param-name>
<param-value>facebookexternalhit/1.1</param-value>
</init-param>
<init-param>
<param-name>crawlerUserAgents</param-name>
<param-value>Facebot</param-value>
</init-param>
<init-param>
<param-name>prerenderToken</param-name>
<param-value>mytoken</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>prerender</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Jsp serverlet mapping url-pattern /* overrides the welcome-file

I'm building a site on Google app engine with Java.
There I'm trying to map jsp pages with servlet mapping as follows:
http://localhost:8080/<any text> should map to r.jsp
http://localhost:8080 should map to home.jsp
But those two urls always get mapped to r.jsp.
And my web.xml is as follows:
<servlet>
<servlet-name>r</servlet-name>
<jsp-file>/r.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>home</servlet-name>
<jsp-file>/home.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>home</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>
I also tried <url-pattern>""</url-pattern> instead of <url-pattern>/</url-pattern> and it also did not work
Any servlet mapping solution for this?
Change you web.xml to something like this
<servlet>
<servlet-name>r</servlet-name>
<jsp-file>/r.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/ewerw</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/rrrxdsfwef</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>r</servlet-name>
<url-pattern>/xy1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>home</servlet-name>
<jsp-file>/home.jsp</jsp-file>
<load-on-startup>0</load-on-startup>
</servlet>
<welcome-file-list>
<welcome-file>home.jsp</welcome-file>
</welcome-file-list>

An iceFaces - facelets URL bar address is not showing

My company has the Spring-Ifaces 1.8 standard to work with a IBM WAS 6.1 solution. After read the icefaces tutorials, i decide to implement a facelets solution to do a better template management.
In the faces-config.xml i put the next line to config the facelets:
<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
The web.xml is configured to search the index.jsp as the main page on the context:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
The index forward to the first page on my navigation logic.
<body>
<jsp:forward page="paso1.iface" />
</body>
But on the browser URL bar address, i still seeing the http://server.com/context path.
When the form data is already written, i submit, run my action and the navigation rule send me to the next page.
But again, on the browser URL bar address, is still in the http://server.com/context path.
<navigation-rule>
<from-view-id>/step1.jspx</from-view-id>
<navigation-case>
<from-action>#{actionBean.action}</from-action>
<from-outcome>success</from-outcome>
<to-view-id>/step2.jspx</to-view-id>
</navigation-case>
<navigation-case>
<from-action>#{actionBean.action}</from-action>
<from-outcome>fail</from-outcome>
<to-view-id>/step1.jspx</to-view-id>
</navigation-case>
</navigation-rule>
I can't use redirect, because there is some session data. And even i try using the standard Java EE Facelets tag com.sun.facelets.FaceletViewHandler, but the page can't be rendered.
How can I force or config properly the IceFaces Facelet to show me the webpage than I'm already step on?
--- web.xml ---
<?xml version="1.0" encoding="UTF-8"?>
<web-app
id="WebApp_ID"
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>venta-directa-web</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>uploadServlet</servlet-name>
<servlet-class>com.icesoft.faces.component.inputfile.FileUploadServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>SimpleCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.SimpleCaptchaServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>StickyCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.StickyCaptchaServlet</servlet-class>
<init-param>
<param-name>width</param-name>
<param-value>250</param-value>
</init-param>
<init-param>
<param-name>height</param-name>
<param-value>75</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>ChineseCaptcha</servlet-name>
<servlet-class>nl.captcha.servlet.ChineseCaptchaServlet</servlet-class>
<init-param>
<param-name>width</param-name>
<param-value>265</param-value>
</init-param>
<init-param>
<param-name>height</param-name>
<param-value>50</param-value>
</init-param>
</servlet>
<context-param>
<param-name>com.icesoft.faces.actionURLSuffix</param-name>
<param-value>.iface</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.debugDOMUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.delegateNonIface</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.concurrentDOMViews</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.heartbeatRetries</param-name>
<param-value>10</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.standardRequestScope</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.component.OutputTextTag</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.uploadDirectory</param-name>
<param-value>upload</param-value>
</context-param>
<context-param>
<description>La cantidad en bytes de un archivo a subir por icefaces.</description>
<param-name>com.icesoft.faces.uploadMaxFileSize</param-name>
<param-value>4048576</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.enableRestoreView11Compatibility</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:app-web-context.xml
classpath:app-core-context.xml
classpath:app-ws-context.xml
classpath:app-dao-context.xml
</param-value>
</context-param>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/mainservlet/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>uploadServlet</servlet-name>
<url-pattern>/uploadHtml</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SimpleCaptcha</servlet-name>
<url-pattern>/simpleImg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>StickyCaptcha</servlet-name>
<url-pattern>/stickyImg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ChineseCaptcha</servlet-name>
<url-pattern>/chineseImg</url-pattern>
</servlet-mapping>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/checkService.jsp</location>
</error-page>
</web-app>
--- faces-config.xml app config ---
<application>
<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler</view-handler>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
<locale-config>
<default-locale>es</default-locale>
<supported-locale>es</supported-locale>
<supported-locale>en</supported-locale>
<supported-locale>en_US</supported-locale>
</locale-config>
</application>
Hope somebody had an answer. Regards.
An ugly solution, but work for me. Is about override the Viewandler:
http://www.logikdev.com/2010/03/24/how-to-personalise-the-urls-with-faces-navigation/

GAE display index.html with JAX-RS

I'm pretty sure this questions is very easy.
I built a app with google app engine. I use JPA and JAX-RS with Jersey.
my web.xml looks like this:
<?xml version="1.0" encoding="utf-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.rest</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
My index.html is in war/WEB-INF/index.html. What do i need to do to display it ?
index.html should go directly under war as in war/index.html.
keep your file in war folder itself,
Don't keep inside WEB-INF.
Once you have taken it out,
You just need to give localhost:8888/ it will display the welcome-file ie index.html
you can keep other Jsp's inside WEB-INF, it will just be invisible for direct URL access.

encounter "Error configuring application listener of class org.directwebremoting.servlet.DwrListener"

i found the error of "Error configuring application listener of class org.directwebremoting.servlet.DwrListener" when deploying application using dwr in tomcat6.
Here is my web.xml
<display-name>DWR (Direct Web Remoting)</display-name>
<description>A Simple Demo DWR</description>
<listener>
<listener-class>org.directwebremoting.servlet.DwrListener</listener-class>
</listener>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<display-name>DWR Servlet</display-name>
<description>Direct Web Remoter Servlet</description>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<!-- This should NEVER be present in live -->
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
<!-- Remove this unless you want to use active reverse ajax -->
<init-param>
<param-name>activeReverseAjaxEnabled</param-name>
<param-value>true</param-value>
</init-param>
<!-- By default DWR creates application scope objects when they are first
used. This creates them when the app-server is started -->
<init-param>
<param-name>initApplicationScopeCreatorsAtStartup</param-name>
<param-value>true</param-value>
</init-param>
<!-- WARNING: allowing JSON-RPC connections bypasses much of the security
protection that DWR gives you. Take this out if security is important -->
<init-param>
<param-name>jsonRpcEnabled</param-name>
<param-value>true</param-value>
</init-param>
<!-- WARNING: allowing JSONP connections bypasses much of the security
protection that DWR gives you. Take this out if security is important -->
<init-param>
<param-name>jsonpEnabled</param-name>
<param-value>true</param-value>
</init-param>
<!-- data: URLs are good for small images, but are slower, and could OOM for
larger images. Leave this out (or keep 'false') for anything but small images -->
<init-param>
<param-name>preferDataUrlSchema</param-name>
<param-value>false</param-value>
</init-param>
<!-- This enables full streaming mode. It's probably better to leave this
out if you are running across the Internet -->
<init-param>
<param-name>maxWaitAfterWrite</param-name>
<param-value>-1</param-value>
</init-param>
<init-param>
<param-name>org.directwebremoting.extend.ServerLoadMonitor</param-name>
<param-value>org.directwebremoting.impl.PollingServerLoadMonitor</param-value>
</init-param>
<!--
For more information on these parameters, see:
- http://getahead.org/dwr/server/servlet
- http://getahead.org/dwr/reverse-ajax/configuration
-->
<load-on-startup>1</load-on-startup>
</servlet>
Are you are getting a ClassNotFound error as well ?
Have you placed dwr.jar in the WEB-INF/lib directory of your webapp?

Resources