Re: Error: Not detached model found in Wicket session

2017-03-06 Thread Ihor Parashynets
hello Martin

Thank you for the update!

Best regards,
Ihor Parashynets

On 6 March 2017 at 12:40, Martin Grigorov  wrote:

> https://issues.apache.org/jira/browse/WICKET-6334
>
> On Fri, Mar 3, 2017 at 10:08 PM, Martin Grigorov <
> martin.grigo...@gmail.com>
> wrote:
>
> > Hi,
> >
> >
> >
> > On Mar 3, 2017 2:38 PM, "Ihor Parashynets"  wrote:
> >
> > Hi all
> >
> > I need some help/clarification on NotDetachedModelChecker. I've checked
> > markmail.org and found this one http://markmail.org/search/?q=
> > NotDetachedModelChecker#query:NotDetachedModelChecker%20list
> > %3Aorg.apache.wicket.users+page:1+mid:i77wqsp7hpbwgtyp+state:results
> > which is close but not the same what I'm facing at.
> >
> > Long story short:
> > 1. I have a Wicket Session, which has LoadableDetachableModel property.
> > 2. This property is being detached on public void detach() method.
> > 3. I have a Wicket test app that adds some additional config for tests'
> > purpose", like this
> >
> > public class TestWebApplication extends MyWebApplication {
> >
> > @Override
> > protected void init() {
> > super.init();
> >
> > //for test's purpose added some extended configuration
> > getRequestLoggerSettings().setRecordSessionSize(true);
> > getRequestLoggerSettings().setRequestLoggerEnabled(true);
> > getRequestLoggerSettings().setRequestsWindowSize(10);
> >
> > getFrameworkSettings().setSerializer(new 
> > JavaSerializer(getApplicationKey())
> {
> > @Override
> > protected ObjectOutputStream newObjectOutputStream(OutputStream
> out) throws IOException {
> > return new CheckingObjectOutputStream(out, new
> NotDetachedModelChecker());
> > }
> > });
> > }
> > }
> >
> > 4. I run the test and it passes but in log file I can see an error
> > message, that the model in Session is not detached. Even though I know
> that
> > it's detached properly.
> >
> > I checked the error stack trace and figured out that if there is a logger
> > enabled (getRequestLoggerSettings().setRequestLoggerEnabled(true)) in
> > combination with NotDetachedModelChecker then in AbstractRequestLogger#
> > requestTime(long timeTaken) there is a serialization of session (
> > sizeInBytes = session.getSizeInBytes()) to check the session size. But it
> > will trigger a chain, where session will be validated for detached models
> > (instance of LoadableDetachabelModel), which is to early (actually at
> > RequestCycle#onDetach() --> listeners#onDetach(this))  such as Session
> will
> > be detach only one step later.
> >
> > I've attached a simple maven project (I was trying to mimic our big real
> > Wicket project) to show the use-case. It's enough to run:  mvn
> > -Dtest=TestNonDetachableModels test to see the error message.
> >
> > And now is the question: do I use it wrong (I mean
> NotDetachedModelChecker)
> > or is there another explanation for such error?
> >
> >
> > It seems Wicket doesn't detach the Session before calculating its size
> and
> > this leads to the error log..
> > I don't have access to the code at the moment but I know that Wicket
> > detaches the Components before calculating their size.
> > I'll be able to say more at Monday.
> >
> >
> > Thank you in advance.
> >
> > --
> > Best regards,
> > Ihor Parashynets
> >
> >
> > -
> > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> > For additional commands, e-mail: users-h...@wicket.apache.org
> >
> >
> >
>



-- 
Best regards,
Ihor Parashynets


Re: Error: Not detached model found in Wicket session

2017-03-06 Thread Martin Grigorov
https://issues.apache.org/jira/browse/WICKET-6334

On Fri, Mar 3, 2017 at 10:08 PM, Martin Grigorov 
wrote:

> Hi,
>
>
>
> On Mar 3, 2017 2:38 PM, "Ihor Parashynets"  wrote:
>
> Hi all
>
> I need some help/clarification on NotDetachedModelChecker. I've checked
> markmail.org and found this one http://markmail.org/search/?q=
> NotDetachedModelChecker#query:NotDetachedModelChecker%20list
> %3Aorg.apache.wicket.users+page:1+mid:i77wqsp7hpbwgtyp+state:results
> which is close but not the same what I'm facing at.
>
> Long story short:
> 1. I have a Wicket Session, which has LoadableDetachableModel property.
> 2. This property is being detached on public void detach() method.
> 3. I have a Wicket test app that adds some additional config for tests'
> purpose", like this
>
> public class TestWebApplication extends MyWebApplication {
>
> @Override
> protected void init() {
> super.init();
>
> //for test's purpose added some extended configuration
> getRequestLoggerSettings().setRecordSessionSize(true);
> getRequestLoggerSettings().setRequestLoggerEnabled(true);
> getRequestLoggerSettings().setRequestsWindowSize(10);
>
> getFrameworkSettings().setSerializer(new 
> JavaSerializer(getApplicationKey()) {
> @Override
> protected ObjectOutputStream newObjectOutputStream(OutputStream 
> out) throws IOException {
> return new CheckingObjectOutputStream(out, new 
> NotDetachedModelChecker());
> }
> });
> }
> }
>
> 4. I run the test and it passes but in log file I can see an error
> message, that the model in Session is not detached. Even though I know that
> it's detached properly.
>
> I checked the error stack trace and figured out that if there is a logger
> enabled (getRequestLoggerSettings().setRequestLoggerEnabled(true)) in
> combination with NotDetachedModelChecker then in AbstractRequestLogger#
> requestTime(long timeTaken) there is a serialization of session (
> sizeInBytes = session.getSizeInBytes()) to check the session size. But it
> will trigger a chain, where session will be validated for detached models
> (instance of LoadableDetachabelModel), which is to early (actually at
> RequestCycle#onDetach() --> listeners#onDetach(this))  such as Session will
> be detach only one step later.
>
> I've attached a simple maven project (I was trying to mimic our big real
> Wicket project) to show the use-case. It's enough to run:  mvn
> -Dtest=TestNonDetachableModels test to see the error message.
>
> And now is the question: do I use it wrong (I mean NotDetachedModelChecker)
> or is there another explanation for such error?
>
>
> It seems Wicket doesn't detach the Session before calculating its size and
> this leads to the error log..
> I don't have access to the code at the moment but I know that Wicket
> detaches the Components before calculating their size.
> I'll be able to say more at Monday.
>
>
> Thank you in advance.
>
> --
> Best regards,
> Ihor Parashynets
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>
>


Re: Error: Not detached model found in Wicket session

2017-03-03 Thread Martin Grigorov
Hi,



On Mar 3, 2017 2:38 PM, "Ihor Parashynets"  wrote:

Hi all

I need some help/clarification on NotDetachedModelChecker. I've checked
markmail.org and found this one http://markmail.org/search/?q=
NotDetachedModelChecker#query:NotDetachedModelChecker%
20list%3Aorg.apache.wicket.users+page:1+mid:i77wqsp7hpbwgtyp+state:results
which is close but not the same what I'm facing at.

Long story short:
1. I have a Wicket Session, which has LoadableDetachableModel property.
2. This property is being detached on public void detach() method.
3. I have a Wicket test app that adds some additional config for tests'
purpose", like this

public class TestWebApplication extends MyWebApplication {

@Override
protected void init() {
super.init();

//for test's purpose added some extended configuration
getRequestLoggerSettings().setRecordSessionSize(true);
getRequestLoggerSettings().setRequestLoggerEnabled(true);
getRequestLoggerSettings().setRequestsWindowSize(10);

getFrameworkSettings().setSerializer(new
JavaSerializer(getApplicationKey()) {
@Override
protected ObjectOutputStream
newObjectOutputStream(OutputStream out) throws IOException {
return new CheckingObjectOutputStream(out, new
NotDetachedModelChecker());
}
});
}
}

4. I run the test and it passes but in log file I can see an error message,
that the model in Session is not detached. Even though I know that it's
detached properly.

I checked the error stack trace and figured out that if there is a logger
enabled (getRequestLoggerSettings().setRequestLoggerEnabled(true)) in
combination with NotDetachedModelChecker then in AbstractRequestLogger#reque
stTime(long timeTaken) there is a serialization of session (sizeInBytes =
session.getSizeInBytes()) to check the session size. But it will trigger a
chain, where session will be validated for detached models (instance of
LoadableDetachabelModel), which is to early (actually at
RequestCycle#onDetach() --> listeners#onDetach(this))  such as Session will
be detach only one step later.

I've attached a simple maven project (I was trying to mimic our big real
Wicket project) to show the use-case. It's enough to run:  mvn
-Dtest=TestNonDetachableModels test to see the error message.

And now is the question: do I use it wrong (I mean NotDetachedModelChecker)
or is there another explanation for such error?


It seems Wicket doesn't detach the Session before calculating its size and
this leads to the error log..
I don't have access to the code at the moment but I know that Wicket
detaches the Components before calculating their size.
I'll be able to say more at Monday.


Thank you in advance.

-- 
Best regards,
Ihor Parashynets


-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


Re: Error: Not detached model found

2015-11-18 Thread leejoyprakash
Thanks Sven, it worked ... 

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624p4672642.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Error: Not detached model found

2015-11-17 Thread leejoyprakash
er(id);
add(new MenuPanel("menu", 
WebApplication.getMenuList()));
}
}

public class CurrentUserModel extends
LoadableDetachableModel {
protected Authentication load() {
return 
SecurityContextHolder.getContext().getAuthentication();
}
}

Note: If I update the code in comment marked as 'Line 1' with the following:

super(id, new
Model(SecurityContextHolder.getContext().getAuthentication()));

The error doesn't show up, that might be because its not a
LoadableDetachableModel.

Is it possible to pass an instance of LoadableDetachableModel to Component
class constructor? 

I am getting the same error for the following code as well:

tree = new NestedTree("tree", provider, state);

Where state is an instance of the following class:

private class TreeItemExpansionModel extends
LoadableDetachableModel<SetTreeItem>>
{
private static final long serialVersionUID = 1L;
private final String treePanelId;

public TreeItemExpansionModel(String treePanelId) {
this.treePanelId = treePanelId;
}

@Override
protected Set load() {
return TreeItemExpansion.get(treePanelId);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof TreeItemExpansionModel) {
return ((TreeItemExpansionModel) 
obj).treePanelId.equals(treePanelId);
}
return false;
}

@Override
public int hashCode() {
return treePanelId.hashCode();
}
}

And the error is as follows:

Caused by:
org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException:
Not detached model found!
A problem occurred while checking object with type:
com.test.web.components.TreeItemProvider$TreeItemModel
Field hierarchy is:
   [class=com.test.web.admin.pages.HomePage, path=0]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=[Ljava.lang.Object;]
  java.util.List 
com.test.web.components.WhistlePanel.selectionList[2]
[class=com.test.web.NavPanel, path=0:navPanel]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree,
path=0:navPanel:tree]
  private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=org.apache.wicket.extensions.markup.html.repeater.tree.nested.Subtree,
path=0:navPanel:tree:subtree]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=org.apache.wicket.markup.repeater.RefreshingView,
path=0:navPanel:tree:subtree:branches]
  private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=[Ljava.lang.Object;]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children[0]
[class=org.apache.wicket.extensions.markup.html.repeater.tree.nested.BranchItem,
path=0:navPanel:tree:subtree:branches:1]
  java.lang.Object 
org.apache.wicket.Component.data
[class=com.test.web.components.TreeItemProvider$TreeItemModel] <- field
that is causing the problem

Thanks in advance.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Error: Not detached model found

2015-11-17 Thread Sven Meier
 super.onInitialize();
}
}

public class MenuPanel extends Panel {
public MenuPanel(String id) {
super(id);
add(new MenuPanel("menu", 
WebApplication.getMenuList()));
}
}

public class CurrentUserModel extends
LoadableDetachableModel {
protected Authentication load() {
return 
SecurityContextHolder.getContext().getAuthentication();
}
}

Note: If I update the code in comment marked as 'Line 1' with the following:

 super(id, new
Model(SecurityContextHolder.getContext().getAuthentication()));

The error doesn't show up, that might be because its not a
LoadableDetachableModel.

Is it possible to pass an instance of LoadableDetachableModel to Component
class constructor?

I am getting the same error for the following code as well:

 tree = new NestedTree("tree", provider, state);

Where state is an instance of the following class:

 private class TreeItemExpansionModel extends
LoadableDetachableModel<SetTreeItem>>
 {
private static final long serialVersionUID = 1L;
private final String treePanelId;

public TreeItemExpansionModel(String treePanelId) {
this.treePanelId = treePanelId;
}

@Override
protected Set load() {
return TreeItemExpansion.get(treePanelId);
}

@Override
public boolean equals(Object obj) {
if (obj instanceof TreeItemExpansionModel) {
return ((TreeItemExpansionModel) 
obj).treePanelId.equals(treePanelId);
}
return false;
}

@Override
public int hashCode() {
return treePanelId.hashCode();
}
 }

And the error is as follows:

Caused by:
org.apache.wicket.core.util.objects.checker.CheckingObjectOutputStream$ObjectCheckException:
Not detached model found!
A problem occurred while checking object with type:
com.test.web.components.TreeItemProvider$TreeItemModel
Field hierarchy is:
   [class=com.test.web.admin.pages.HomePage, path=0]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=[Ljava.lang.Object;]
  java.util.List 
com.test.web.components.WhistlePanel.selectionList[2]
[class=com.test.web.NavPanel, path=0:navPanel]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=org.apache.wicket.extensions.markup.html.repeater.tree.NestedTree,
path=0:navPanel:tree]
  private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=org.apache.wicket.extensions.markup.html.repeater.tree.nested.Subtree,
path=0:navPanel:tree:subtree]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=org.apache.wicket.markup.repeater.RefreshingView,
path=0:navPanel:tree:subtree:branches]
  private java.lang.Object 
org.apache.wicket.MarkupContainer.children
[class=[Ljava.lang.Object;]
private java.lang.Object 
org.apache.wicket.MarkupContainer.children[0]
[class=org.apache.wicket.extensions.markup.html.repeater.tree.nested.BranchItem,
path=0:navPanel:tree:subtree:branches:1]
  java.lang.Object 
org.apache.wicket.Component.data
[class=com.test.web.components.TreeItemProvider$TreeItemModel] <- field
that is causing the problem

Thanks in advance.

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Error: Not detached model found

2015-11-17 Thread leejoyprakash
Hello Sven,

This error is thrown in my test case. I think my basic understanding about
the way wicket works is wrong.

In my CustomerWicketTester class(which inherits from WicketTester), I have
overridden the method as follows:

@Override
public void executeAjaxEvent(final Component component, final String event)
{
serializationChecker();
super.executeAjaxEvent(component, event);
}

So from my test case while calling 'wicketTester.clickTreeNode("Users");'
which intern calls executeAjaxEvent throws the above error.

Following is my custom JavaSerializer class and the method which uses it:

public void serializationChecker(){
javaSerializer.serialize(getLastRenderedPage());
}

private class CustomJavaSerializer extends JavaSerializer {

private final String appKey;
public CustomJavaSerializer(String applicationKey) {
super(applicationKey);
this.appKey = applicationKey;
}

@Override
protected ObjectOutputStream newObjectOutputStream(OutputStream out) 
throws
IOException {
IObjectChecker checker = new NotDetachedModelChecker();
IObjectChecker checker2 = new
SerializableChecker.ObjectSerializationChecker();
return new CheckingObjectOutputStream(out, checker, checker2);
 }

@Override
public byte[] serialize(Object object) throws WicketRuntimeException {
try
{
final ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try
{
oos = newObjectOutputStream(out);
oos.writeObject(appKey);
oos.writeObject(object);
}
finally
{
try
{
IOUtils.close(oos);
}
finally
{
out.close();
}
}
return out.toByteArray();
}
catch (Exception e)
{
throw new WicketRuntimeException("Error serializing object " +
object.getClass() + " [object=" + object + "]", e);
}
}
}


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624p4672632.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



Re: Error: Not detached model found

2015-11-17 Thread Sven Meier

Hi,

WicketTester detaches the tested page *after* each request.

Have you tried checking serialization after executing the Ajax event?

@Override
public void executeAjaxEvent(final Component component, final String event)
{
super.executeAjaxEvent(component, event);
serializationChecker();
}

Regards
Sven



On 17.11.2015 18:42, leejoyprakash wrote:

Hello Sven,

This error is thrown in my test case. I think my basic understanding about
the way wicket works is wrong.

In my CustomerWicketTester class(which inherits from WicketTester), I have
overridden the method as follows:

@Override
public void executeAjaxEvent(final Component component, final String event)
{
serializationChecker();
super.executeAjaxEvent(component, event);
}

So from my test case while calling 'wicketTester.clickTreeNode("Users");'
which intern calls executeAjaxEvent throws the above error.

Following is my custom JavaSerializer class and the method which uses it:

public void serializationChecker(){
javaSerializer.serialize(getLastRenderedPage());
}

private class CustomJavaSerializer extends JavaSerializer {

private final String appKey;
public CustomJavaSerializer(String applicationKey) {
super(applicationKey);
this.appKey = applicationKey;
}

@Override
protected ObjectOutputStream newObjectOutputStream(OutputStream out) 
throws
IOException {
IObjectChecker checker = new NotDetachedModelChecker();
IObjectChecker checker2 = new
SerializableChecker.ObjectSerializationChecker();
return new CheckingObjectOutputStream(out, checker, checker2);
 }

@Override
public byte[] serialize(Object object) throws WicketRuntimeException {
try
{
final ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
try
{
oos = newObjectOutputStream(out);
oos.writeObject(appKey);
oos.writeObject(object);
}
finally
{
try
{
IOUtils.close(oos);
}
finally
{
out.close();
}
}
return out.toByteArray();
}
catch (Exception e)
{
throw new WicketRuntimeException("Error serializing object " +
object.getClass() + " [object=" + object + "]", e);
}
 }
}


--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Error-Not-detached-model-found-tp4672624p4672632.html
Sent from the Users forum mailing list archive at Nabble.com.

-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org



-
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org