Skip to content

Commit

Permalink
Merge branch '2.1.10.x' into v2.1
Browse files Browse the repository at this point in the history
# Conflicts:
#	onebusaway-admin-webapp/pom.xml
#	onebusaway-agency-metadata/pom.xml
#	onebusaway-alerts-persistence/pom.xml
#	onebusaway-api-core/pom.xml
#	onebusaway-api-webapp/pom.xml
#	onebusaway-combined-webapp/pom.xml
#	onebusaway-container/pom.xml
#	onebusaway-core/pom.xml
#	onebusaway-enterprise-acta-webapp/pom.xml
#	onebusaway-enterprise-webapp/pom.xml
#	onebusaway-federations-webapp/pom.xml
#	onebusaway-federations/pom.xml
#	onebusaway-frontend-webapp/pom.xml
#	onebusaway-geocoder/pom.xml
#	onebusaway-geospatial/pom.xml
#	onebusaway-gtfs-hibernate-spring/pom.xml
#	onebusaway-gtfs-realtime-archiver/pom.xml
#	onebusaway-gtfs-realtime-model/pom.xml
#	onebusaway-gwt-common/pom.xml
#	onebusaway-nextbus-api-webapp/pom.xml
#	onebusaway-phone-webapp/pom.xml
#	onebusaway-phone/pom.xml
#	onebusaway-presentation/pom.xml
#	onebusaway-quickstart/onebusaway-quickstart-assembly/pom.xml
#	onebusaway-quickstart/onebusaway-quickstart-bootstrap/pom.xml
#	onebusaway-quickstart/onebusaway-quickstart-common/pom.xml
#	onebusaway-quickstart/onebusaway-quickstart-mains/pom.xml
#	onebusaway-quickstart/onebusaway-quickstart-webapp/pom.xml
#	onebusaway-quickstart/pom.xml
#	onebusaway-realtime-api/pom.xml
#	onebusaway-sms-webapp/pom.xml
#	onebusaway-status-agent/pom.xml
#	onebusaway-transit-data-federation-builder/pom.xml
#	onebusaway-transit-data-federation-webapp/pom.xml
#	onebusaway-transit-data-federation/pom.xml
#	onebusaway-transit-data/pom.xml
#	onebusaway-twilio-webapp/pom.xml
#	onebusaway-users/pom.xml
#	onebusaway-util/pom.xml
#	onebusaway-watchdog-webapp/pom.xml
#	pom.xml
  • Loading branch information
sheldonabrown committed Dec 22, 2021
2 parents 2d4f425 + e8bc4d9 commit f9de126
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public long getCurrentTime() {
public Object getData() {
return data;
}

@JsonIgnore
public boolean isText() { return isText; }
public boolean isString() { return isText; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public String getSiri() {
if(getType().equals("xml")) {
return _realtimeService.getSiriXmlSerializer().getXml(_siriResponse);
} else {
return _realtimeService.getSiriJsonSerializer().getJson(_siriResponse, _servletRequest.getParameter("callback"));
return _realtimeService.getSiriJsonSerializer().getJson(_siriResponse,
/*_servletRequest.getParameter("callback")*/null);
// callback happens at a lower level
}
} catch(Exception e) {
_log.error("Siri v1 serialization failed: ", e,e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ protected String getSiri() {
.getXml(_siriResponse);
} else {
return _realtimeService.getSiriJsonSerializer().getJson(
_siriResponse, _servletRequest.getParameter("callback"));
_siriResponse, /*_servletRequest.getParameter("callback")*/null);
// callback happens at a lower level
}
} catch (Exception e) {
_log.error("Siri v2 serialization failed: ", e,e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.onebusaway.api.impl;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.*;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.inject.Inject;
Expand Down Expand Up @@ -51,18 +52,20 @@ public String fromObject(ActionInvocation invocation, Object obj, String resultC
if (obj != null && obj instanceof ResponseBean) {
// check if serialization already occurred as with SIRI calls
ResponseBean bean = (ResponseBean) obj;
isText = bean.isText();
value = bean.getData().toString();
isText = bean.isString();
if (bean.getData() != null) {
value = bean.getData().toString();
}
}
if (!isText) {
if (obj != null && !isText) {
mapper.setSerializerProvider(new CustomSerializerProvider());
mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true);
mapper.configure(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS, true);
mapper.configure(SerializationFeature.WRITE_NULL_MAP_VALUES, false);

value = mapper.writeValueAsString(obj);
}
if (callback != null) {
if (value != null && callback != null) {
stream.write(callback + "(" + value + ")");
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,36 @@

import com.thoughtworks.xstream.XStream;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;

public class CustomXStreamHandler extends XStreamHandler {

@Override
public String fromObject(ActionInvocation invocation, Object obj, String resultCode, Writer out) throws IOException {
if (obj != null) {
if (obj instanceof ResponseBean) {
ResponseBean bean = (ResponseBean) obj;
if (bean.isString() && bean.getData() != null) {
out.write(bean.getData().toString());
return null;
}
XStream xstream = this.createXStream(invocation);
xstream.toXML(obj, out);
}

}

return null;
}

@Override
public void toObject(ActionInvocation invocation, Reader in, Object target) {
XStream xstream = this.createXStream(invocation);
xstream.fromXML(in, target);
}

@Override
protected XStream createXStream(ActionInvocation invocation) {
return createXStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ public JsonSerializer<Object> findNullValueSerializer(BeanProperty property) thr
if (property.getType().getRawClass().equals(String.class))
return Serializers.EMPTY_STRING_SERIALIZER_INSTANCE;
if (property.getType().getRawClass().equals(Long.class))
return Serializers.NULL_LONG_SERIALIZER_INSTANCE;
return Serializers.NULL_NUMBER_SERIALIZER_INSTANCE;
if (property.getType().getRawClass().equals(Integer.class))
return Serializers.NULL_NUMBER_SERIALIZER_INSTANCE;
if (property.getType().getRawClass().equals(Double.class))
return Serializers.NULL_NUMBER_SERIALIZER_INSTANCE;
if (property.getType().getRawClass().equals(Collection.class) || property.getType().getRawClass().equals(List.class))
return Serializers.NULL_COLLECTION_SERIALIZER_INSTANCE;
else
return super.findNullValueSerializer(property);
else {
// the defaults have changed, so now we explicitly send a hint
// not to serialize null values other than those above
return null; // don't serialize
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class Serializers extends JsonSerializer<Object> {
public static final JsonSerializer<Object> EMPTY_STRING_SERIALIZER_INSTANCE = new EmptyStringSerializer();
public static final JsonSerializer<Object> NULL_LONG_SERIALIZER_INSTANCE = new NullLongSerializer();
public static final JsonSerializer<Object> NULL_NUMBER_SERIALIZER_INSTANCE = new NullNumberSerializer();
public static final JsonSerializer<Object> NULL_COLLECTION_SERIALIZER_INSTANCE = new NullCollectionSerializer();


Expand All @@ -46,8 +46,8 @@ public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider
}
}

private static class NullLongSerializer extends JsonSerializer<Object> {
public NullLongSerializer() {}
private static class NullNumberSerializer extends JsonSerializer<Object> {
public NullNumberSerializer() {}

@Override
public void serialize(Object o, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
Expand Down
28 changes: 26 additions & 2 deletions onebusaway-api-webapp/src/main/webapp/WEB-INF/urlrewrite.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,33 @@
<!-- make sure type param is present and infer from URL -->
<!-- this changed slightly in now that .json and .xml are support by the action -->
<rule>
<condition type="parameter" name="type">([^json]|[^xml])</condition>
<from>^([^;]*)/siri/([^.]*)\.(xml|json)(.*)$</from>
<condition type="parameter" name="type">null</condition>
<from>^([^;]*)/siri/([^.]*)\.(json|xml)(.*)$</from>
<to type="redirect" last="true">$1/siri/$2.$3$4&amp;type=$3</to>
</rule>

<rule>
<condition type="parameter" name="type">json</condition>
<from>^([^;]*)/siri/(vehicle-monitoring)[?](.*)$</from>
<to type="redirect" last="true">$1/siri/$2.json?$3</to>
</rule>

<rule>
<condition type="parameter" name="type">xml</condition>
<from>^([^;]*)/siri/(vehicle-monitoring)[?](.*)$</from>
<to type="redirect" last="true">$1/siri/$2.xml?$3</to>
</rule>

<rule>
<condition type="parameter" name="type">json</condition>
<from>^([^;]*)/siri/(stop-monitoring)[?](.*)$</from>
<to type="redirect" last="true">$1/siri/$2.json?$3</to>
</rule>

<rule>
<condition type="parameter" name="type">xml</condition>
<from>^([^;]*)/siri/(stop-monitoring)[?](.*)$</from>
<to type="redirect" last="true">$1/siri/$2.xml?$3</to>
</rule>

</urlrewrite>

0 comments on commit f9de126

Please sign in to comment.