001: package com.mimer.ws.validateSQL;
002:
003: //If you don't already have Axis, go to xml.apache.org and download this excellent SOAP implementation
004: import org.apache.axis.AxisFault;
005: import org.apache.axis.client.Call;
006: import org.apache.axis.client.Service;
007: import org.apache.axis.encoding.XMLType;
008:
009: import javax.xml.rpc.ParameterMode;
010: import javax.xml.rpc.ServiceException;
011: import java.rmi.RemoteException;
012: import javax.xml.namespace.QName;
013: import java.net.URL;
014:
015: /**
016: *
017: * @author olle
018: */
019: public class ValidateSQL99Client {
020:
021: //This method makes the web service call
022: //If you want to you can create a web service proxy from the WSDL file,
023: //9 times out of 10, that's what you really want to do.
024: public ValidatorResult callSQL99Validator(URL a_url,
025: int a_sessionId, int a_sessionKey, String a_sqlStatement,
026: String a_resultType) throws RemoteException,
027: ServiceException {
028:
029: Service l_service = new Service();
030: Call l_call = (Call) l_service.createCall();
031:
032: //Set the target server and name space
033: l_call.setTargetEndpointAddress(a_url);
034: l_call.setOperationName(new QName("SQL99Validator",
035: "validateSQL"));
036:
037: //Add the parameter names and types
038: //Use the session Id you got from the openSession call here
039: l_call.addParameter("a_sessionId", XMLType.XSD_INT,
040: ParameterMode.IN);
041: //Use the session key you got from the openSession call here
042: l_call.addParameter("a_sessionKey", XMLType.XSD_INT,
043: ParameterMode.IN);
044: //The SQL statement to be validated against the standard
045: l_call.addParameter("a_sqlStatement", XMLType.XSD_STRING,
046: ParameterMode.IN);
047: //The format of the result. This must be "text" or "html".
048: //Hopefully some type of XML format will be available as well
049: l_call.addParameter("a_resultType", XMLType.XSD_STRING,
050: ParameterMode.IN);
051:
052: QName l_qn = new QName("http://sqlvalidator.mimer.com/v1.0",
053: "ValidatorResult");
054: // QName l_qn = new QName( "http://sqlvalidator.mimer.com/v1", "ValidatorResult" );
055:
056: l_call
057: .registerTypeMapping(
058: ValidatorResult.class,
059: l_qn,
060: new org.apache.axis.encoding.ser.BeanSerializerFactory(
061: ValidatorResult.class, l_qn),
062: new org.apache.axis.encoding.ser.BeanDeserializerFactory(
063: ValidatorResult.class, l_qn));
064:
065: //Set the return type
066: l_call.setReturnType(l_qn);
067:
068: Object l_ret = l_call.invoke(new Object[] {
069: Integer.valueOf(a_sessionId),
070: Integer.valueOf(a_sessionKey), a_sqlStatement,
071: a_resultType });
072:
073: return (ValidatorResult) l_ret;
074: }
075:
076: public SessionData openSession(URL a_url, String a_userName,
077: String a_password, String a_callingProgram,
078: String a_callingProgramVersion, String a_targetDbms,
079: String a_targetDbmsVersion, String a_connectionTechnology,
080: String a_connectionTechnologyVersion, int a_interactive)
081: throws RemoteException, ServiceException {
082:
083: Service l_service = new Service();
084: Call l_call = (Call) l_service.createCall();
085:
086: //Set the target server and name space
087: l_call.setTargetEndpointAddress(a_url);
088: l_call.setOperationName(new QName("SQL99Validator",
089: "openSession"));
090:
091: //Supply the user name. If you use anonymous you will be logged in and the pw will be ignored
092: l_call.addParameter("a_userName", XMLType.XSD_STRING,
093: ParameterMode.IN);
094: //The pw. If user name is anonymous this can be anything. But it has to be supplied anyway.
095: l_call.addParameter("a_password", XMLType.XSD_STRING,
096: ParameterMode.IN);
097: //The name of the calling client program.
098: //This is optional. If you don't want to give out this info, please enter "N/A"
099: l_call.addParameter("a_callingProgram", XMLType.XSD_STRING,
100: ParameterMode.IN);
101: //And the version of the calling program.
102: //This is optional. If you don't want to give out this info, please enter "N/A"
103: l_call.addParameter("a_callingProgramVersion",
104: XMLType.XSD_STRING, ParameterMode.IN);
105: //The target DBMS, could be Mimer SQL Engine, Oracle, ...
106: //This is optional. If you don't want to give out this info, please enter "N/A"
107: l_call.addParameter("a_targetDbms", XMLType.XSD_STRING,
108: ParameterMode.IN);
109: //The version of the target DBMS
110: //This is optional. If you don't want to give out this info, please enter "N/A"
111: l_call.addParameter("a_targetDbmsVersion", XMLType.XSD_STRING,
112: ParameterMode.IN);
113: //The connection Technology used, could be ODBC, JDBC, ADO
114: //This is optional. If you don't want to give out this info, please enter "N/A"
115: l_call.addParameter("a_connectionTechnology",
116: XMLType.XSD_STRING, ParameterMode.IN);
117: //Version
118: //This is optional. If you don't want to give out this info, please enter "N/A"
119: l_call.addParameter("a_connectionTechnologyVersion",
120: XMLType.XSD_STRING, ParameterMode.IN);
121: //Set this to 1 if your application is interactive where the user enters queries and then runs them
122: //Set it to 2 if it is non interactive, such as for instance a JDBC Bridge driver that intercepts SQL
123: l_call.addParameter("a_interactive", XMLType.XSD_INT,
124: ParameterMode.IN);
125:
126: QName l_qn = new QName("http://sqlvalidator.mimer.com/v1.0",
127: "SessionData");
128: // QName l_qn = new QName( "http://sqlvalidator.mimer.com/v1", "SessionData" );
129:
130: l_call
131: .registerTypeMapping(
132: SessionData.class,
133: l_qn,
134: new org.apache.axis.encoding.ser.BeanSerializerFactory(
135: SessionData.class, l_qn),
136: new org.apache.axis.encoding.ser.BeanDeserializerFactory(
137: SessionData.class, l_qn));
138:
139: //Set the return type
140: l_call.setReturnType(l_qn);
141:
142: Object l_ret = l_call.invoke(new Object[] { a_userName,
143: a_password, a_callingProgram, a_callingProgramVersion,
144: a_targetDbms, a_targetDbmsVersion,
145: a_connectionTechnology, a_connectionTechnologyVersion,
146: Integer.valueOf(a_interactive) });
147:
148: return (SessionData) l_ret;
149: }
150:
151: public static void main(String args[]) {
152: try {
153: //For testing on the local machine
154: //URL l_url = new URL("http://localhost:8081/services");
155:
156: //For testing on the live server
157: // URL l_url = new URL("http://sqlvalidator.mimer.com/beta2/services");
158: URL l_url = new URL(
159: "http://sqlvalidator.mimer.com/v1/services");
160:
161: //Create self and
162: ValidateSQL99Client l_valSql = new ValidateSQL99Client();
163:
164: SessionData l_sd = l_valSql.openSession(l_url, "anonymous",
165: "doesn't matter", "OlleClient", "8534",
166: "Mimer SQL Engine", "8.2.4g", "JDBC", "2.0", 2);
167:
168: int l_session = l_sd.getSessionId();
169: int l_key = l_sd.getSessionKey();
170:
171: //Set the url for subsequent calls
172: //This is to allow for load balancing to a server on the other side of the world
173: l_url = new URL(l_sd.getTarget());
174:
175: //make a few calls
176: System.out.println(l_valSql.callSQL99Validator(l_url,
177: l_session, l_key, "select * from tab1", "text"));
178: System.out.println(l_valSql.callSQL99Validator(l_url,
179: l_session, l_key, "insert", "text"));
180: System.out.println(l_valSql.callSQL99Validator(l_url,
181: l_session, l_key, "select", "html"));
182: System.out.println(l_valSql.callSQL99Validator(l_url,
183: l_session, l_key,
184: "select * from t1 where a like \"a\"", "html"));
185: System.out.println(l_valSql.callSQL99Validator(l_url,
186: l_session, l_key, "insert into t1 values (1,2,3)",
187: "text"));
188: System.out.println(l_valSql.callSQL99Validator(l_url,
189: l_session, l_key, "insert t1 values (1,2,3)",
190: "html"));
191: System.out.println(l_valSql.callSQL99Validator(l_url,
192: l_session, l_key, "delete from t1 where a > 1",
193: "text"));
194: System.out.println(l_valSql.callSQL99Validator(l_url,
195: l_session, l_key, "delete t1 where a < 1", "html"));
196: System.out.println(l_valSql.callSQL99Validator(l_url,
197: l_session, l_key,
198: "insert into t2 (a,b,c) values (1, 2, 3)", "text"));
199: System.out.println(l_valSql.callSQL99Validator(l_url,
200: l_session, l_key,
201: "insert ito t2 (a,b,c) values (1, 2, 3)", "html"));
202: } catch (Exception e) {
203: if (e instanceof AxisFault) {
204: System.err.println(((AxisFault) e).dumpToString());
205: } else
206: e.printStackTrace();
207: }
208: }
209: };
|