Skip to content

Instantly share code, notes, and snippets.

@xignite-engineering
Forked from slpsys/axis2.java
Created December 17, 2012 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xignite-engineering/4323381 to your computer and use it in GitHub Desktop.
Save xignite-engineering/4323381 to your computer and use it in GitHub Desktop.
import com.xignite.www.services.XigniteGlobalHistoricalXigniteGlobalHistoricalSoapStub;
import com.xignite.www.services.XigniteGlobalHistoricalXigniteGlobalHistoricalSoapStub.GetGlobalHistoricalQuotesRangeResponse;
import com.xignite.www.services.XigniteGlobalHistoricalXigniteGlobalHistoricalSoapStub.*;
import javax.xml.stream.util.*;
import org.apache.axis2.addressing.*;
import java.util.*;
public class Axis2Test {
private XigniteGlobalHistoricalXigniteGlobalHistoricalSoapStub stub;
private HeaderE header;
public Axis2Test() {
try {
// One-time initialization code
this.stub = new XigniteGlobalHistoricalXigniteGlobalHistoricalSoapStub();
this.header = new HeaderE();
Header myHeader = new Header();
// Optimally, this would be your API token, not your email address
myHeader.setUsername("you@yourcompany.com");
this.header.setHeader(myHeader);
}
catch (org.apache.axis2.AxisFault af) {
System.err.println("Could not intitialize request: " + af.getMessage());
af.printStackTrace();
}
}
public static final String SERVICE_URI = "http://www.xignite.com/services/";
public HeaderE getHeader () { return this.header; };
public XigniteGlobalHistoricalXigniteGlobalHistoricalSoapStub getStub() { return this.stub; }
protected void retrieveQuotes(String symbol) throws Exception {
// Instantiate the XigniteGlobalHistorical proxy
// proxy object using the Helper class.
// This class was autogenerated by the WSDL2Java tool
try {
// Instantiate the return class from the operation
// This class was autogenerated by the WSDL2Java tool
this.stub._getServiceClient().setTargetEPR(new EndpointReference("http://globalhistorical.xignite.com/xGlobalHistorical.asmx"));
GetGlobalHistoricalQuotesRange getQuotesArguments = new GetGlobalHistoricalQuotesRange();
getQuotesArguments.setIdentifier(symbol);
getQuotesArguments.setIdentifierType(IdentifierTypes.Symbol);
getQuotesArguments.setStartDate("8/1/2011");
getQuotesArguments.setEndDate("8/30/2011");
// Axis2 does not handle .NET's WSDL serialized of enums very much.
AdjustmentMethods adj = AdjustmentMethods.Factory.create();
AdjustmentMethods_type0[] adjInnerTypes = new AdjustmentMethods_type0[1];
adjInnerTypes[0] = AdjustmentMethods_type0.Factory.fromString(AdjustmentMethods_type0._SplitOnly, SERVICE_URI);
adj.setAdjustmentMethods_type0(adjInnerTypes);
getQuotesArguments.setAdjustmentMethod(adj);
// Call the service
GetGlobalHistoricalQuotesRangeResponse response =
this.getStub().GetGlobalHistoricalQuotesRange(getQuotesArguments, this.getHeader());
GlobalHistoricalQuotes r1 = response.getGetGlobalHistoricalQuotesRangeResult();
ArrayOfGlobalHistoricalQuote r2 = r1.getGlobalQuotes();
GlobalHistoricalQuote[] objQuote = r2.getGlobalHistoricalQuote();
// objQuote is pointing to the result of the operation
if (objQuote[0].getOutcome() == OutcomeTypes.RegistrationError)
{
// code to handle registration errors
System.out.println(OutcomeTypes.RegistrationError.toString() + ": " + objQuote[0].getMessage());
}
else if (objQuote[0].getOutcome() == OutcomeTypes.RequestError)
{
// code to handle request errors
System.out.println(OutcomeTypes.RequestError.toString() + ": " + objQuote[0].getMessage());
}
else if (objQuote[0].getOutcome() == OutcomeTypes.SystemError)
{
// code to handle system errors
System.out.println(OutcomeTypes.SystemError.toString() + ": " + objQuote[0].getMessage());
}
else // Success
{
for(int i = 0; i < objQuote.length; i++)
{
System.out.println(objQuote[i].getDate() + ": " + objQuote[i].getLast());
}
}
}
catch (Exception ex) {
// add exception handling code here
System.err.println("Error calling service: " + ex.getMessage());
}
}
public static void main(String[] args) throws Exception {
Axis2Test test = new Axis2Test();
String symbol = ReadInput();
while (symbol != null && symbol != "") {
test.retrieveQuotes(symbol);
symbol = ReadInput();
}
}
public static String ReadInput() {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter symbol to retrieve: ");
return scanner.nextLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment