public UploadHostPicturesExternal() { ApiCredential cred = new ApiCredential(); apiContext.setApiCredential(cred); //set api call credential apiContext.getApiCredential().seteBayToken(USERTOKEN); //enable api logging apiContext.setApiLogging(apiLogging); //register EPS server URL in ApiContext object apiContext.setEpsServerUrl(SERVERURL);
}
public static void main(String[] args) { UploadHostPicturesExternal sample = new UploadHostPicturesExternal(); try { // create and initial an UploadSiteHostedPicturesRequestType object UploadSiteHostedPicturesRequestType requestObj = new UploadSiteHostedPicturesRequestType(); requestObj.setWarningLevel(WarningLevelCodeType.HIGH);
//set the ExternalPictureURL with the image URL string array requestObj.setExternalPictureURL(pictureURL); UploadSiteHostedPicturesResponseType responseObj = sample.upLoadSiteHostedPicture(requestObj); if (responseObj != null && responseObj instanceof UploadSiteHostedPicturesResponseType) { UploadSiteHostedPicturesResponseType response = (UploadSiteHostedPicturesResponseType) responseObj; System.out.println(response.getAck()); System.out.println(response.getBuild()); System.out.println(response.getSiteHostedPictureDetails().getFullURL());
private static String convertFileContent2String(String fileName) { String fileContentInString = ""; try { File soapFile = new File(fileName); byte fileContent[] = new byte[(int) soapFile.length()]; FileInputStream soapFileIS = new FileInputStream(soapFile); soapFileIS.read(fileContent, 0, fileContent.length); fileContentInString = new String(fileContent); } catch (Exception ex) { throw new RuntimeException(ex); }
return fileContentInString; }
/** * Add eBay API authentication token to the XML Document * @param doc, XML Document * @throws SdkException */ private void addAuthToken(Document doc) throws SdkException { Node node = XmlUtil.getChildByName(doc, "UploadSiteHostedPicturesRequest"); Node requesterCredentials = XmlUtil.appendChildNode(doc, EBAY_NAMESPACE, node, "RequesterCredentials"); String tokenString = this.apiContext.getApiCredential().geteBayToken(); if (tokenString == null || tokenString.length() == 0) { throw new SdkException("No Token Found!!!"); } else { XmlUtil.appendChildNode(doc, requesterCredentials, "eBayAuthToken", tokenString); } }
/** * Convert an XML Document to an XML String * @param doc, XML Document * @return string representation of the XML document * @throws TransformerException */ private String xmlToString(Document doc) throws TransformerException { Source source = new DOMSource(doc); StringWriter stringWriter = new StringWriter(); Result result = new StreamResult(stringWriter); TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(); transformer.transform(source, result); return stringWriter.getBuffer().toString(); }