有一个web服务,我需要检索3个java对象。这些是对象
@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
}
我的问题在于吸气剂。这是GET代码。客户变量是泽西客户端。
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;
}
每当我尝试运行代码时,它都会在webResource.accept(MediaType.APPLICATION_XML).accept(XmlLicenseFile.class)部分失败。它失败并出现ClientException。知道为什么它会因为解组而失败吗?
- EDIT-- 这是正在构建的URI 本地主机/ myWS / 1.0 / licenseFiles / EBB080CCFB02309AE0440021287E6A9E
如果我在浏览器中点击该URL,则返回有效的licenseFile。
答案 0 :(得分:0)
所以,问题是URI没有&#34; http://&#34;部分。一旦我补充说,这一切都奏效了! :d