Fixed not serializable error when stopping/starting Tomcat

This commit is contained in:
Nanne Baars 2015-08-22 10:40:42 +02:00
parent 16c262f3bc
commit 69350a6e0c
2 changed files with 39 additions and 5 deletions

View File

@ -1,12 +1,14 @@
package org.owasp.webgoat.util;
import java.util.Locale;
import javax.annotation.Resource;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import javax.inject.Inject;
import java.io.Serializable;
import java.util.Locale;
/***************************************************************************************************
*
@ -37,14 +39,20 @@ import org.springframework.stereotype.Component;
*/
@Component("labelManager")
@Scope(value="session", proxyMode=ScopedProxyMode.INTERFACES)
public class LabelManagerImpl implements LabelManager
public class LabelManagerImpl implements LabelManager, Serializable
{
@Resource
private LabelProvider labelProvider;
private transient LabelProvider labelProvider;
/** Locale mapped with current session. */
private Locale locale = new Locale(LabelProvider.DEFAULT_LANGUAGE);
protected LabelManagerImpl() {}
@Inject
public LabelManagerImpl(LabelProvider labelProvider) {
this.labelProvider = labelProvider;
}
public void setLocale(Locale locale)
{
if (locale != null)

View File

@ -0,0 +1,26 @@
package org.owasp.webgoat.util;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class LabelManagerImplTest {
@Test
public void shouldSerialize() throws IOException {
LabelManagerImpl labelManager = new LabelManagerImpl(null);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(labelManager);
}
@Test
public void shouldSerializeWithLabelProvider() throws IOException {
LabelManagerImpl labelManager = new LabelManagerImpl(new LabelProvider());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(bos);
out.writeObject(labelManager);
}
}