diff --git a/pom.xml b/pom.xml index 68e6bc9..12a2a32 100644 --- a/pom.xml +++ b/pom.xml @@ -1,71 +1,71 @@ - - 4.0.0 - - io.ljunggren - usps-legacy-api - 0.0.1-SNAPSHOT - jar - - usps-api - http://maven.apache.org - - - UTF-8 - 1.8 - 1.8 - - - - - org.apache.httpcomponents - httpclient - 4.5.8 - - - io.ljunggren - xml-utils - 0.0.1-SNAPSHOT - - - commons-io - commons-io - 2.8.0 - - - org.projectlombok - lombok - 1.18.22 - provided - - - junit - junit - 4.13.2 - test - - - org.mockito - mockito-core - 4.3.1 - test - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - - - + + 4.0.0 + + io.ljunggren + usps-legacy-api + 0.0.1-SNAPSHOT + jar + + usps-api + http://maven.apache.org + + + UTF-8 + 1.8 + 1.8 + + + + + org.apache.httpcomponents + httpclient + 4.5.8 + + + io.ljunggren + xml-utils + 0.0.1-SNAPSHOT + + + commons-io + commons-io + 2.8.0 + + + org.projectlombok + lombok + 1.18.38 + provided + + + junit + junit + 4.13.2 + test + + + org.mockito + mockito-core + 4.3.1 + test + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + diff --git a/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyApi.java b/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyApi.java index 9af89b8..1aaf0aa 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyApi.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyApi.java @@ -1,105 +1,105 @@ -package io.ljunggren.usps.legacy.api; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Stream; - -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.NameValuePair; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.message.BasicNameValuePair; - -import io.ljunggren.usps.legacy.api.tracking.request.TrackFieldRequest; -import io.ljunggren.usps.legacy.api.tracking.response.Error; -import io.ljunggren.usps.legacy.api.tracking.response.TrackInfo; -import io.ljunggren.usps.legacy.api.tracking.response.TrackingResponse; -import io.ljunggren.xml.utils.XmlUtils; - -public class UspsLegacyApi { - - private String username; - private UspsLegacyEnvironment environment; - - public UspsLegacyApi(UspsLegacyEnvironment environment, String username) { - this.environment = environment; - this.username = username; - } - - public TrackingResponse track(String... trackingNumbers) throws IOException { - CloseableHttpClient httpClient = HttpClients.createDefault(); - String url = environment.getDomain(); - HttpPost post = new HttpPost(url); - try { - String xmlRequest = XmlUtils.objectToXml(generateTrackingRequest(trackingNumbers)); - List params = Arrays.asList(new NameValuePair[] { - new BasicNameValuePair("api", "trackV2"), - new BasicNameValuePair("xml", xmlRequest) - }); - post.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); - CloseableHttpResponse httpResponse = httpClient.execute(post); - int responseCode = httpResponse.getStatusLine().getStatusCode(); - if (responseCode == HttpStatus.SC_OK) { - String xml = getResult(httpResponse); - return parseTrackingResponse(xml); - } - return generateError(String.format("Response code %d", responseCode)); - } catch (Exception e) { - return generateError(e.getMessage()); - } finally { - httpClient.close(); - } - } - - private TrackFieldRequest generateTrackingRequest(String... trackingNumbers) { - TrackFieldRequest request = new TrackFieldRequest(); - request.setUserId(username); - Stream.of(trackingNumbers).forEach(trackingNumber -> request.addTrackingNumber(trackingNumber)); - return request; - } - - private TrackingResponse parseTrackingResponse(String xml) throws Exception { - try { - return parse(xml, TrackingResponse.class); - } - catch (Exception e) { - return generateError(e.getMessage()); - } - } - - private T parse(String xml, Class clazz) throws Exception { - try { - return XmlUtils.xmlToObject(xml, clazz); - } catch (Exception e) { - throw new Exception("Unable to parse response"); - } - } - - private static String getResult(HttpResponse response) throws UnsupportedOperationException, IOException { - BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); - StringBuilder result = new StringBuilder(); - String line = new String(); - while ((line = rd.readLine()) != null) { - result.append(line); - } - return result.toString(); - } - - private TrackingResponse generateError(String message) { - TrackingResponse response = new TrackingResponse(); - TrackInfo trackInfo = new TrackInfo(); - Error error = new Error(0, message); - trackInfo.setError(error); - response.addTrackInfo(trackInfo); - return response; - } - -} +package io.ljunggren.usps.legacy.api; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +import org.apache.http.HttpResponse; +import org.apache.http.HttpStatus; +import org.apache.http.NameValuePair; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.message.BasicNameValuePair; + +import io.ljunggren.usps.legacy.api.tracking.request.TrackFieldRequest; +import io.ljunggren.usps.legacy.api.tracking.response.Error; +import io.ljunggren.usps.legacy.api.tracking.response.TrackInfo; +import io.ljunggren.usps.legacy.api.tracking.response.TrackingResponse; +import io.ljunggren.xml.utils.XmlUtils; + +public class UspsLegacyApi { + + private String username; + private UspsLegacyEnvironment environment; + + public UspsLegacyApi(UspsLegacyEnvironment environment, String username) { + this.environment = environment; + this.username = username; + } + + public TrackingResponse track(String... trackingNumbers) throws IOException { + CloseableHttpClient httpClient = HttpClients.createDefault(); + String url = environment.getDomain(); + HttpPost post = new HttpPost(url); + try { + String xmlRequest = XmlUtils.objectToXml(generateTrackingRequest(trackingNumbers)); + List params = Arrays.asList(new NameValuePair[] { + new BasicNameValuePair("api", "trackV2"), + new BasicNameValuePair("xml", xmlRequest) + }); + post.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); + CloseableHttpResponse httpResponse = httpClient.execute(post); + int responseCode = httpResponse.getStatusLine().getStatusCode(); + if (responseCode == HttpStatus.SC_OK) { + String xml = getResult(httpResponse); + return parseTrackingResponse(xml); + } + return generateError(String.format("Response code %d", responseCode)); + } catch (Exception e) { + return generateError(e.getMessage()); + } finally { + httpClient.close(); + } + } + + private TrackFieldRequest generateTrackingRequest(String... trackingNumbers) { + TrackFieldRequest request = new TrackFieldRequest(); + request.setUserId(username); + Stream.of(trackingNumbers).forEach(trackingNumber -> request.addTrackingNumber(trackingNumber)); + return request; + } + + private TrackingResponse parseTrackingResponse(String xml) throws Exception { + try { + return parse(xml, TrackingResponse.class); + } + catch (Exception e) { + return generateError(e.getMessage()); + } + } + + private T parse(String xml, Class clazz) throws Exception { + try { + return XmlUtils.xmlToObject(xml, clazz); + } catch (Exception e) { + throw new Exception("Unable to parse response"); + } + } + + private static String getResult(HttpResponse response) throws UnsupportedOperationException, IOException { + BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8)); + StringBuilder result = new StringBuilder(); + String line = new String(); + while ((line = rd.readLine()) != null) { + result.append(line); + } + return result.toString(); + } + + private TrackingResponse generateError(String message) { + TrackingResponse response = new TrackingResponse(); + TrackInfo trackInfo = new TrackInfo(); + Error error = new Error(0, message); + trackInfo.setError(error); + response.addTrackInfo(trackInfo); + return response; + } + +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyEnvironment.java b/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyEnvironment.java index 6494f66..6101351 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyEnvironment.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/UspsLegacyEnvironment.java @@ -1,18 +1,18 @@ -package io.ljunggren.usps.legacy.api; - -public enum UspsLegacyEnvironment { - - PRODUCTION("https://secure.shippingapis.com/ShippingAPI.dll"), - TESTING("https://testing.shippingapis.com/ShippingAPITest.dll"); - - private String domain; - - private UspsLegacyEnvironment(String domain) { - this.domain = domain; - } - - public String getDomain() { - return domain; - } - -} +package io.ljunggren.usps.legacy.api; + +public enum UspsLegacyEnvironment { + + PRODUCTION("https://secure.shippingapis.com/ShippingAPI.dll"), + TESTING("https://testing.shippingapis.com/ShippingAPITest.dll"); + + private String domain; + + private UspsLegacyEnvironment(String domain) { + this.domain = domain; + } + + public String getDomain() { + return domain; + } + +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackFieldRequest.java b/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackFieldRequest.java index a84b42a..017ba8b 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackFieldRequest.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackFieldRequest.java @@ -1,45 +1,45 @@ -package io.ljunggren.usps.legacy.api.tracking.request; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@JacksonXmlRootElement(localName = "TrackFieldRequest") -public class TrackFieldRequest { - - @JacksonXmlProperty(isAttribute = true, localName = "USERID") - private String userId; - @JacksonXmlProperty(localName = "Revision") - private int revision = 1; - @JacksonXmlProperty(localName = "ClientIp") - private String clientIp = "127.0.0.1"; - @JacksonXmlProperty(localName = "SourceId") - private String sourceId = "Default"; - @JacksonXmlProperty(localName = "TrackID") - @JacksonXmlElementWrapper(useWrapping = false) - private List trackIds; - - @JsonIgnore - public void addTrackingNumber(String trackingNumber) { - if (trackingNumber == null) { - return; - } - TrackId trackId = new TrackId(trackingNumber); - if (trackIds == null) { - trackIds = new ArrayList<>(); - } - trackIds.add(trackId); - } - -} +package io.ljunggren.usps.legacy.api.tracking.request; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JacksonXmlRootElement(localName = "TrackFieldRequest") +public class TrackFieldRequest { + + @JacksonXmlProperty(isAttribute = true, localName = "USERID") + private String userId; + @JacksonXmlProperty(localName = "Revision") + private int revision = 1; + @JacksonXmlProperty(localName = "ClientIp") + private String clientIp = "127.0.0.1"; + @JacksonXmlProperty(localName = "SourceId") + private String sourceId = "Default"; + @JacksonXmlProperty(localName = "TrackID") + @JacksonXmlElementWrapper(useWrapping = false) + private List trackIds; + + @JsonIgnore + public void addTrackingNumber(String trackingNumber) { + if (trackingNumber == null) { + return; + } + TrackId trackId = new TrackId(trackingNumber); + if (trackIds == null) { + trackIds = new ArrayList<>(); + } + trackIds.add(trackId); + } + +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackId.java b/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackId.java index ef4ed5d..0d4669e 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackId.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/tracking/request/TrackId.java @@ -1,19 +1,19 @@ -package io.ljunggren.usps.legacy.api.tracking.request; - -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@JacksonXmlRootElement(localName = "TrackID") -public class TrackId { - - @JacksonXmlProperty(isAttribute = true, localName = "ID") - private String id; - -} +package io.ljunggren.usps.legacy.api.tracking.request; + +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JacksonXmlRootElement(localName = "TrackID") +public class TrackId { + + @JacksonXmlProperty(isAttribute = true, localName = "ID") + private String id; + +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/Error.java b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/Error.java index 2f321e8..6518dde 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/Error.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/Error.java @@ -1,24 +1,24 @@ -package io.ljunggren.usps.legacy.api.tracking.response; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(value = Include.NON_NULL) -public class Error { - - @JacksonXmlProperty(localName = "Number") - private long number; - @JacksonXmlProperty(localName = "Description") - private String description; - -} +package io.ljunggren.usps.legacy.api.tracking.response; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(value = Include.NON_NULL) +public class Error { + + @JacksonXmlProperty(localName = "Number") + private long number; + @JacksonXmlProperty(localName = "Description") + private String description; + +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackDetail.java b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackDetail.java index 9a526c7..706dfe8 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackDetail.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackDetail.java @@ -1,49 +1,49 @@ -package io.ljunggren.usps.legacy.api.tracking.response; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(value = Include.NON_NULL) -public class TrackDetail { - - @JacksonXmlProperty(localName = "EventTime") - private String eventTime; - @JacksonXmlProperty(localName = "EventDate") - private String eventDate; - @JacksonXmlProperty(localName = "Event") - private String event; - @JacksonXmlProperty(localName = "EventCity") - private String eventCity; - @JacksonXmlProperty(localName = "EventState") - private String eventState; - @JacksonXmlProperty(localName = "EventZIPCode") - private String eventZipCode; - @JacksonXmlProperty(localName = "EventCountry") - private String eventCountry; - @JacksonXmlProperty(localName = "FirmName") - private String firmName; - @JacksonXmlProperty(localName = "Name") - private String name; - @JacksonXmlProperty(localName = "AuthorizedAgent") - private boolean authorizedAgent; - @JacksonXmlProperty(localName = "EventCode") - private String eventCode; - @JacksonXmlProperty(localName = "DeliveryAttributeCode") - private String deliveryAttributeCode; - @JacksonXmlProperty(localName = "GMT") - private String gmt; - @JacksonXmlProperty(localName = "GMTOffset") - private String gmtOffset; - - -} +package io.ljunggren.usps.legacy.api.tracking.response; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(value = Include.NON_NULL) +public class TrackDetail { + + @JacksonXmlProperty(localName = "EventTime") + private String eventTime; + @JacksonXmlProperty(localName = "EventDate") + private String eventDate; + @JacksonXmlProperty(localName = "Event") + private String event; + @JacksonXmlProperty(localName = "EventCity") + private String eventCity; + @JacksonXmlProperty(localName = "EventState") + private String eventState; + @JacksonXmlProperty(localName = "EventZIPCode") + private String eventZipCode; + @JacksonXmlProperty(localName = "EventCountry") + private String eventCountry; + @JacksonXmlProperty(localName = "FirmName") + private String firmName; + @JacksonXmlProperty(localName = "Name") + private String name; + @JacksonXmlProperty(localName = "AuthorizedAgent") + private boolean authorizedAgent; + @JacksonXmlProperty(localName = "EventCode") + private String eventCode; + @JacksonXmlProperty(localName = "DeliveryAttributeCode") + private String deliveryAttributeCode; + @JacksonXmlProperty(localName = "GMT") + private String gmt; + @JacksonXmlProperty(localName = "GMTOffset") + private String gmtOffset; + + +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackInfo.java b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackInfo.java index 5dff8dc..29c1bb2 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackInfo.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackInfo.java @@ -1,96 +1,96 @@ -package io.ljunggren.usps.legacy.api.tracking.response; - -import java.util.Date; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonFormat; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(value = Include.NON_NULL) -public class TrackInfo { - - @JacksonXmlProperty(isAttribute = true, localName = "ID") - private String id; - @JacksonXmlProperty(localName = "Class") - private String clazz; - @JacksonXmlProperty(localName = "ClassOfMailCode") - private String classOfMailcode; - @JacksonXmlProperty(localName = "DestinationCity") - private String destinationCidy; - @JacksonXmlProperty(localName = "DestinationState") - private String destinationState; - @JacksonXmlProperty(localName = "DestinationZip") - private String destinationZip; - @JacksonXmlProperty(localName = "EmailEnabled") - private Boolean emailEnabled; - @JacksonXmlProperty(localName = "ExpectedDeliveryDate") - private String expectedDeliveryDate; - @JacksonXmlProperty(localName = "ExpectedDeliveryTime") - private String expectedDeliveryTime; - @JacksonXmlProperty(localName = "ExpectedDeliveryType") - private String expectedDeliveryType; - @JacksonXmlProperty(localName = "GuaranteedDeliveryDate") - private String guaranteedDeliveryDate; - @JacksonXmlProperty(localName = "GuaranteedDeliveryTime") - private String guaranteedDeliveryTime; - @JacksonXmlProperty(localName = "GuaranteedDeliveryType") - private String guaranteedDeliveryType; - @JacksonXmlProperty(localName = "KahalaIndicator") - private Boolean kahalaIndicator; - @JacksonXmlProperty(localName = "MailTypeCode") - private String mailTypeCode; - @JacksonXmlProperty(localName = "MPDATE") - @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSSSSS") - private Date mpDate; - @JacksonXmlProperty(localName = "MPSUFFIX") - private Date mpSuffix; - @JacksonXmlProperty(localName = "OriginCity") - private String originCity; - @JacksonXmlProperty(localName = "OriginState") - private String originState; - @JacksonXmlProperty(localName = "OriginZip") - private String originZip; - @JacksonXmlProperty(localName = "PodEnabled") - private Boolean podEnabled; - @JacksonXmlProperty(localName = "TPodEnabled") - private Boolean tPodEnabled; - @JacksonXmlProperty(localName = "RestoreEnabled") - private Boolean restoreEnabled; - @JacksonXmlProperty(localName = "RramEnabled") - private Boolean rramEnabled; - @JacksonXmlProperty(localName = "RreEnabled") - private Boolean rreEnabled; - @JacksonXmlProperty(localName = "Service") - @JacksonXmlElementWrapper(useWrapping = false) - private List services; - @JacksonXmlProperty(localName = "ServiceTypeCode") - private String serviceTypeCode; - @JacksonXmlProperty(localName = "Status") - private String status; - @JacksonXmlProperty(localName = "StatusCategory") - private String statusCategory; - @JacksonXmlProperty(localName = "StatusSummary") - private String statusSummary; - @JacksonXmlProperty(localName = "TABLECODE") - private String tableCode; - @JacksonXmlProperty(localName = "TrackSummary") - @JacksonXmlElementWrapper(useWrapping = false) - private List trackSummaries; - @JacksonXmlProperty(localName = "TrackDetail") - @JacksonXmlElementWrapper(useWrapping = false) - private List trackDetails; - @JacksonXmlProperty(localName = "Error") - private Error error; -} +package io.ljunggren.usps.legacy.api.tracking.response; + +import java.util.Date; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(value = Include.NON_NULL) +public class TrackInfo { + + @JacksonXmlProperty(isAttribute = true, localName = "ID") + private String id; + @JacksonXmlProperty(localName = "Class") + private String clazz; + @JacksonXmlProperty(localName = "ClassOfMailCode") + private String classOfMailcode; + @JacksonXmlProperty(localName = "DestinationCity") + private String destinationCidy; + @JacksonXmlProperty(localName = "DestinationState") + private String destinationState; + @JacksonXmlProperty(localName = "DestinationZip") + private String destinationZip; + @JacksonXmlProperty(localName = "EmailEnabled") + private Boolean emailEnabled; + @JacksonXmlProperty(localName = "ExpectedDeliveryDate") + private String expectedDeliveryDate; + @JacksonXmlProperty(localName = "ExpectedDeliveryTime") + private String expectedDeliveryTime; + @JacksonXmlProperty(localName = "ExpectedDeliveryType") + private String expectedDeliveryType; + @JacksonXmlProperty(localName = "GuaranteedDeliveryDate") + private String guaranteedDeliveryDate; + @JacksonXmlProperty(localName = "GuaranteedDeliveryTime") + private String guaranteedDeliveryTime; + @JacksonXmlProperty(localName = "GuaranteedDeliveryType") + private String guaranteedDeliveryType; + @JacksonXmlProperty(localName = "KahalaIndicator") + private Boolean kahalaIndicator; + @JacksonXmlProperty(localName = "MailTypeCode") + private String mailTypeCode; + @JacksonXmlProperty(localName = "MPDATE") + @JsonFormat(pattern="yyyy-MM-dd HH:mm:ss.SSSSSS") + private Date mpDate; + @JacksonXmlProperty(localName = "MPSUFFIX") + private Date mpSuffix; + @JacksonXmlProperty(localName = "OriginCity") + private String originCity; + @JacksonXmlProperty(localName = "OriginState") + private String originState; + @JacksonXmlProperty(localName = "OriginZip") + private String originZip; + @JacksonXmlProperty(localName = "PodEnabled") + private Boolean podEnabled; + @JacksonXmlProperty(localName = "TPodEnabled") + private Boolean tPodEnabled; + @JacksonXmlProperty(localName = "RestoreEnabled") + private Boolean restoreEnabled; + @JacksonXmlProperty(localName = "RramEnabled") + private Boolean rramEnabled; + @JacksonXmlProperty(localName = "RreEnabled") + private Boolean rreEnabled; + @JacksonXmlProperty(localName = "Service") + @JacksonXmlElementWrapper(useWrapping = false) + private List services; + @JacksonXmlProperty(localName = "ServiceTypeCode") + private String serviceTypeCode; + @JacksonXmlProperty(localName = "Status") + private String status; + @JacksonXmlProperty(localName = "StatusCategory") + private String statusCategory; + @JacksonXmlProperty(localName = "StatusSummary") + private String statusSummary; + @JacksonXmlProperty(localName = "TABLECODE") + private String tableCode; + @JacksonXmlProperty(localName = "TrackSummary") + @JacksonXmlElementWrapper(useWrapping = false) + private List trackSummaries; + @JacksonXmlProperty(localName = "TrackDetail") + @JacksonXmlElementWrapper(useWrapping = false) + private List trackDetails; + @JacksonXmlProperty(localName = "Error") + private Error error; +} diff --git a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackingResponse.java b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackingResponse.java index 3e26dee..cb722eb 100644 --- a/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackingResponse.java +++ b/src/main/java/io/ljunggren/usps/legacy/api/tracking/response/TrackingResponse.java @@ -1,41 +1,41 @@ -package io.ljunggren.usps.legacy.api.tracking.response; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; -import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonInclude(value = Include.NON_NULL) -@JacksonXmlRootElement(localName = "TrackResponse") -public class TrackingResponse { - - @JacksonXmlProperty(localName = "TrackInfo") - @JacksonXmlElementWrapper(useWrapping = false) - private List trackInfos; - - @JsonIgnore - public void addTrackInfo(TrackInfo trackInfo) { - if (trackInfo == null) { - return; - } - if (trackInfos == null) { - trackInfos = new ArrayList<>(); - } - trackInfos.add(trackInfo); - } - -} +package io.ljunggren.usps.legacy.api.tracking.response; + +import java.util.ArrayList; +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; +import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(value = Include.NON_NULL) +@JacksonXmlRootElement(localName = "TrackResponse") +public class TrackingResponse { + + @JacksonXmlProperty(localName = "TrackInfo") + @JacksonXmlElementWrapper(useWrapping = false) + private List trackInfos; + + @JsonIgnore + public void addTrackInfo(TrackInfo trackInfo) { + if (trackInfo == null) { + return; + } + if (trackInfos == null) { + trackInfos = new ArrayList<>(); + } + trackInfos.add(trackInfo); + } + +} diff --git a/src/test/resources/trackFieldRequest.xml b/src/test/resources/trackFieldRequest.xml index c1d303a..e68bce8 100644 --- a/src/test/resources/trackFieldRequest.xml +++ b/src/test/resources/trackFieldRequest.xml @@ -1,6 +1,6 @@ - -1 -127.0.0.1 -tracking - + +1 +127.0.0.1 +tracking + \ No newline at end of file diff --git a/src/test/resources/trackingResponse.xml b/src/test/resources/trackingResponse.xml index 0e98d65..52e337a 100644 --- a/src/test/resources/trackingResponse.xml +++ b/src/test/resources/trackingResponse.xml @@ -1,243 +1,243 @@ - - - USPS Ground Advantage<SUP>&#153;</SUP> - FC - AVON - IN - 46123 - true - false - DM - 2024-09-11 14:25:20.000000 - 444855581 - DANVILLE - IN - 46122 - true - false - false - false - false - Signature Confirmation<SUP>&#153;</SUP> - Up to $100 insurance included - 021 - Delivered, Individual Picked Up at Post Office - Delivered - Your item was picked up at the post office at 1:52 pm on September 18, 2024 in DANVILLE, IN 46122. The item was signed for by A LJUMGGREN. - T - - 1:52 pm - September 18, 2024 - Delivered, Individual Picked Up at Post Office - DANVILLE - IN - 46122 - - - A LJUMGGREN - false - 01 - - 17:52:00 - -04:00 - - - - September 16, 2024 - Redelivery Scheduled - AVON - IN - 46123 - - - - false - VR - - - - - - 3:35 pm - September 13, 2024 - Notice Left (No Authorized Recipient Available) - AVON - IN - 46123 - - - - false - 56 - - 19:35:35 - -04:00 - - - 7:59 am - September 13, 2024 - Out for Delivery - AVON - IN - 46123 - - - - false - OF - - 11:59:41 - -04:00 - - - 7:48 am - September 13, 2024 - Arrived at Post Office - DANVILLE - IN - 46122 - - - - false - 07 - - 11:48:41 - -04:00 - - - 4:35 am - September 13, 2024 - Arrived at USPS Facility - DANVILLE - IN - 46122 - - - - false - U1 - - 08:35:05 - -04:00 - - - 3:21 am - September 13, 2024 - In Transit to Next Facility - - - - - - - false - TL - - 07:21:46 - -04:00 - - - 3:03 am - September 13, 2024 - Departed USPS Regional Facility - INDIANAPOLIS IN DISTRIBUTION CENTER - - - - - - false - T1 - - 07:03:22 - -04:00 - - - 8:27 pm - September 12, 2024 - Arrived at USPS Regional Destination Facility - INDIANAPOLIS IN DISTRIBUTION CENTER - - - - - - false - 10 - - 00:27:19 - -04:00 - - - 10:05 pm - September 11, 2024 - Arrived at USPS Origin Facility - SAINT PAUL - MN - 55131 - - - - false - 10 - - 04:05:21 - -06:00 - - - 8:50 pm - September 11, 2024 - Accepted at USPS Origin Facility - SAINT PAUL - MN - 55128 - - - - false - OA - - 01:50:21 - -05:00 - - - 3:31 pm - September 11, 2024 - Shipment Received, Package Acceptance Pending - SAINT PAUL - MN - 55128 - - - - false - TM - - 20:31:46 - -05:00 - - - 1:48 pm - September 11, 2024 - Shipping Label Created, USPS Awaiting Item - SAINT PAUL - MN - 55128 - - - - false - GX - - 18:48:22 - -05:00 - - - - - -2147219283 - A status update is not yet available on your package. It will be available when the shipper provides an update or the package is given to USPS. Check back soon. Sign up for Informed Delivery<SUP>&reg;</SUP> to receive notifications for packages addressed to you. - - + + + USPS Ground Advantage<SUP>&#153;</SUP> + FC + AVON + IN + 46123 + true + false + DM + 2024-09-11 14:25:20.000000 + 444855581 + DANVILLE + IN + 46122 + true + false + false + false + false + Signature Confirmation<SUP>&#153;</SUP> + Up to $100 insurance included + 021 + Delivered, Individual Picked Up at Post Office + Delivered + Your item was picked up at the post office at 1:52 pm on September 18, 2024 in DANVILLE, IN 46122. The item was signed for by A LJUMGGREN. + T + + 1:52 pm + September 18, 2024 + Delivered, Individual Picked Up at Post Office + DANVILLE + IN + 46122 + + + A LJUMGGREN + false + 01 + + 17:52:00 + -04:00 + + + + September 16, 2024 + Redelivery Scheduled + AVON + IN + 46123 + + + + false + VR + + + + + + 3:35 pm + September 13, 2024 + Notice Left (No Authorized Recipient Available) + AVON + IN + 46123 + + + + false + 56 + + 19:35:35 + -04:00 + + + 7:59 am + September 13, 2024 + Out for Delivery + AVON + IN + 46123 + + + + false + OF + + 11:59:41 + -04:00 + + + 7:48 am + September 13, 2024 + Arrived at Post Office + DANVILLE + IN + 46122 + + + + false + 07 + + 11:48:41 + -04:00 + + + 4:35 am + September 13, 2024 + Arrived at USPS Facility + DANVILLE + IN + 46122 + + + + false + U1 + + 08:35:05 + -04:00 + + + 3:21 am + September 13, 2024 + In Transit to Next Facility + + + + + + + false + TL + + 07:21:46 + -04:00 + + + 3:03 am + September 13, 2024 + Departed USPS Regional Facility + INDIANAPOLIS IN DISTRIBUTION CENTER + + + + + + false + T1 + + 07:03:22 + -04:00 + + + 8:27 pm + September 12, 2024 + Arrived at USPS Regional Destination Facility + INDIANAPOLIS IN DISTRIBUTION CENTER + + + + + + false + 10 + + 00:27:19 + -04:00 + + + 10:05 pm + September 11, 2024 + Arrived at USPS Origin Facility + SAINT PAUL + MN + 55131 + + + + false + 10 + + 04:05:21 + -06:00 + + + 8:50 pm + September 11, 2024 + Accepted at USPS Origin Facility + SAINT PAUL + MN + 55128 + + + + false + OA + + 01:50:21 + -05:00 + + + 3:31 pm + September 11, 2024 + Shipment Received, Package Acceptance Pending + SAINT PAUL + MN + 55128 + + + + false + TM + + 20:31:46 + -05:00 + + + 1:48 pm + September 11, 2024 + Shipping Label Created, USPS Awaiting Item + SAINT PAUL + MN + 55128 + + + + false + GX + + 18:48:22 + -05:00 + + + + + -2147219283 + A status update is not yet available on your package. It will be available when the shipper provides an update or the package is given to USPS. Check back soon. Sign up for Informed Delivery<SUP>&reg;</SUP> to receive notifications for packages addressed to you. + + \ No newline at end of file