So, the issue was that the URI didn't have the "http://" part. Once I added that, it all worked! :D
Issues unmarshalling POJO
-
13-07-2023 - |
Question
There's a webservice that has 3 java objects that I need to retrieve. These are the objects
@XmlRootElement(name="licenseFile")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlLicenseFile implements Cloneable
{
//URI Info
public static final String URI_PATH = "licenseFiles";
@XmlAttribute
private String url;
//Base License Info
private String licenseFileId;
private String licenseStatus;
private String licenseFileType;
private String licenseFileVersion;
//Request Info
private String requestSource;
private String locale;
private Boolean overrideErrors;
private String internallyRequestingUserId;
private String requestorUserProfileId;
private String externalIpAddress;
private Boolean internalUseOnly;
//Contract Info
private String serviceId; //Used to be called contractNumber
private String contractAdminName;
private String contractAdminEmail;
private String organizationName;
private String contractStartDate;
private String contractEndDate;
private Boolean overdraftAllowed;
private String vlaType;
private Integer vlaLogAutoSendFrequency;
//Server Info
@XmlElementWrapper(name="licenseServers")
@XmlElement(name="licenseServer")
private List<XmlLicenseServer> licenseServers;
//License Package Info
@XmlElementWrapper(name="licensePackages")
@XmlElement(name="licensePackage")
private List<XmlLicensePackage> licensePackages;
//Error Info
private String errorType;
private Integer errorCode;
private String errorDescription;
//Database Info
private String creationDate;
private String lastUpdateDate;
//License Content
private String licenseFileName;
private String licenseFileContent;
public String getOrganizationName() {
return organizationName;
}
public void setOrganizationName(String organizationName) {
this.organizationName = organizationName;
}
// ALL OF THE OTHER SETTERS AND GETTERS GO HERE
}
@XmlRootElement(name="licensePackage")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlLicensePackage
{
//URI Info
public static final String URI_PATH = "licensePackages";
@XmlAttribute
private String url;
//Base Package Info
private String licensePackageId;
private String licenseFileId;
private String packageStatus;
private String partNumber;
//Package Info
private String packageName;
private String packageVersion; //Calculated
private String operatingSystem; //Can be calculated or passed in
//Generation Info
private String serialNumber;
private Integer seatCount;
private String packageExpireDate;
//Client/Concurrency Info
private String concurrencyType;
private String clientType;
//Reconciliation Info
private String productReconciliationId;
//Error Info
private String errorType;
private Integer errorCode;
private String errorDescription;
//Database Info
private String creationDate;
private String lastUpdateDate;
//ALL THE GETTERS AND SETTERS
}
@XmlRootElement(name="licenseServer")
@XmlAccessorType(XmlAccessType.FIELD)
public class XmlLicenseServer
{
private String serverName;
private String computerId;
//ALL SETTERS AND GETTERS HERE
}
My issue is with the getter. Here's the GET code. The client variable is a jersey client.
public static XmlLicenseFile getLicenseFile(String key){
XmlLicenseFile returnedFile = null;
URI uri = constructURIByFileId(key); //THIS CREATES THE URI, AND I'VE CONFIRMED IT'S CORRECT
try{
WebResource webResource = client.resource(uri.toString());
returnedFile = webResource.accept(MediaType.APPLICATION_XML).get(XmlLicenseFile.class);
if(returnedFile == null){
throw new ProviderException(ResponseErrorType.NOT_FOUND, "The license file doesn't exists", "", "");
} //TODO Fill error cases
}catch(Exception e){
logger.error(e);
throw new ProviderException(ResponseErrorType.INTERNAL_SERVICE_ERROR, "Internal Server Error", "", "");
}
return returnedFile;
}
Everytime I try to run the code, it fails in the webResource.accept(MediaType.APPLICATION_XML).accept(XmlLicenseFile.class) part. It fails with a ClientException. Any idea why is it failing with the unmarshalling?
--EDIT-- Here's the URI that's being built localhost/myWS/1.0/licenseFiles/EBB080CCFB02309AE0440021287E6A9E
If I hit that URL in the browser, it returns the valid licenseFile.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow