ocpsoft / rewrite Goto Github PK
View Code? Open in Web Editor NEWOCPsoft URL-Rewriting Framework
Home Page: http://ocpsoft.org/rewrite/
License: Apache License 2.0
OCPsoft URL-Rewriting Framework
Home Page: http://ocpsoft.org/rewrite/
License: Apache License 2.0
Especially for use cases like "switch to SSL for these URLs".
Corresponding forum post:
http://ocpsoft.org/support/topic/jsf-prettyfaces-force-login-page-to-redirect-to-https
@ParameterBinding
@ValidateRegExp(“[a-z]{2}”)
private String value;
Alex Soto (@lordofthejars) has been working on an Asciidoctor Java integration library that will handle all the dirty work of getting the required gems and the bridge code to invoke Ruby. I encourage the project to adopt this library to keep things simple & maintainable.
https://github.com/lordofthejars/asciidoctor-java-integration
Note that this will be moved upstream to this location any time now:
Hi,
rewrite looks awesome :) There is a tiny little thing I would love to see:
I am using the faces-integration and I defined a
.addRule(Join.path("/{locale}/{page}.xhtml").to("/{page}.xhtml")
if I now define the de/index.xhtml accordingly to that I get a
com.sun.faces.context.FacesFileNotFoundException: /de/index.xhtml Not Found in ExternalContext as a Resource
Would be awesome to be able to define rewritten URLs as welcome-files ...
Using latest GF 3.1.2.2 with Mojarra 2.1.6 (SNAPSHOT 20111206).
Thanks,
We already discussed the things I would like to add here: http://ocpsoft.org/support/topic/performance-tuning/. This issue is just for tracking the branch.
@ParameterBinding
@ValidateWith(CustomConverter.class)
private String value;
Should just be @ParameterBinding
I created the following rule:
return ConfigurationBuilder.begin().defineRule().when(Direction.isInbound().and(Path.matches("/qr/{qrId}")))
.perform(Forward.to("/qms/index.html#view-qr{qrId}"));
When I attempt to use it, I get a 404 not found. I am able to copy and paste the exact URL in to my browser and it works.
Tags rendered with = title =
are omitted because by default, asciidoc treats these elements as the document title, and does not render them on single page requests.
Need to pass the !notitle
flag when calling render(input)
Or jason porter suggested passing header-footer:
Asciidoctor.render('Asciidoc text goes here', :header_footer => true)
Since commit 9e8bbb5 ("Expressions support no longer requires solder directly") a JSF app using both Rewrite and Solder (or anything that depends on it like Seam-Faces) will fail to deploy because Weld will see 2 ELContext producers.
org.ocpsoft.rewrite.cdi.expressions.ELContextProducer contains indeed:
@produces ELContext createELContext() {
return createELContext(resolver, functionMapper.get(), variableMapper.get());
}
Just like Solder. Hence the ambiguous dependency.
Hi,
There is a slight issue with the mega-rewrite showcase app: it has the same "final name" as the composite query showcase app i.e.: <finalName>composite-query</finalName>
See: https://github.com/ocpsoft/rewrite/blob/master/showcase/mega-rewrite/pom.xml
Regards,
Julien.
.defineRule()
.when(Path.matches("{something}.css").where("something").matches(".*"))
.perform(Transform.with(Less.class)
.resolvedBy(WebResourceResolver.fileType(".less")));
Should probably look more like:
.defineRule()
.when(Path.matches("{something}.css").where("something").matches(".*"))
.perform(Transform.with(Less.class)
.resolvedBy(WebResourceResolver.named("{something}.less")));
http://localhost:8080/socialpm-gwt/login?
java.lang.StringIndexOutOfBoundsException: String index out of range: -1 java.lang.String.substring(String.java:1937) java.lang.String.substring(String.java:1904) org.ocpsoft.rewrite.servlet.impl.HttpInboundRewriteImpl.getRequestQueryString(HttpInboundRewriteImpl.java:194) org.ocpsoft.rewrite.servlet.impl.HttpInboundRewriteImpl.getRequestQueryStringSeparator(HttpInboundRewriteImpl.java:182) org.ocpsoft.rewrite.servlet.impl.HttpInboundRewriteImpl.getURL(HttpInboundRewriteImpl.java:200) org.ocpsoft.rewrite.servlet.config.QueryString$2.evaluateHttp(QueryString.java:123) org.ocpsoft.rewrite.servlet.config.HttpCondition.evaluate(HttpCondition.java:41) org.ocpsoft.rewrite.config.And.evaluate(And.java:55) org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:93) org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteHttp(DefaultHttpRewriteProvider.java:62) org.ocpsoft.rewrite.servlet.http.HttpRewriteProvider.rewrite(HttpRewriteProvider.java:44) org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:221) org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:177) org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65) org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)
When I use this rule with an application deployed to the context path /myapp
:
.addRule(
CDN.relocate("/faces/javax.faces.resource/jquery.js")
.to("//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js")
)
I'm getting:
<script type="text/javascript" src="/myapp//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
It's the recommended way to use schemaless URLs to let the browser choose whether to use SSL or not when requesting the URL.
See:
https://developers.google.com/speed/libraries/devguide#jquery
Does it work with JBoss 4.X ? i have added in META-INF/services/.... but i can't able to see any log which says its installed. Do we need to specify anything in web.xml?
It seems like the order of rules is not preserved in some cases. See corresponding forum post:
http://ocpsoft.org/support/topic/default-deny?replies=8#post-3782
Hi all,
It seems a stackoverflow error is thrown by the access control app.
I have attached the full JBoss 7 logs here: http://ocpsoft.org/support/topic/stackoverflow-error-thrown-by-showcases-access-control#post-3242
Regards,
Julien Martin.
Hello,
i add this rule:
.addRule(Join.path("/u/{name}").to("/protected/index.jsp?u={name}").withInboundCorrection())
but when i entered url('protected/index.jsp?u=someone'),i hadn't see expected url('u/someone'),it seems that withInboundCorrection don't work with parameter?
~Richard
This may not be the best place to raise this issue, but I can't find any other contact address:
http://ocpsoft.org/support/ only shows a blank page, all forums are gone.
I think something just like in rest @path(from="/",to="/pages/home.xhtml"),and I can put this before a method related to home page render bean.So I don't need to maintain a Configuration class
I would like to see a SimpleJoin and SimplePath in rewrite to allow performance improvements. The implementation would only use java.lang.String#equals
for the match checking.
The topic is discussed at the following forum post: http://ocpsoft.org/support/rewrite/performance-tuning
This should definitely be done. But we still have to keep in mind that the current implementation of this annotation highly depends on JSF.
Hello,
<meta http-equiv="refresh" content="0;url=./faces/index.xhtml" />
should be:
<meta http-equiv="refresh" content="0;url=./index.xhtml" />
in https://github.com/ocpsoft/rewrite/blob/master/showcase/composite-query/src/main/webapp/index.html
because faces servlet is defined as follows:
<servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.xhtml</url-pattern> </servlet-mapping>
Regards,
Julien.
Need to figure out what this new module will be called (or if we will reuse an existing one.)
This is caused when multiple locators provide an instance of the same service.
@PathPattern
is much nicer. It contains "Path" (like the Rewrite condition is called) and there is no naming conflict with JAX-RS.
// add rule to the configuration
context.getConfigurationBuilder().addRule(ruleBuilder);
org.mozilla.javascript.JavaScriptException: [object Object] (Less#14014)
org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1057)
org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3178)
org.mozilla.javascript.InterpretedFunction.exec(InterpretedFunction.java:175)
org.mozilla.javascript.Context.evaluateString(Context.java:1111)
org.ocpsoft.rewrite.transform.less.Less.transform(Less.java:61)
org.ocpsoft.rewrite.transform.StringTransformer.transform(StringTransformer.java:43)
org.ocpsoft.rewrite.transform.PipelineOutputBuffer.transform(PipelineOutputBuffer.java:62)
org.ocpsoft.rewrite.transform.PipelineOutputBuffer.execute(PipelineOutputBuffer.java:44)
org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.flushBufferedStreams(HttpRewriteWrappedResponse.java:114)
org.ocpsoft.rewrite.servlet.impl.DefaultRewriteLifecycleListener.afterInboundLifecycle(DefaultRewriteLifecycleListener.java:36)
org.ocpsoft.rewrite.servlet.impl.DefaultRewriteLifecycleListener.afterInboundLifecycle(DefaultRewriteLifecycleListener.java:9)
org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:189)
org.jboss.solder.servlet.exception.CatchExceptionFilter.doFilter(CatchExceptionFilter.java:65)
org.jboss.solder.servlet.event.ServletEventBridgeFilter.doFilter(ServletEventBridgeFilter.java:74)
It seems to be related to imports.
I just ran into this issue with 2.0.0.Final.
@Join(path="/something", to="/faces/view.xhtml")
public class SomeBean {
@Parameter
private String value;
}
Everything is fine with this URL:
/something?value=foobar
The value
field contains foobar
. But when I add another query parameter like this to the URL like this:
/something?value=foobar&abc=123
In this case the value
field contains the value 123
instead of foobar
.
As discussed in the meeting, we will simply use Context.put()
and Context.get()
using the type of the class as a key. This is much better than changing the *Context classes each time we need a new object in the context.
Since updating to 2.0.0.Beta2 we are getting random exceptions when rendering SASS files. It happens only sometimes. Not sure why. I guess it has something to do with moving the ScriptingContainer to a field.
java.lang.NullPointerException
at org.jruby.embed.internal.ThreadSafeLocalContextProvider.isRuntimeInitialized(ThreadSafeLocalContextProvider.java:73)
at org.jruby.embed.ScriptingContainer.terminate(ScriptingContainer.java:1753)
at org.ocpsoft.rewrite.transform.markup.JRubyTransformer.transform(JRubyTransformer.java:86)
at org.ocpsoft.rewrite.transform.StringTransformer.transform(StringTransformer.java:51)
at org.ocpsoft.rewrite.transform.PipelineContentInterceptor.transform(PipelineContentInterceptor.java:76)
at org.ocpsoft.rewrite.transform.PipelineContentInterceptor.intercept(PipelineContentInterceptor.java:57)
at org.ocpsoft.rewrite.servlet.impl.ResponseContentInterceptorChainImpl.proceed(ResponseContentInterceptorChainImpl.java:44)
at org.ocpsoft.rewrite.servlet.impl.ResponseContentInterceptorChainImpl.begin(ResponseContentInterceptorChainImpl.java:59)
at org.ocpsoft.rewrite.servlet.impl.HttpRewriteWrappedResponse.flushBufferedContent(HttpRewriteWrappedResponse.java:151)
at org.ocpsoft.rewrite.servlet.impl.DefaultRewriteLifecycleListener.afterInboundLifecycle(DefaultRewriteLifecycleListener.java:56)
at org.ocpsoft.rewrite.servlet.impl.DefaultRewriteLifecycleListener.afterInboundLifecycle(DefaultRewriteLifecycleListener.java:28)
at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:198)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:171)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
I tried to write this rule with 2.0.0.Alpha4:
.addRule()
.when( Path.matches( "/styles/{name}.css" ).and( Resource.exists( "/styles/{name}.sass" ) ) )
.perform( Forward.to( "/styles/{name}.sass" ).and( Transform.with( Sass.class ) ) );
The rule will throw this error:
java.lang.IllegalStateException: Required parameter [name] value was null.
at org.ocpsoft.rewrite.param.RegexParameterizedPatternBuilder.extractBoundValues(RegexParameterizedPatternBuilder.java:245)
at org.ocpsoft.rewrite.param.RegexParameterizedPatternBuilder.build(RegexParameterizedPatternBuilder.java:130)
at org.ocpsoft.rewrite.servlet.config.Resource.evaluateHttp(Resource.java:52)
at org.ocpsoft.rewrite.servlet.config.HttpCondition.evaluate(HttpCondition.java:41)
at org.ocpsoft.rewrite.config.And.evaluate(And.java:75)
at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:109)
at org.ocpsoft.rewrite.config.And.evaluate(And.java:75)
at org.ocpsoft.rewrite.config.RuleBuilder.evaluate(RuleBuilder.java:109)
at org.ocpsoft.rewrite.servlet.impl.DefaultHttpRewriteProvider.rewriteHttp(DefaultHttpRewriteProvider.java:161)
at org.ocpsoft.rewrite.servlet.http.HttpRewriteProvider.rewrite(HttpRewriteProvider.java:43)
at org.ocpsoft.rewrite.servlet.RewriteFilter.rewrite(RewriteFilter.java:234)
at org.ocpsoft.rewrite.servlet.RewriteFilter.doFilter(RewriteFilter.java:186)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.__invoke(StandardContextValve.java:123)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java)
at org.apache.catalina.core.StandardHostValve.__invoke(StandardHostValve.java:171)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:722)
I'm not sure how to handle this. Is it something that should be supported?
Hello,
http://localhost:8080/composite-query/?c=LTg1NDM0OTA1OSM/Zm9vPTEmYmFyPTImYmF6PTMmY2FiPTQ=
should render as:
http://localhost:8080/composite-query/index.xhtml?c=LTg1NDM0OTA1OSM/Zm9vPTEmYmFyPTImYmF6PTMmY2FiPTQ=
in the composite query showcase app.
I am not sure how to fix this...
Regards,
Julien.
See issue #48, especially comment:
There's an error in the README.md (Groovy on Grails).
http://burtbeckwith.com/blog/?p=1213
"Why? Because it doesn’t exist. The framework is called Grails. Just Grails."
Mapping of CSS URLs to runtime compiled SASS and LESS files in project.
Hey Lincoln,
I'm opening a ticket for this because I think I know why this is happening. Actually it's a Rewrite bug. I'm trying to explain this in the following paragraphs.
First of all. This is the exception:
java.lang.IllegalStateException: Committed
at org.eclipse.jetty.server.Response.resetBuffer(Response.java:1066)
at org.eclipse.jetty.server.Response.sendError(Response.java:274)
at org.eclipse.jetty.server.Response.sendError(Response.java:376)
at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:162)
at org.eclipse.jetty.servlet.DefaultServlet.doGet(DefaultServlet.java:472)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
[...]
at java.lang.Thread.run(Thread.java:662)
You can reproduce it by running the ExpressionLanguageTest
in the JSF module. This test contains a simple configuration which simply forwards /name/{param}
to /faces/expression-language.xhtml
. I think I know what is going wrong here:
The request to /name/christian
comes in and is processed by the RewriteFilter
. The flow is set to Flow.FORWARD
and the request is then forwarded to /faces/expression-language.xhtml
. The forwarded request hits the RewriteFilter
a second time and it seems like it is correctly processed there.
The problem occurs inside the JSF lifecycle. At some time the RewritePhaseListener
kicks in to process PhaseOperations
. At this point the following code is executed:
Lifecycle.proceed().perform(operation.getEvent(), operation.getContext());
Actually I'm not 100% sure what this codes does and why. But it sets the flow to PROCEED
. The problems seems to be that the flow of the outer request (the original request) is modified and not the flow of the forwarded one.
Later the RewriteFilter
of the outer request continues its work after the RequestDispatcher.forward()
call finished. Now as the flow changed from FORWARD
to PROCEED
, it calls chain.doFilter()
and the request is further processed by the servlet engine. As the URL doesn't match any servlet mapping the default servlet processes it. But the default servlet won't find any resource matching the URL and therefore tries to send a 404. But this fails as the forwarded request was already committed.
So I think this is the problem. This was really difficult to debug. I thought it would be better to open a ticket for this to hear your thought about this. :)
Sounds much nicer.
("{*}something{*}").where("*").matches(".*")
will fail to match the string "blah-something-blah" because only the first "*" parameter instance will be configured.
ConfigurationBuilder.begin()
// These rules will only be evaluated if the Subset.when() condition evaluates to true.
// Perhaps create a sub-Flow here?
.addRule(Subset.when(Condition...)
.defineRule()...perform()
.addRule()
.addRule()
.defineRule()...perform()
.addRule()
.addRule())
.addRule(Join.path("blah").to("blarg"));
I'm using this configuration with 2.0.0.Alpha4:
@Named
@ViewScoped
@Join(path = "/somepage", to = "/WEB-INF/pages/somepage.jsf")
public class SomePage implements Serializable {
// ....
}
This URL works fine:
http://localhost:8080/myapp/somepage
But this one results in a 404:
http://localhost:8080/myapp/somepage;jsessionid=8970B4E77CAFE4390B0A2ED374C1815B
I think we should handle this somehow. Didn't we have some special handling for JSESSIONID in PrettyFaces too?
During an include or forward, vital information gets stuffed into request parameters. It would be nice to be able to access this information from an injectable Java resource.
javax.servlet.forward.request_uri
javax.servlet.forward.context_path
javax.servlet.forward.servlet_path
javax.servlet.forward.path_info
javax.servlet.forward.query_string
javax.servlet.include.request_uri
javax.servlet.include.context_path
javax.servlet.include.servlet_path
javax.servlet.include.path_info
javax.servlet.include.query_string
Path.matches("/{param}").and(QueryString.exists("{param}");
Param should be extracted upon its second use.
@Override
public Object convert(Rewrite event, EvaluationContext context, Object value)
{
deferredValue = deferred.convert(event, context, value);
return deferredValue;
}
Configuring parameters should be a global event for the rule.
/**
* Access http://{domain}.example.com:8080/context/literal and you should see a FileNotFoundException or
* * 404 for "/{domain}.xhtml", where "{domain}" matches the sub-domain of example.com
*/
.addRule(Join.path("/literal").to("/{domain}.xhtml")
.where("domain").matches(..etc..) // == NPE
.when(Domain.matches("{domain}.example.com")));
Join fixall = Join.path("/{page}").to("/{page}.xhtml").when(
DispatchType.isRequest()
.andNot(Path.matches(".*javax.faces.resource.*"))
);
fixall.where("page").matches(".*"); // this does not apply to outbound
org.ocpsoft.rewrite.param.DefaultParameterStore:46
Else clause is activated when the parameter name is not valid... should not be set to default parameter... should throw exception.
@Override
public Configuration getConfiguration(ServletContext context)
{
return ConfigurationBuilder.begin()
.addRule()
.when(Direction.isInbound().and(Path.matches("/{path}")))
.perform(Log.message(Level.INFO, "Client requested path: {path}"))
.where("blah").matches(".*");
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.