All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.perimeterx.models.risk.Request Maven / Gradle / Ivy

There is a newer version: 6.13.0
Show newest version
package com.perimeterx.models.risk;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import com.perimeterx.models.PXContext;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Request model
 * 

* Created by shikloshi on 05/07/2016. */ public class Request { @JsonProperty("ip") public String IP; @JsonProperty("uri") public String URI; @JsonProperty("url") public String URL; @JsonProperty("headers") @JsonSerialize(using = HeadersSerializer.class) public List> Headers; public static Request fromContext(PXContext context) { Request request = new Request(); request.IP = context.getIp(); request.URI = context.getUri(); request.URL = context.getFullUrl(); request.Headers = new ArrayList<>(context.getHeaders().entrySet()); return request; } } class HeadersSerializer extends StdSerializer>> { HeadersSerializer() { this(null); } private HeadersSerializer(Class>> t) { super(t); } @Override public void serialize(List> entries, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeStartArray(); if (entries != null) { for (Map.Entry entry : entries) { jsonGenerator.writeStartObject(); jsonGenerator.writeStringField("name", entry.getKey()); jsonGenerator.writeStringField("value", entry.getValue()); jsonGenerator.writeEndObject(); } } jsonGenerator.writeEndArray(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy