Fwd: XStream.fromXML in a JSP page throwing CannotResolveClassException

View: New views
3 Messages — Rating Filter:   Alert me  

Parent Message unknown Fwd: XStream.fromXML in a JSP page throwing CannotResolveClassException

by someuser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

Before I start, I know JSP gets compiled into a Servlet and I can use normal POJO's but the requirements is only using JSP. Somehow, I cannot use fromXML in a JSP file, any reasons why? Any assistance is helpful and appreciated!

The working code snippet is below, it can be saved as test.jsp and you can see the exception live:

<%@ page import="com.thoughtworks.xstream.XStream"%>
<%@ page import="com.thoughtworks.xstream.io.xml.DomDriver"%>
<%@ page import="com.thoughtworks.xstream.annotations.XStreamAlias"%>
<%@ page import="com.thoughtworks.xstream.annotations.XStreamAsAttribute"%>

<%!
@XStreamAlias("InstanceParameter")
public static class InstanceParameter {
    @XStreamAlias("ID") @XStreamAsAttribute
    public String id;
    @XStreamAlias("Value") @XStreamAsAttribute
    public String value;
}
%>
<%
InstanceParameter testA = new InstanceParameter();
testA.id = "Hello";
testA.value = "World";

// This works. Returns 'toXML: <InstanceParameter ID="Hello" Value="World"/>'
XStream stream = new XStream(new DomDriver());
stream.processAnnotations(InstanceParameter.class);
String xml = stream.toXML(testA);
System.out.println("toXML: " + xml);

// This does not work. 
InstanceParameter param = (InstanceParameter)stream.fromXML(xml);
System.out.println("fromXML: " + param.id);

out.close();
%>

The exception I am getting is the following:
com.thoughtworks.xstream.mapper.CannotResolveClassException: org.apache.jsp.rulesTranslator_jsp$InstanceParameter : org.apache.jsp.rulesTranslator_js
$InstanceParameter
        at com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.DynamicProxyMapper.realClass(DynamicProxyMapper.java:71)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.PackageAliasingMapper.realClass(PackageAliasingMapper.java:88)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.ClassAliasingMapper.realClass(ClassAliasingMapper.java:86)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.ArrayMapper.realClass(ArrayMapper.java:96)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.MapperWrapper.realClass(MapperWrapper.java:38)
        at com.thoughtworks.xstream.mapper.CachingMapper.realClass(CachingMapper.java:52)
        at com.thoughtworks.xstream.core.util.HierarchicalStreams.readClassType(HierarchicalStreams.java:29)
        at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:136)
        at com.thoughtworks.xstream.core.AbstractTreeMarshallingStrategy.unmarshal(AbstractTreeMarshallingStrategy.java:33)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:923)
        at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:909)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:853)
        at com.thoughtworks.xstream.XStream.fromXML(XStream.java:845)
        at org.apache.jsp.rulesTranslator_jsp$RuleExtractor.getSaveRuleXML(rulesTranslator_jsp.java:955)
        at org.apache.jsp.rulesTranslator_jsp$RuleExtractor.process(rulesTranslator_jsp.java:1148)
        at org.apache.jsp.rulesTranslator_jsp._jspService(rulesTranslator_jsp.java:1229)


Any help is appreciated. I am really puzzling, it works fine in plain pogo Java, but within a JSP page the fromXML part doesn't work at all.

-Mohamed Mansour

Re: Fwd: XStream.fromXML in a JSP page throwing CannotResolveClassException

by Jörg Schaible-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Mohamed,

Mohamed Mansour wrote:

> Hello,
>
> Before I start, I know JSP gets compiled into a Servlet and I can use
> normal POJO's but the requirements is only using JSP. Somehow, I cannot
> use fromXML in a JSP file, any reasons why? Any assistance is helpful and
> appreciated!

Since the missing class is also generated by the jsp compiler, it might be
very well, that it is not part of the default class loader.

> The working code snippet is below, it can be saved as test.jsp and you can
> see the exception live:
>
> <%@ page import="com.thoughtworks.xstream.XStream"%>
> <%@ page import="com.thoughtworks.xstream.io.xml.DomDriver"%>
> <%@ page import="com.thoughtworks.xstream.annotations.XStreamAlias"%>
> <%@ page
> import="com.thoughtworks.xstream.annotations.XStreamAsAttribute"%>
>
> <%!
> @XStreamAlias("InstanceParameter")
> public static class InstanceParameter {
>     @XStreamAlias("ID") @XStreamAsAttribute
>     public String id;
>     @XStreamAlias("Value") @XStreamAsAttribute
>     public String value;
> }
> %>
> <%
> InstanceParameter testA = new InstanceParameter();
> testA.id = "Hello";
> testA.value = "World";
>
> // This works. Returns 'toXML: <InstanceParameter ID="Hello"
> Value="World"/>'
> XStream stream = new XStream(new DomDriver());


try here to insert:

xstream.setClassloader(getClass().getClassloader());


> stream.processAnnotations(InstanceParameter.class);
> String xml = stream.toXML(testA);
> System.out.println("toXML: " + xml);
>
> // This does not work.
> InstanceParameter param = (InstanceParameter)stream.fromXML(xml);
> System.out.println("fromXML: " + param.id);
>
> out.close();
> %>
>
>
> The exception I am getting is the following:
>
> com.thoughtworks.xstream.mapper.CannotResolveClassException:
> org.apache.jsp.rulesTranslator_jsp$InstanceParameter :
> org.apache.jsp.rulesTranslator_js
> $InstanceParameter
>         at
>
com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
>         at

[snip]

>
> Any help is appreciated. I am really puzzling, it works fine in plain pogo
> Java, but within a JSP page the fromXML part doesn't work at all.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Re: Fwd: XStream.fromXML in a JSP page throwing CannotResolveClassException

by someuser :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks Jörg, works perfectly! 

 - Mohamed


On Sun, Nov 8, 2009 at 7:32 AM, Jörg Schaible <joerg.schaible@...> wrote:
Hi Mohamed,

Mohamed Mansour wrote:

> Hello,
>
> Before I start, I know JSP gets compiled into a Servlet and I can use
> normal POJO's but the requirements is only using JSP. Somehow, I cannot
> use fromXML in a JSP file, any reasons why? Any assistance is helpful and
> appreciated!

Since the missing class is also generated by the jsp compiler, it might be
very well, that it is not part of the default class loader.

> The working code snippet is below, it can be saved as test.jsp and you can
> see the exception live:
>
> <%@ page import="com.thoughtworks.xstream.XStream"%>
> <%@ page import="com.thoughtworks.xstream.io.xml.DomDriver"%>
> <%@ page import="com.thoughtworks.xstream.annotations.XStreamAlias"%>
> <%@ page
> import="com.thoughtworks.xstream.annotations.XStreamAsAttribute"%>
>
> <%!
> @XStreamAlias("InstanceParameter")
> public static class InstanceParameter {
>     @XStreamAlias("ID") @XStreamAsAttribute
>     public String id;
>     @XStreamAlias("Value") @XStreamAsAttribute
>     public String value;
> }
> %>
> <%
> InstanceParameter testA = new InstanceParameter();
> testA.id = "Hello";
> testA.value = "World";
>
> // This works. Returns 'toXML: <InstanceParameter ID="Hello"
> Value="World"/>'
> XStream stream = new XStream(new DomDriver());


try here to insert:

xstream.setClassloader(getClass().getClassloader());


> stream.processAnnotations(InstanceParameter.class);
> String xml = stream.toXML(testA);
> System.out.println("toXML: " + xml);
>
> // This does not work.
> InstanceParameter param = (InstanceParameter)stream.fromXML(xml);
> System.out.println("fromXML: " + param.id);
>
> out.close();
> %>
>
>
> The exception I am getting is the following:
>
> com.thoughtworks.xstream.mapper.CannotResolveClassException:
> org.apache.jsp.rulesTranslator_jsp$InstanceParameter :
> org.apache.jsp.rulesTranslator_js
> $InstanceParameter
>         at
>
com.thoughtworks.xstream.mapper.DefaultMapper.realClass(DefaultMapper.java:68)
>         at

[snip]

>
> Any help is appreciated. I am really puzzling, it works fine in plain pogo
> Java, but within a JSP page the fromXML part doesn't work at all.

- Jörg


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email