Merge pull request #36 from nbaars/master

Fixed not serializable error when stopping/starting Tomcat
This commit is contained in:
mayhew64 2015-08-23 07:59:05 -04:00
commit 06d025daf0
2 changed files with 39 additions and 5 deletions

View File

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