Friday, September 18, 2015

Oracle Taleo WebService Sample Client Code to Create New Candidate

Let's assume you wants to import the candidates into Taleo systems. Using Taleo BulkAPI, CandidateService allows your application to create and update a candidate in Taleo systems.

We can implement the above usecase with following options:

  • Java Code using SAAJ: SAAJ stands for "SOAP with Attachments API for Java." With it, you can make Java API calls that generate XML messages which comply with the SOAP 1.1 or 1.2 specifications, as well as the WS-I Basic Profile 1.1 specification. It allows developers to read and write SOAP-based XML messages, and in some cases, to send and receive those messages over the Internet. SAAJ offers an alternative to JAX-RPC or JAX-WS
public class SOAPClientSAAJ {
     * This method process the new candidate creation
     * @return employeeNumber
     * @throws SOAPException
     * @throws Exception
    public static String processCandidateCreationSOAPRequest() throws SOAPException, Exception {
        SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
        SOAPConnection soapConnection = soapConnectionFactory.createConnection();

        // Trust to certificates

        // Send SOAP Message to SOAP Server
        String url = "";
        SOAPMessage soapResponse =, url);
        String employeeNumber = processCandidateCreationSOAPResponse(soapResponse);
        return employeeNumber;
    public SOAPClientSAAJ() {
     * This method parse the soapResponse and gets the employeeNumber 
     * @param soapResponse
     * @return employeeNumber
     * @throws TransformerConfigurationException
     * @throws SOAPException
     * @throws ParserConfigurationException
     * @throws TransformerException
     * @throws SAXException
     * @throws IOException
    private static String processCandidateCreationSOAPResponse(SOAPMessage soapResponse) throws TransformerConfigurationException,
                                                                               TransformerException, SAXException,
                                                                               IOException {
        TransformerFactory transformerFactory = TransformerFactory.newInstance();
        Transformer transformer = transformerFactory.newTransformer();
        Source sourceContent = soapResponse.getSOAPPart().getContent();
        StringWriter writer = new StringWriter();
        transformer.transform(sourceContent, new StreamResult(writer));
        String output = writer.toString();

        DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        InputSource is = new InputSource();
        is.setCharacterStream(new StringReader(output));

        Document doc = db.parse(is);
        NodeList nodes = doc.getElementsByTagName("createResponse");
        Element element = (Element)nodes.item(0);
        NodeList name = element.getElementsByTagName("Number");
        Element line = (Element)name.item(0);
        return getCharacterDataFromElement(line).toString();

     * This method creates the soapMessage and calls the webservice
     * @return
     * @throws Exception
    private static SOAPMessage callCandidateCreationSOAPRequest() throws Exception {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("can", "");

        SOAPHeader soapHeader = envelope.getHeader();
        SOAPElement SecuritySoapElement = soapHeader.addChildElement("Security", "ns1");
        SOAPElement usernameTokenSoapElement = SecuritySoapElement.addChildElement("UsernameToken", "ns1");

        SOAPElement usernameSoapElement = usernameTokenSoapElement.addChildElement("Username", "ns1");
        SOAPElement passwordSoapElement = usernameTokenSoapElement.addChildElement("Password", "ns1");

        // SOAP Body
        SOAPBody soapBody = envelope.getBody();
        SOAPElement createSoapBodyElem = soapBody.addChildElement("create", "can");
        SOAPElement candidateSoapBodyElem = createSoapBodyElem.addChildElement("candidate", "can");

        SOAPElement emailAddressSoapBodyElem = candidateSoapBodyElem.addChildElement("EmailAddress", "can");

        SOAPElement addressSoapBodyElem = candidateSoapBodyElem.addChildElement("Address", "can");
        addressSoapBodyElem.addTextNode("123 Main Street");

        SOAPElement address2SoapBodyElem = candidateSoapBodyElem.addChildElement("Address2", "can");
        address2SoapBodyElem.addTextNode("Apartment 1");

        SOAPElement firstNameSoapBodyElem = candidateSoapBodyElem.addChildElement("FirstName", "can");

        SOAPElement lastNameSoapBodyElem = candidateSoapBodyElem.addChildElement("LastName", "can");

        // Save message
        return soapMessage;

     * This method trust the https certificates 
     * @throws Exception
    private static void doTrustToCertificates() throws Exception {
        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;

                public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {

                public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
            } };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        HostnameVerifier hv = new HostnameVerifier() {
            public boolean verify(String urlHostName, SSLSession session) {
                if (!urlHostName.equalsIgnoreCase(session.getPeerHost())) {
                    System.out.println("Warning: URL host '" + urlHostName + "' is different to SSLSession host '" +
                                       session.getPeerHost() + "'.");
                return true;

    private static String getCharacterDataFromElement(Element e) {
        Node child = e.getFirstChild();
        if (child instanceof CharacterData) {
            CharacterData cd = (CharacterData)child;
            return cd.getData();
        return "";


  • Java Code using Apache Axis2: - First you should Import the WSDL Files into Your Development Platform using below command.

“wsdl2java.bat -uri pathToWsdl/WsdlFilename -d xmlbeans -ns2p namespaceURL=javaPackageName”

public class CandidateDC {
     * Main method call the importCandidate method
     * @param args
    public static void main(String[] args) {
        try {
            long employeeNumber = importCandidate();
            System.out.println("Candidate Num: " + employeeNumber);
        } catch (AxisFault e) {
        } catch (RemoteException e) {
        } catch (WebServiceFault e) {
     * This method process the new candidate creation
     * @return employeeNumber
     * @throws AxisFault
     * @throws RemoteException
     * @throws WebServiceFault
    public static long importCandidate() throws AxisFault, RemoteException, WebServiceFault {
        CandidateServiceStub stub =
            new CandidateServiceStub("https://hostname/enterprise/soap?ServiceName=CandidateService");
        HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
        auth.setPreemptiveAuthentication(true); // activate preemptive authentication
        stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);

        CreateDocument createDoc = CreateDocument.Factory.newInstance();
        CreateDocument.Create create = createDoc.addNewCreate();
        Candidate candidate = create.addNewCandidate();

        SearchableStringField address = candidate.addNewAddress();
        address.setStringValue("123 Main Street");

        SearchableStringField address2 = candidate.addNewAddress2();
        address2.setStringValue("Apartment 1");

        SearchableStringField lastName = candidate.addNewLastName();

        SearchableStringField firstName = candidate.addNewFirstName();

        SearchableStringField emailAddress = candidate.addNewEmailAddress();

        CreateResponseDocument createResponse = stub.create(createDoc);
        long val = createResponse.getCreateResponse().getNumber();
        return val;
 public CandidateDC() {

If you get the " Software caused connection abort: recv failed" issue - More Details


  1. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Thanks for such post and please keep it up. Oracle ADF online Training

  2. Superb i really enjoyed very much with this article here. Really its a amazing article i had ever read. I hope it will help a lot for all. Thank you so much for this amazing posts and please keep update like this excellent article.thank you for sharing such a great blog with us. expecting for your updation.
    Digital Marketing Company in Chennai


  3. Wonderful blog.. Thanks for sharing informative Post. Its very useful to me.

    Installment loans
    Payday loans
    Title loans

  4. The information regarding oracle updates are more helpful to learn about new techniques.

  5. Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!
    Web development company in bangalore
    Outsource magento ecommerce services india
    ECommerce Website developers in bangalore

  6. Do you want to pursue Oracle Taleo as your Profession? You can join the course, where industry expert mentors run the entire training module. The tutorial is composed of latest industry updates and business insights so that besides theoretical knowledge, the participants can acquire best industry knowledge and compatibility. The Oracle Taleo Training has flexible timing so that on job professionals can join the course for their career development.

  7. Is this also applicable to TEE (Taleo Enterprise Edition) hosted on cloud

  8. Thank you for providing useful information and this is the best article blog for the students.learn Oracle Fusion Financials Online Training.

    Oracle Fusion Financials Online Training

  9. Thank you for sharing such a valuable article with good information containing in this blog.learn Oracle Fusion Technical Online Training.

    Oracle Fusion Technical Online Training

  10. Thanks for sharing valuable information in the article.students can make a good career by learning Oracle Fusion SCM Online Training.

    Oracle Fusion SCM Online Training

  11. Thanks for providing such a great information in the blog and also very helpful to all.learn best Oracle Fusion HCM Online Training.

    Oracle Fusion HCM Online Training

  12. I would like to thank you for the efforts you have made in writing this article. I am hoping the same best work from you in the future as well. Oracle Fusion Financials Online Training

  13. Awesome post. your article is really informative and helpful for me and other bloggers too Oracle Fusion Financials Online Training

  14. Thank you for providing useful information and this is the best article blog for the students.

    Oracle Fusion Technical Online Training

  15. Thank you for sharing such a valuable article with good information containing in this blog.

    Oracle Fusion SCM Online Training

  16. Thanks for sharing valuable information in the article.students can make a good career

    HR Training In Hyderabad

  17. Thanks for providing such a great information in the blog and also very helpful to all the students.

    Core HR Training Hyderabad

  18. Thank you for providing useful information and this is the best article blog for the students.

    Oracle Fusion HCM Online Training