Skip to content

Commit

Permalink
Merge pull request #3034 from SCADA-LTS/fix/#3033_Fixed_HttpMessageNo…
Browse files Browse the repository at this point in the history
…tWritableException

#3033 Fixed HttpMessageNotWritableException:
  • Loading branch information
Limraj authored Oct 21, 2024
2 parents 5f8fbf1 + 8d30fb9 commit 6a72887
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 9 deletions.
Binary file not shown.
2 changes: 2 additions & 0 deletions WebContent/WEB-INF/springDispatcher-servlet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@
<array>
<bean class="org.scada_lts.web.security.XssProtectStringSerializer" />
<bean class="org.scada_lts.web.security.XssProtectCssStyleSerializer" />
<bean class="org.scada_lts.web.beans.serializer.ChronologySerializer" />
<bean class="org.scada_lts.web.beans.serializer.LocalDateTimeSerializer" />
</array>
</property>
</bean>
Expand Down
2 changes: 1 addition & 1 deletion src/com/serotonin/mango/web/dwr/BaseDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
import org.scada_lts.mango.adapter.MangoEvent;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.mango.service.SystemSettingsService;
import org.scada_lts.web.contnet.SnippetContentGenerator;
import org.scada_lts.web.content.SnippetContentGenerator;

abstract public class BaseDwr {
public static final String MODEL_ATTR_EVENTS = "events";
Expand Down
2 changes: 1 addition & 1 deletion src/org/scada_lts/mango/service/DataPointService.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ public void saveEventDetectors(DataPointVO dataPoint) {
for (PointEventDetectorVO pointEventDetector: dataPoint.getEventDetectors()) {
try {
pointEventDetectorDAO.insert(dataPoint.getId(), pointEventDetector);
} catch (DuplicateKeyException e) {
} catch (Exception e) {
pointEventDetectorDAO.update(dataPoint.getId(), pointEventDetector);
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/org/scada_lts/mango/service/PointValueService.java
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,16 @@ static void add(BatchWriteBehindEntry e) {
}
}
}

private int instancesSize;
private int entriesSize;

public BatchWriteBehind() {}

@Override
public void work() {
try {
this.instancesSize = instances.size();
BatchWriteBehindEntry[] inserts;
while (true) {
synchronized (ENTRIES) {
Expand All @@ -558,6 +563,7 @@ public void work() {

inserts = new BatchWriteBehindEntry[ENTRIES.size() < MAX_ROWS ? ENTRIES
.size() : MAX_ROWS];
this.entriesSize = inserts.length;
ENTRIES.pop(inserts);
ENTRIES_MONITOR.setValue(ENTRIES.size());
}
Expand Down Expand Up @@ -617,7 +623,7 @@ public WorkItemPriority getPriorityType() {

@Override
public String toString() {
return "BatchWriteBehind{instances size: " + instances.size() + '}';
return "BatchWriteBehind{current instances size: " + INSTANCES_MONITOR.getValue() + ", current entries size: " + ENTRIES_MONITOR.getValue() + ", instances size: " + this.instancesSize + ", entries size: " + this.entriesSize + '}';
}

@Override
Expand Down
11 changes: 9 additions & 2 deletions src/org/scada_lts/mango/service/SystemSettingsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.serotonin.mango.rt.event.type.AuditEventType;
import com.serotonin.mango.rt.event.type.SystemEventType;
import com.serotonin.mango.rt.maint.DataPurge;
import com.serotonin.mango.util.LoggingUtils;
import com.serotonin.mango.vo.User;
import com.serotonin.mango.vo.bean.PointHistoryCount;
import com.serotonin.mango.vo.event.EventTypeVO;
Expand Down Expand Up @@ -525,8 +526,14 @@ private static Map<String, String> deserializeMap(String json) {
}

public CssStyle getCustomCss() {
String content = SystemSettingsDAO.getValue(SystemSettingsDAO.CUSTOM_CSS_CONTENT);
return new CssStyle(content);
String defaultContent = SystemSettingsUtils.getCustomCssContent();
try {
String content = SystemSettingsDAO.getValue(SystemSettingsDAO.CUSTOM_CSS_CONTENT);
return new CssStyle(content);
} catch (Exception ex) {
LOG.error(LoggingUtils.exceptionInfo(ex));
return new CssStyle(defaultContent);
}
}

public void saveCustomCss(CssStyle cssStyle) {
Expand Down
24 changes: 24 additions & 0 deletions src/org/scada_lts/web/beans/serializer/ChronologySerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.scada_lts.web.beans.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.time.chrono.Chronology;


public class ChronologySerializer extends StdSerializer<Chronology> {

public ChronologySerializer() {
super(Chronology.class);
}

@Override
public void serialize(Chronology value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
jgen.writeStringField("id", value.getId());
jgen.writeStringField("calendarType", value.getCalendarType());
jgen.writeEndObject();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.scada_lts.web.beans.serializer;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;
import java.time.LocalDateTime;


public class LocalDateTimeSerializer extends StdSerializer<LocalDateTime> {

public LocalDateTimeSerializer() {
super(LocalDateTime.class);
}

@Override
public void serialize(LocalDateTime value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
jgen.writeStartObject();
jgen.writeNumberField("nano", value.getNano());
jgen.writeNumberField("year", value.getYear());
jgen.writeNumberField("monthValue", value.getMonthValue());
jgen.writeNumberField("dayOfMonth", value.getDayOfMonth());
jgen.writeNumberField("hour", value.getHour());
jgen.writeNumberField("minute", value.getMinute());
jgen.writeNumberField("second", value.getSecond());
jgen.writeStringField("month", value.getMonth().name());
jgen.writeStringField("dayOfWeek", value.getDayOfWeek().name());
jgen.writeNumberField("dayOfYear", value.getDayOfYear());
jgen.writeObjectField("chronology", value.getChronology());
jgen.writeEndObject();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.web.contnet;
package org.scada_lts.web.content;

import java.io.IOException;
import java.util.HashMap;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.scada_lts.web.contnet;
package org.scada_lts.web.content;

import java.io.IOException;
import java.io.PrintWriter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.powermock.modules.junit4.PowerMockRunner;
import org.scada_lts.dao.SystemSettingsDAO;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.web.contnet.SnippetContentGenerator;
import org.scada_lts.web.content.SnippetContentGenerator;
import org.springframework.mock.web.MockHttpSession;
import utils.TestConcurrentUtils;
import utils.mock.EventServiceMock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.scada_lts.dao.SystemSettingsDAO;
import org.scada_lts.mango.service.EventService;
import org.scada_lts.mango.service.ViewService;
import org.scada_lts.web.contnet.SnippetContentGenerator;
import org.scada_lts.web.content.SnippetContentGenerator;
import org.springframework.mock.web.MockHttpSession;
import utils.*;
import utils.mock.ChangePointValueDataPointRtMock;
Expand Down

0 comments on commit 6a72887

Please sign in to comment.