Search in sources :

Example 6 with JavaSerializer

use of org.apache.wicket.serialize.java.JavaSerializer in project wicket by apache.

the class TestApp2 method init.

@Override
protected void init() {
    getSharedResources().add("cancelButton", new DefaultButtonImageResource("Cancel"));
    setPageManagerProvider(new DefaultPageManagerProvider(this) {

        @Override
        public IPageManager get(IPageManagerContext pageManagerContext) {
            IDataStore dataStore = new HttpSessionDataStore(pageManagerContext, new PageNumberEvictionStrategy(100));
            IPageStore pageStore = new DefaultPageStore(new JavaSerializer(getApplicationKey()), dataStore, getStoreSettings().getInmemoryCacheSize());
            return new PageStoreManager(getName(), pageStore, pageManagerContext);
        }
    });
}
Also used : IPageStore(org.apache.wicket.pageStore.IPageStore) IPageManager(org.apache.wicket.page.IPageManager) PageStoreManager(org.apache.wicket.page.PageStoreManager) DefaultButtonImageResource(org.apache.wicket.markup.html.image.resource.DefaultButtonImageResource) HttpSessionDataStore(org.apache.wicket.pageStore.memory.HttpSessionDataStore) PageNumberEvictionStrategy(org.apache.wicket.pageStore.memory.PageNumberEvictionStrategy) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) DefaultPageManagerProvider(org.apache.wicket.DefaultPageManagerProvider) IDataStore(org.apache.wicket.pageStore.IDataStore) DefaultPageStore(org.apache.wicket.pageStore.DefaultPageStore)

Example 7 with JavaSerializer

use of org.apache.wicket.serialize.java.JavaSerializer in project wicket by apache.

the class DifferentPageCheckerTest method serializingAnotherPage.

/**
 * https://issues.apache.org/jira/browse/WICKET-5634
 *
 * Tests that the serialization fails when a checking ObjectOutputStream is
 * used with DifferentPageChecker and there is a component in the object tree that
 * keeps a reference to a page which is not component.getPage()..
 */
@Test
public void serializingAnotherPage() {
    JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {

        @Override
        protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
            IObjectChecker checker = new DifferentPageChecker();
            return new CheckingObjectOutputStream(out, checker);
        }
    };
    WebComponent component = new ComponentThatKeepsAReferenceToAnotherPage(MockPageWithLink.LINK_ID);
    MockPageWithLink rootPage = new MockPageWithLink();
    rootPage.add(component);
    byte[] serialized = serializer.serialize(rootPage);
    assertNull("The produced byte[] must be null if there was an error", serialized);
}
Also used : WebComponent(org.apache.wicket.markup.html.WebComponent) OutputStream(java.io.OutputStream) ObjectOutputStream(java.io.ObjectOutputStream) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) MockPageWithLink(org.apache.wicket.MockPageWithLink) Test(org.junit.Test)

Example 8 with JavaSerializer

use of org.apache.wicket.serialize.java.JavaSerializer in project wicket by apache.

the class SessionCheckerTest method serializingTheSession.

/**
 * https://issues.apache.org/jira/browse/WICKET-5634
 *
 * Tests that the serialization fails when a checking ObjectOutputStream is
 * used with SessionChecker and there is a component in the object tree that
 * keeps a reference to the Wicket Session.
 */
@Test
public void serializingTheSession() {
    JavaSerializer serializer = new JavaSerializer("JavaSerializerTest") {

        @Override
        protected ObjectOutputStream newObjectOutputStream(OutputStream out) throws IOException {
            IObjectChecker checker = new SessionChecker();
            return new CheckingObjectOutputStream(out, checker);
        }
    };
    WebMarkupContainer container = new WebMarkupContainer("container");
    // WICKET-6196 force container#children to be an array
    container.add(new Label("id1"));
    container.add(new ComponentWithAReferenceToTheSession("id2"));
    byte[] serialized = serializer.serialize(container);
    assertNull("The produced byte[] must be null if there was an error", serialized);
}
Also used : OutputStream(java.io.OutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Label(org.apache.wicket.markup.html.basic.Label) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) WebMarkupContainer(org.apache.wicket.markup.html.WebMarkupContainer) Test(org.junit.Test)

Example 9 with JavaSerializer

use of org.apache.wicket.serialize.java.JavaSerializer in project wicket by apache.

the class PageIdPoliticTest method setUp.

@Before
public void setUp() throws Exception {
    application = new MockApplication();
    dataStore = new InMemoryPageStore() {

        @Override
        public void storeData(String sessionId, int pageId, byte[] pageAsBytes) {
            super.storeData(sessionId, pageId, pageAsBytes);
            storeCount++;
        }
    };
    tester = new WicketTester(application) {

        @Override
        protected IPageManagerProvider newTestPageManagerProvider() {
            return new IPageManagerProvider() {

                @Override
                public IPageManager apply(IPageManagerContext pageManagerContext) {
                    IPageStore pageStore = new DefaultPageStore(new JavaSerializer(application.getApplicationKey()), dataStore, 4);
                    return new PageStoreManager(application.getName(), pageStore, pageManagerContext);
                }
            };
        }
    };
}
Also used : IPageStore(org.apache.wicket.pageStore.IPageStore) IPageManager(org.apache.wicket.page.IPageManager) MockApplication(org.apache.wicket.mock.MockApplication) IPageManagerProvider(org.apache.wicket.IPageManagerProvider) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) DefaultPageStore(org.apache.wicket.pageStore.DefaultPageStore) PageStoreManager(org.apache.wicket.page.PageStoreManager) WicketTester(org.apache.wicket.util.tester.WicketTester) IPageManagerContext(org.apache.wicket.page.IPageManagerContext) InMemoryPageStore(org.apache.wicket.versioning.InMemoryPageStore) Before(org.junit.Before)

Example 10 with JavaSerializer

use of org.apache.wicket.serialize.java.JavaSerializer in project wicket by apache.

the class PageProviderTest method pageProviderIsSerializeble.

@Test
public void pageProviderIsSerializeble() throws Exception {
    TestMapperContext mapperContext = new TestMapperContext();
    Page page = new TestPage();
    mapperContext.getPageManager().touchPage(page);
    mapperContext.getPageManager().commitRequest();
    PageProvider pageProvider = new PageProvider(page.getPageId(), page.getRenderCount());
    JavaSerializer javaSerializer = new JavaSerializer("app");
    byte[] serialized = javaSerializer.serialize(pageProvider);
    PageProvider deserialized = (PageProvider) javaSerializer.deserialize(serialized);
    deserialized.setPageSource(mapperContext);
    assertThat(deserialized.getPageInstance(), is(page));
}
Also used : PageProvider(org.apache.wicket.core.request.handler.PageProvider) MockPage(org.apache.wicket.MockPage) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage) TestMapperContext(org.apache.wicket.core.request.mapper.TestMapperContext) JavaSerializer(org.apache.wicket.serialize.java.JavaSerializer) Test(org.junit.Test)

Aggregations

JavaSerializer (org.apache.wicket.serialize.java.JavaSerializer)10 DefaultPageStore (org.apache.wicket.pageStore.DefaultPageStore)5 IPageManager (org.apache.wicket.page.IPageManager)4 IPageManagerContext (org.apache.wicket.page.IPageManagerContext)4 PageStoreManager (org.apache.wicket.page.PageStoreManager)4 IDataStore (org.apache.wicket.pageStore.IDataStore)4 IPageStore (org.apache.wicket.pageStore.IPageStore)4 Test (org.junit.Test)4 ObjectOutputStream (java.io.ObjectOutputStream)2 OutputStream (java.io.OutputStream)2 DefaultPageManagerProvider (org.apache.wicket.DefaultPageManagerProvider)2 IPageManagerProvider (org.apache.wicket.IPageManagerProvider)2 DefaultButtonImageResource (org.apache.wicket.markup.html.image.resource.DefaultButtonImageResource)2 HttpSessionDataStore (org.apache.wicket.pageStore.memory.HttpSessionDataStore)2 PageNumberEvictionStrategy (org.apache.wicket.pageStore.memory.PageNumberEvictionStrategy)2 WicketTester (org.apache.wicket.util.tester.WicketTester)2 InMemoryPageStore (org.apache.wicket.versioning.InMemoryPageStore)2 Before (org.junit.Before)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ObjectInputStream (java.io.ObjectInputStream)1