package com.ssk.ws.custom.wsdl.types;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;

public class HRServiceClient2 {
	
	private static EndpointReference targetEPR = new EndpointReference(
			"http://localhost:8080/axis2/services/HRService");

	public static OMElement getEmployeeRequest(String eid) {
		
		OMFactory fac = OMAbstractFactory.getOMFactory();
		OMNamespace omNs = fac.createOMNamespace(
				"http://types.wsdl.custom.ws.ssk.com/xsd", "hr");

		OMElement method = fac.createOMElement("getEmployee", omNs);
		OMElement value = fac.createOMElement("in", omNs);
		value.addChild(fac.createOMText(value, eid));
		method.addChild(value);
		return method;
	}

	public static void main(String[] args) {
		try {
			OMElement getEmployeeRequest = getEmployeeRequest("1");
			Options options = new Options();
			options.setTo(targetEPR);
			options.setTransportInProtocol(Constants.TRANSPORT_HTTP);

			ServiceClient sender = new ServiceClient();
			sender.setOptions(options);
			
			System.out.println("Sending request..");
			getEmployeeRequest.serialize(System.out);
			
			OMElement result = sender.sendReceive(getEmployeeRequest);
			
			System.out.println();
			System.out.println("Got Request!");
			result.serialize(System.out);
			
			//String response = result.getFirstElement().getText();
			//System.err.println("Current price of WSO: " + response);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
