Request logging through application serializer

Deals with generic topics such as logging, framework and so on. If you are not sure where to place your topic just put it here.
Post Reply
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Request logging through application serializer

Post by Bernd Welter »

Hi there,

every once in a while a player sends a request message to us (support, consulting) for a reproduction of a case. More and more often we encounter a "we can't reproduce the request in the raw request runner without applying some manual changes...". Here is an example:

Code: Select all

{
  "message": "Cannot construct instance of `com.ptvgroup.xserver.xtour.Location` (no Creators, like default constructor, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (org.apache.cxf.transport.http.AbstractHTTPDestination$1); line: 38180, column: 1] (through reference chain: com.ptvgroup.xserver.xtour.PlanToursRequest[\"locations\"]->java.util.ArrayList[0])",
  "errorLine": 38180,
  "errorColumn": 1,
  "faultType": "com.ptvgroup.xserver.exceptions.InvalidRequestFault"
}
The engine needs t know whether this location is a DepotSite or a CustomerSite.
The engine needs t know whether this location is a DepotSite or a CustomerSite.
Please ensure to provide requests / responses in a proper, complete way.
JSON is state of the art. XML/SOAP is also possible but not the first choice...
Maybe you have to check the settings of the serializer / deserializer you use.

Bernd
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
User avatar
Bernd Welter
Site Admin
Posts: 2695
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Request logging through application serializer (xServer2)

Post by Bernd Welter »

Here's some feedback from a partner who uses the C# clients we shipped with the xServer 2 (xserver-client-bundle-VERSION.zip):
Within the "Xserver.cs" class there's the Initialize() method where the JsonSerializerSettings based on NewtonSoft / Microsoft.Rest are initialised. He then applies those settings in combination with SafeJsonConvert.DeserializeObject<T>() or SafeJsonConvert.SerializeObject() which returns the proper message bodies.
If you want to use Microsoft's Serializer you have to
  • implement new Converters and
  • update the attributes of the entity classes which you want to use for the Serialisation
Unfortunately the Microsoft.Rest library is deprecated.
And here's some sample code:

Code: Select all

{
     Formatting = Formatting.Indented,
     DateFormatHandling = DateFormatHandling.IsoDateFormat,
     DateTimeZoneHandling = DateTimeZoneHandling.Utc,
     NullValueHandling = NullValueHandling.Ignore,
     ReferenceLoopHandling = ReferenceLoopHandling.Serialize,
     ContractResolver = new ReadOnlyJsonContractResolver(),
     Converters = new List<JsonConverter>
            {
                new Iso8601TimeSpanConverter()
            }
};

result.Converters.Add(new PolymorphicSerializeJsonConverter<InsertionPosition>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<Geometry>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<Interval>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<ChangeToursAction>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<TourViolation>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<ChangeToursProposalsQuery>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<RouteLocation>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<XServerFault>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<Horizon>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<OptimizationGoal>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<DistanceMode>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<TimeConsideration>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<DistanceMatrixContents>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<DrivingTimeRegulationLogbookSummary>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<WorkingTimeDirectiveLogbookSummary>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<DrivingTimeRegulationOptions>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<RoutingVehiclePosition>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<EmissionValueScenario>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<EmissionValues>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<VehiclePosition>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<InputWaypoint>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<JobProgress>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<MapSection>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<Position>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<Order>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<WorkingHours>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<TourPlanningLocation>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<ServiceStatus>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<RequestBase>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<ResultLimitation>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<ResponseBase>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<RouteEvent>("$type"));
result.Converters.Add(new PolymorphicSerializeJsonConverter<ViolationReport>("$type"));

Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany

Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning... :twisted:
Post Reply