I'm trying to redirect from a Spring MVC Controller in my Webapplication to an external URL given by a certain payment service. The URL Pattern is:
https://xxz.et/xyz/abc.jsp;jsessionid=<SessionID>.worker11?FRONTENDLANGUAGESELECTED=de
What the browser Address bar shows is:
https://xxz.net/xyz/abc.jsp?FRONTENDLANGUAGESELECTED=de
and the payment service returns Session Timeout. If I enter the complete URL manually, it works. I tried redirecting either by httpResponse.sendRedirect() or making the method return redirct:.
I have had the same problem. This is because you use servlets 2.4, you can change this in you file: webapp.xml for use Servlets 3.0.
Use this xml config header:
<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">
I hope I could have helped you. a greeting
Related
I'm trying to deploy a war file with an embedded Jetty. You can clone a minimal working example here: https://github.com/guilty/jetty-test
When you build the project and try to run the war-project with a jetty-runner (which can be downloaded here: http://mvnrepository.com/artifact/org.eclipse.jetty/jetty-runner/9.2.10.v20150310), everything works fine.
As you can see, I have a jar-project, which has a dependency to war-project (with classes classifier). It tries to start an embedded Jetty server and deploy the war-project, but problem is, it reads the application-context.xml twice. As I understand, it finds it twice in the classpath: once in a built *.war, and once in a dependency I made with classes classifier.
The same happens if you use jetty-runner and call Runner.main(new String[] { "path-to.war" }), though as I said before, it works fine when called from command line.
So my question, I guess, is how to restrict classpath to Jetty, if that's at all possible.
As I mentioned, this is a minimal working example, not a real-world application. If I can be of any assistance -- please let me know.
Edit: I've been asked to put relevant code here, because links may rot.
Since I won't post all the code, I'm going to describe the situation. I have a *.war project, which is a standard web application powered by spring. It has a class, which throws an exception if more than one instance of it is created by spring (which should never happen, since it's scope is singleton).
Another project references the war-project with a classes classifier (i.e. gets everything that lays in src/main/java and src/main/resources) and tries to deploy the war-file produced by war-project. Here is the relevant deployment code:
Server server = new Server(8080);
WebAppContext webAppContext = new WebAppContext(args[0], "/");
server.setHandler(webAppContext);
server.start();
This code runs, but the server fails to start, because a second instance of the bean I wrote about before gets created and it throws an exception.
web.xml of the war-project:
<?xml version="1.0" encoding="UTF-8"?>
<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">
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:application-context.xml</param-value>
</context-param>
</web-app>
application-context.xml of the war-project contains only one bean, with default (singleton) scope and nothing else.
Here's the relevant pom.xml part of jar-project:
<dependency>
<groupId>com.github.guilty.jettyTest</groupId>
<artifactId>web-project</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>classes</classifier>
</dependency>
I'm working with WebSphere 8.5 and JSF2.0 and I have a problem using WorkManager (from websphere - async bean). I have a workManagerExample class that implements Work interface. When I call the workManagerExample from my application I'm not longer available to get the methods of a class already loaded in my app. Situation: I have an Utility class in my app (which it is working fine) but when a try to use it (like Utility.someMethod) from the workManagerExample I'm getting a NPE. I checked the Utility class before calling the 'startWork(WorkManagerExample)' and is not null, I can use it as usual. BTW the workManager is working fine without calling any already loaded classes from my app. I can't pass the Utility class as a parameter of workManagerExample constructor (this is a restriction from the client/customer guy). My question is why I'm not longer to use the Utility class functions from this Asyn Bean?
web.xml
<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">
//some extra config not related
<resource-ref>
<description>WorkManager</description>
<res-ref-name>wm/default</res-ref-name>
<res-type>com.ibm.websphere.asynchbeans.WorkManager</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</web-app>
ibm-web-bnd.xml
<web-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host" />
<resource-ref name="wm/default" binding-name="wm/default" />
</web-bnd>
This is my reference guide http://www.bencode.net/blog/2014/07/26/was-async-beans/
Some java code:
Class1.java
WorkManager workManager = getWorkManager();
if (workManager!=null){
GetInfoWork currentOfferWork = new GetInfoWork(); //GetInfoWork implements Work
workManager.startWork(currentOfferWork);
}
In GetInfoWork.java, when I try 'FacesContext.getCurrentInstance();' I always get NULL but If I try from Class1.java it works as expected. Folder structure is as usual JSF2 web app, this is an existing application and now I want to add this Async Bean functionality through workManager (from com.ibm.ws.runtime.jar).
FacesContext.getCurrentInstance() is not your utility class, but internal part of the JSF framework. If you take a look at java doc:
public static FacesContext getCurrentInstance()
Return the FacesContext instance for the request that is being processed by the current thread.
FacesContext needs a thread handling a web request to work correctly and async bean is called in separate thread, which doesn't know about JSF context at all, and thats the reason why you are getting null. Your Class1 is called by thread handling the web request.
However you are incorrect in your statement:
I can't pass the Utility class as a parameter of workManagerExample constructor (this is a restriction).
I don't know where you found this restriction, but is not true. See the Infocenter - Developing work objects to run code in parallel
So your code should be something like this:
WorkManager workManager = getWorkManager();
if (workManager!=null){
// extract from FacesContext what you need
....
// and pass it to work item
GetInfoWork currentOfferWork = new GetInfoWork(pass, whatEver, objectsYouNeed, inWork); //GetInfoWork implements Work
workManager.startWork(currentOfferWork);
}
UPDATE
If not via constructor you can pass it via setter method. But do not pass FacesContext, but the stuff you really need, as some data from that context will be invalid after end of web request. e.g.:
GetInfoWork currentOfferWork = new GetInfoWork(); //GetInfoWork implements Work
currentOfferWork.setMyParam1(param1);
currentOfferWork.setMyParam2(param2);
workManager.startWork(currentOfferWork);
I'd like to be able to do cross-context request forwarding in Tomcat with the Tuckey URLRewrite filter. For example, I'd like to be able to route an incoming request with an SEO-/user-friendly URL like http://example.com/group-elements/300245/some-descriptive-text, where "group-elements" isn't the name of a deployed application, to a URL mapped to a Java Spring controller method for application 'foo', like http://example.com/foo/app/group/300245/elements. I'm using Tomcat 7.0.27 and URLRewrite 3.2.0; I'm working with Java Spring 3.1 web applications.
The URLRewrite 3.20 documentation notes an optional 'context' attribute for the 'to' filter parameter element:
If your application server is configured to allow "cross context" communication then this attribute can be used to forward (and only forward, not redirect or other "to" types) requests to a named servlet context.
On Tomcat, for instance, the application contexts in the server configuration (server.xml or context.xml) need the option crossContext="true". For instance, the two applications mentioned before ("app" and "forum") have to be defined as:
<Context docBase="app" path="/app" reloadable="true" crossContext="true"/>
<Context docBase="forum" path="/forum" reloadable="true" crossContext="true"/>
Given that and the original discussion about the feature, the 'context' attribute seems to be what I'm looking for. However, I haven't been able to properly enable cross-context request forwarding.
Here's my 'Context' entry application 'foo' in conf/server.xml:
<Context docBase="foo" path="/foo" reloadable="true" crossContext="true"/>
I have my urlrewrite.xml file and web.xml file in webapps/ROOT/WEB-INF/. Here's what they look like:
urlrewrite.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
<rule>
<from>baz</from>
<!-- Note: this 'to' element's value has an error. See the edit at bottom of this post for corrected version. -->
<to context="foo">/foo/app/group/300245/elements</to>
</rule>
</urlrewrite>
web.xml:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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_5.xsd" version="2.5">
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
The rule defined above in urlrewrite.xml is intentionally basic and hard-coded. In this case I'm simply trying to get the cross-context aspect of the rule working before developing the regular expressions in 'to' and 'from'.
When I request http://example.com/baz with that rule in place, Tomcat returns a 404 error saying "The requested resource (/baz) is not available." I've tried a few variations in the 'to' filter parameter, but nothing has worked yet. And I haven't been able to find any examples of how 'context' should be used.
Any ideas on how I could get this kind of cross-context request filtering to work? Is it even possible? I imagine I might be able to achieve what I'm trying to do by renaming foo.war to ROOT.war or changing the root application as mentioned here, but I'd like to try doing this via URLRewrite unless doing so is infeasible or a bad idea on its face.
If showing more of my configuration would help, please let me know. Thanks in advance for any input.
Edit:
Thanks to Christopher Schultz for the helpful answer. In my case, the problem was caused by two things: 1) not having a context.xml file in webapps/ROOT/META-INF, and 2) having an error in the 'to' element in the URL rewrite rule in webapps/ROOT/WEB-INF/urlrewrite.xml.
The fix involved putting a proper context.xml file in webapps/ROOT/META-INF. For reference for anyone else that encounters this problem, that file ended up looking like this:
webapps/ROOT/META-INF/context.xml
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="ROOT" path="/" reloadable="true" crossContext="true" />
As Schultz mentions, it's only necessary for a context with crossContext="true" to be defined for the context implied in the 'from' element in a given URL rewrite rule (here, that's ROOT). It is not necessary to explicitly define a context for the application in the 'to' URL rewrite rule. In other words, you shouldn't need to manually create a context.xml file for that application -- so continuing the example above, you would not need to manually define and put a context.xml file into webapps/foo/META-INF/.
Schultz's answer reflects the recommendations for defining a context in the official Tomcat documentation: http://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Defining_a_context.
The problem was also caused by the fact that the URL rewrite rule in my initial post had an error. The correct version should have been:
urlrewrite.xml:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<urlrewrite>
<rule>
<from>baz</from>
<!-- Note: the use of '/app' instead of '/foo/app/' below -->
<to context="foo">/app/group/300245/elements</to>
</rule>
</urlrewrite>
If your (real) webapp is deployed to /foo and you want to on-the-fly rewrite URLs like /group-elements/baz to forward (not redirect) to /foo/app/group/300245/elements, then you're going to have to deploy your rewrite filter to one of two places: /group-elements or /.
The above configuration appears to be deploying to ROOT (which is /) but then mapping the URL /baz to /foo/app/group/300245/elements. Instead, you probably want this:
<rule>
<from>/group-elements/baz</from>
<to context="foo">/foo/app/group/300245/elements</to>
</rule>
It looks like you were trying to hit http://example.com/baz which I would have expected to work. The last bit of magic is going to be making the ROOT context cross-context (note that your webapp does NOT need to be cross-context: only the urlrewrite one does). You can change the ROOT webapp to be cross-context by addint crossContext="true" to webapps/ROOT/META-INF/context.xml.
Finally, you should really stop putting <Context> elements in server.xml: leaving them in there basically means you need to restart Tomcat in order to change your webapp deployments.
After the comments I come do this possible conclusion:
I think you are mixing the concepts of a reverse proxy with cross-context. Cross-context is method to share data between two web-applications within the same application server. A reverse-proxy like 'Apache http' can rewrite a url to pass it to a certain server behind it, effectively hiding any unwanted parts or performing other operations like load-balancing.
The infrastructure would be: client --> reverse proxy --> application server
I'm using seam 2.2.2.Final with Richfaces 3.3.3.Final on JBoss AS 6.
My application is translated into 2 languages (dutch and english).
Sometimes (varying from hours to days) the web application looses the translations. It then only displays the key's as labels and not the translations.
Would anyone know what causes this?
First I thought it could be caused by the character set used in dutch. I then converted the files to ascii with native2ascii.exe but this did not solve the problem.
I'm using the default messages.properties files from seam. In my case these are messages_nl.properties and messages_en.properties. In JSF I use the EL-tags #{messages['key']}. after a few hours or days it seems like the application can't find the files anymore.
My faces-config.xml file contains these settings:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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_1_2.xsd">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<locale-config>
<default-locale>nl</default-locale>
<supported-locale>nl</supported-locale>
<supported-locale>en</supported-locale>
</locale-config>
</application>
</faces-config>
In JSF I use it like this:
<h:outputText value="#{messages['admin.scheduling.title']}" />
In Code I use
Messages.instance().get("admin.scheduling.title");
What are you using for translation? A converter?
The getAsString method must return the translated string.
Could you post the code?
I've ultimately solved this by creating an own implementation of the messages component.
It seems like an internal cache in seam gets cleared (probably after deserialisation of something). If the cache is (almost) empty I read the bundles again.
i did a tutorial after this -> http://java.dzone.com/articles/spring-ws-how
when i go to url http://localhost:8080/myService/services/MemberDetailsRequest.wsdl , i get the static wsdl file.. but when i use SoapUI to import in the wsdl file and then test it.. i only get 404 error, any1 has a solution to that?
any suggestions, why i can't get any responses with soapUI?
Check to make sure that your #PayloadRoot initializers are correct. My "localpart" definition did not match the element name in the XSD. here is how my Java class looks now:
#PayloadRoot(localPart = "GetLoginRequest", namespace = "<namespace>")
And here is the XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="<namespace>" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="<namespace>">
<xsd:include schemaLocation="user-types.xsd"></xsd:include>
<xsd:element name="GetLoginRequest" type="loginRequest"></xsd:element>
<xsd:element name="GetLoginReply" type="loginReply"></xsd:element>
</xsd:schema>
Make sure SoapUI follows your URL mapping.
In my case, SoapUI did not automatically append ".wsdl" at the end.
in my web.xml:
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/services/HelloPersonService.wsdl</url-pattern>
</servlet-mapping>
In Soap UI, the ".wsdl" was not there. Just add it manually in the address-bar like thing in Soap UI and proceed with your test.
PayloadRoot namespace and schema namespace should be same
Do a component scan on the package that contains all the endpoints. This worked for me. In memberservice-servlet.xml include the following
<context:component-scan base-package="org.bk.memberservice.endpoint" />