You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Musachy Barroso <mu...@gmail.com> on 2009/07/31 20:18:49 UTC

stealing code and other cool stuff

You might have noticed I just committed the code of Jasper compiler
under the sandox/struts2-jsp-plugin. I modified jasper (unable to
extend as most of the code is private) to read JSPs from the classpath
and compile them into java in memory (no intermediate file required),
and then I am using the java compiler API to compile the java code and
keep a cache of the generated servlets.

The end result is that I can use JSPs from the classpath now. TLDs and
includes do not work currently, but they will soon, I hope. Then I
will make it work from an OSGi bundle. I know some people want to be
able to package JSPs in jars, so this might work out, eventually.

 musachy
-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Musachy Barroso <mu...@gmail.com>.
The JSP plugin can now serve JSPs from inside OSGi bundles (using our
OSGi plugin). I am not sure how useless this is, but it is fun.

musachy
-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Musachy Barroso <mu...@gmail.com>.
yes it can be used outside struts, the changes are not big deal, I am
surprised this hasn't done before. Maybe I have some surprises waiting
for me in the "includes" :)

musachy

On Fri, Jul 31, 2009 at 11:38 AM, Antonio
Petrelli<an...@gmail.com> wrote:
> 2009/7/31 Musachy Barroso <mu...@gmail.com>:
>> I modified jasper (unable to
>> extend as most of the code is private) to read JSPs from the classpath
>> and compile them into java in memory (no intermediate file required),
>> and then I am using the java compiler API to compile the java code and
>> keep a cache of the generated servlets.
>
> Great! Musachy you are da man!
> Why don't you write an article about it and publish it to
> Theserverside or similar journals?
> Do you think is portable in any way outside of Struts?
>
> Antonio
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Antonio Petrelli <an...@gmail.com>.
2009/7/31 Musachy Barroso <mu...@gmail.com>:
> I modified jasper (unable to
> extend as most of the code is private) to read JSPs from the classpath
> and compile them into java in memory (no intermediate file required),
> and then I am using the java compiler API to compile the java code and
> keep a cache of the generated servlets.

Great! Musachy you are da man!
Why don't you write an article about it and publish it to
Theserverside or similar journals?
Do you think is portable in any way outside of Struts?

Antonio

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Struts2 Sitemesh handling 404

Posted by Morten Solberg <mo...@uniweb.no>.
Hi,

I am having a hard time figuring out how to get this working properly. I 
have handled 404 pages / unknown actions this way:

web.xml
<error-page>
	<error-code>404</error-code>
         <location>/error/pagenotfound</location>
</error-page>

struts.xml
<package name="error" namespace="/error" extends="controlpanel-default">
   <action name="pagenotfound" class="com.uniweb.cp.common.Error">
    <result name="success" type="freemarker">/error/notfound.ftl</result>
   </action>
</package>

This works fine and are not decorated. This is what I want. For unknown 
actions e.g URL's like http://localhost:8080/asdf, I have implemented 
UnknownHandler with the definition of handleUnknownAction like this:

public ActionConfig handleUnknownAction(String namespace, String actionName)
             throws XWorkException {
ActionConfig actionConfig = new ActionConfig.Builder("error", 
"pagenotfound", "com.uniweb.cp.common.Error")
				.addResultConfig(new ResultConfig.Builder(Action.SUCCESS, 
resultsByExtension.get("ftl").getClassName())
						.addParams(resultsByExtension.get("ftl").getParams())
						.addParam(resultsByExtension.get("ftl").getDefaultResultParam(), 
"/error/notfound.ftl")
						.build())
				.build();
  return actionConfig;
}

This redirects to the same action, however, notfound.ftl in this case is 
decorated.

Have any of you had the same problem? Or is there another way to solve 
the unknown action problem?


Regards,

Morten Solberg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Musachy Barroso <mu...@gmail.com>.
Ok, I committed the code, includes work, and so do tag libraries, so
it is usable. One thing to note about includes, relative paths will
not work, because a relative path can resolve to multiple files.
because multiple files can be under the same path in different jars,
it is a good idea to place jsps inside unique paths, like:

 <action name="HelloWorld" class="example.HelloWorld">
       <result type="embeddedJsp">org/apache/struts2/jsps/simple0.jsp</result>
  </action>

Also, java 6 is required. The code uses jasper 5, I gave a try to 6
but was giving me trouble and I was out of beers at home, so my will
was weak ;)

musachy
-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Musachy Barroso <mu...@gmail.com>.
duh..I was looking for jasper-compiler, like it was in 5, now it is
"jasper". that's great, thanks for the tip! I will update the code for
jasper 6, and follow Martin's advice this time ;)


musachy

On Fri, Jul 31, 2009 at 1:14 PM, Tomislav
Stojcevich<st...@gmail.com> wrote:
> 6 is in maven repo, they just changed the group (no source though, but
> you can that from their scm)
>
> see http://repo2.maven.org/maven2/org/apache/tomcat/
>
>
> --tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Tomislav Stojcevich <st...@gmail.com>.
6 is in maven repo, they just changed the group (no source though, but
you can that from their scm)

see http://repo2.maven.org/maven2/org/apache/tomcat/


--tom

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Musachy Barroso <mu...@gmail.com>.
yeah, the thing is that this code is just to test if it can be done.
It is using the code from 5.5. I couldn't use Jasper 6 (from tomcat 6
that is) because I can't find jasper-runtime 6 in maven, and in
version 6 there is a whole "el" package that is not in maven either(so
i would have to copy that also..yuck). So instead of fighting with
that, I went for jasper 5 and if I can get it to work, I will try to
port my changes to jasper 6, or just send patches to the tomcat guys
to make some stuff protected so I can extend it.

for the record and to help my memory later, the jasper code comes from
tomcat 5.5.27

musachy

On Fri, Jul 31, 2009 at 11:27 AM, Martin Cooper<ma...@apache.org> wrote:
> Maybe you did this and I missed it, but it would have been good to see the
> original clone of Jasper checked in first, and then your changes checked in
> over that. That way, we would all be able to see the baseline from which you
> started, not to mention be able to track back to Tomcat sources and port
> ongoing updates / bug fixes from over there.
>
> --
> Martin Cooper
>
>
> On Fri, Jul 31, 2009 at 11:18 AM, Musachy Barroso <mu...@gmail.com> wrote:
>
>> You might have noticed I just committed the code of Jasper compiler
>> under the sandox/struts2-jsp-plugin. I modified jasper (unable to
>> extend as most of the code is private) to read JSPs from the classpath
>> and compile them into java in memory (no intermediate file required),
>> and then I am using the java compiler API to compile the java code and
>> keep a cache of the generated servlets.
>>
>> The end result is that I can use JSPs from the classpath now. TLDs and
>> includes do not work currently, but they will soon, I hope. Then I
>> will make it work from an OSGi bundle. I know some people want to be
>> able to package JSPs in jars, so this might work out, eventually.
>>
>>  musachy
>> --
>> "Hey you! Would you help me to carry the stone?" Pink Floyd
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
>> For additional commands, e-mail: dev-help@struts.apache.org
>>
>>
>



-- 
"Hey you! Would you help me to carry the stone?" Pink Floyd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Martin Cooper <ma...@apache.org>.
Maybe you did this and I missed it, but it would have been good to see the
original clone of Jasper checked in first, and then your changes checked in
over that. That way, we would all be able to see the baseline from which you
started, not to mention be able to track back to Tomcat sources and port
ongoing updates / bug fixes from over there.

--
Martin Cooper


On Fri, Jul 31, 2009 at 11:18 AM, Musachy Barroso <mu...@gmail.com> wrote:

> You might have noticed I just committed the code of Jasper compiler
> under the sandox/struts2-jsp-plugin. I modified jasper (unable to
> extend as most of the code is private) to read JSPs from the classpath
> and compile them into java in memory (no intermediate file required),
> and then I am using the java compiler API to compile the java code and
> keep a cache of the generated servlets.
>
> The end result is that I can use JSPs from the classpath now. TLDs and
> includes do not work currently, but they will soon, I hope. Then I
> will make it work from an OSGi bundle. I know some people want to be
> able to package JSPs in jars, so this might work out, eventually.
>
>  musachy
> --
> "Hey you! Would you help me to carry the stone?" Pink Floyd
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>

Re: Casting ActionSupport

Posted by Illya Kysil <ik...@gmail.com>.
Hi,

Check your code twice - JVM is right :)

> ... casting inherited classes of ActionSupport to ActionSupport
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

>                ActionSupport support = new ActionSupport();
>                Test5 test = (Test5)support;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

On Mon, Aug 3, 2009 at 12:11, Morten Solberg<mo...@uniweb.no> wrote:
> Hi,
>
> I'm having problems casting inherited classes of ActionSupport to
> ActionSupport. I haven't had any problems with this until now. I'm running
> struts 2.1.8-snapshot
>
> Example:
>
> public class ActionSupportTest {
>        @Test
>        public void testCastSDWebActionSupport() {
>                ActionSupport support = new ActionSupport();
>                Test5 test = (Test5)support;
>                assertNotNull(test);
>        }
> }
>
> public class Test5 extends ActionSupport {
> }
>
>
> Running the test gives:
>
> java.lang.ClassCastException: com.opensymphony.xwork2.ActionSupport cannot
> be cast to com.uniweb.cp.common.Test5
>        at
> com.uniweb.cp.common.ActionSupportTest.testCastSDWebActionSupport(ActionSupportTest.java:19)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
>        at
> org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
>        at
> org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
>        at
> org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
>        at
> org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
>        at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
>        at
> org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
>        at
> org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
>        at
> org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
>        at
> org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
>        at
> com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:99)
>        at
> com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
>        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>        at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>        at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>        at
> com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
>
>
>
> Best regards,
>
> Morten Solberg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>



-- 
Illya Kysil
--
"EASY" is the word you use to describe other people's job.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Casting ActionSupport

Posted by Morten Solberg <mo...@uniweb.no>.
Hi,

I'm having problems casting inherited classes of ActionSupport to 
ActionSupport. I haven't had any problems with this until now. I'm 
running struts 2.1.8-snapshot

Example:

public class ActionSupportTest {
	@Test
	public void testCastSDWebActionSupport() {
		ActionSupport support = new ActionSupport();
		Test5 test = (Test5)support;
		assertNotNull(test);
	}
}

public class Test5 extends ActionSupport {
}


Running the test gives:

java.lang.ClassCastException: com.opensymphony.xwork2.ActionSupport 
cannot be cast to com.uniweb.cp.common.Test5
	at 
com.uniweb.cp.common.ActionSupportTest.testCastSDWebActionSupport(ActionSupportTest.java:19)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at org.junit.internal.runners.TestMethod.invoke(TestMethod.java:59)
	at 
org.junit.internal.runners.MethodRoadie.runTestMethod(MethodRoadie.java:98)
	at org.junit.internal.runners.MethodRoadie$2.run(MethodRoadie.java:79)
	at 
org.junit.internal.runners.MethodRoadie.runBeforesThenTestThenAfters(MethodRoadie.java:87)
	at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:77)
	at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:42)
	at 
org.junit.internal.runners.JUnit4ClassRunner.invokeTestMethod(JUnit4ClassRunner.java:88)
	at 
org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51)
	at 
org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44)
	at 
org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27)
	at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37)
	at 
org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42)
	at com.intellij.rt.junit4.Junit4ClassSuite.run(Junit4ClassSuite.java:99)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)



Best regards,

Morten Solberg

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: stealing code and other cool stuff

Posted by Wes Wannemacher <we...@wantii.com>.
On Fri, Jul 31, 2009 at 2:18 PM, Musachy Barroso<mu...@gmail.com> wrote:
> You might have noticed I just committed the code of Jasper compiler
> under the sandox/struts2-jsp-plugin. I modified jasper (unable to
> extend as most of the code is private) to read JSPs from the classpath
> and compile them into java in memory (no intermediate file required),
> and then I am using the java compiler API to compile the java code and
> keep a cache of the generated servlets.
>
> The end result is that I can use JSPs from the classpath now. TLDs and
> includes do not work currently, but they will soon, I hope. Then I
> will make it work from an OSGi bundle. I know some people want to be
> able to package JSPs in jars, so this might work out, eventually.
>
>

Some people?

/me, whistling quietly in the corner

The other practical application for this is possibly using .tag files
(jsp snippets) instead of freemarker for our templates. I have longed
for the the ability to compile JSP outside of the context of a
container! Great work Musachy.

-Wes

-- 
Wes Wannemacher

Head Engineer, WanTii, Inc.
Need Training? Struts, Spring, Maven, Tomcat...
Ask me for a quote!

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org