1 18 19 package cowsultants.itracker.web.test; 20 21 import java.io.*; 22 import java.util.*; 23 import java.net.*; 24 25 import org.apache.axis.*; 26 import org.apache.axis.attachments.*; 27 import org.apache.axis.client.*; 28 import org.apache.axis.encoding.*; 29 import org.apache.axis.utils.*; 30 31 import javax.activation.*; 32 import javax.xml.namespace.QName ; 33 import javax.xml.rpc.ParameterMode ; 34 35 import cowsultants.itracker.ejb.client.models.*; 36 import cowsultants.itracker.ejb.client.util.*; 37 38 public class TestIssueService { 39 40 public static void main(String [] args) throws Exception { 41 if(args == null || args.length != 3) { 42 System.out.println("Usage: java TestIssueService <wsurl> <userid> <password>"); 43 return; 44 } 45 46 try { 47 Service service = new Service(); 48 Call call = (Call) service.createCall(); 49 50 QName qnGeneric = new QName ("urn:itracker", "genericmodel"); 51 call.registerTypeMapping(GenericModel.class, qnGeneric, 52 new org.apache.axis.encoding.ser.BeanSerializerFactory(GenericModel.class, qnGeneric), 53 new org.apache.axis.encoding.ser.BeanDeserializerFactory(GenericModel.class, qnGeneric)); 54 55 QName qnIssue = new QName ("urn:itracker", "issue"); 56 call.registerTypeMapping(IssueModel.class, qnIssue, 57 new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueModel.class, qnIssue), 58 new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueModel.class, qnIssue)); 59 60 QName qnIssueField = new QName ("urn:itracker", "issuefield"); 61 call.registerTypeMapping(IssueFieldModel.class, qnIssueField, 62 new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueFieldModel.class, qnIssueField), 63 new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueFieldModel.class, qnIssueField)); 64 65 QName qnIssueHistory = new QName ("urn:itracker", "issuehistory"); 66 call.registerTypeMapping(IssueHistoryModel.class, qnIssueHistory, 67 new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueHistoryModel.class, qnIssueHistory), 68 new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueHistoryModel.class, qnIssueHistory)); 69 70 QName qnIssueAttachment = new QName ("urn:itracker", "issueattachment"); 71 call.registerTypeMapping(IssueAttachmentModel.class, qnIssueAttachment, 72 new org.apache.axis.encoding.ser.BeanSerializerFactory(IssueAttachmentModel.class, qnIssueAttachment), 73 new org.apache.axis.encoding.ser.BeanDeserializerFactory(IssueAttachmentModel.class, qnIssueAttachment)); 74 75 QName qnComponent = new QName ("urn:itracker", "component"); 76 call.registerTypeMapping(ComponentModel.class, qnComponent, 77 new org.apache.axis.encoding.ser.BeanSerializerFactory(ComponentModel.class, qnComponent), 78 new org.apache.axis.encoding.ser.BeanDeserializerFactory(ComponentModel.class, qnComponent)); 79 80 QName qnVersion = new QName ("urn:itracker", "version"); 81 call.registerTypeMapping(VersionModel.class, qnVersion, 82 new org.apache.axis.encoding.ser.BeanSerializerFactory(VersionModel.class, qnVersion), 83 new org.apache.axis.encoding.ser.BeanDeserializerFactory(VersionModel.class, qnVersion)); 84 85 QName qnNotification = new QName ("urn:itracker", "notification"); 86 call.registerTypeMapping(NotificationModel.class, qnNotification, 87 new org.apache.axis.encoding.ser.BeanSerializerFactory(NotificationModel.class, qnNotification), 88 new org.apache.axis.encoding.ser.BeanDeserializerFactory(NotificationModel.class, qnNotification)); 89 90 QName qnProject = new QName ("urn:itracker", "project"); 91 call.registerTypeMapping(ProjectModel.class, qnProject, 92 new org.apache.axis.encoding.ser.BeanSerializerFactory(ProjectModel.class, qnProject), 93 new org.apache.axis.encoding.ser.BeanDeserializerFactory(ProjectModel.class, qnProject)); 94 95 QName qnCustomField = new QName ("urn:itracker", "customfield"); 96 call.registerTypeMapping(CustomFieldModel.class, qnCustomField, 97 new org.apache.axis.encoding.ser.BeanSerializerFactory(CustomFieldModel.class, qnCustomField), 98 new org.apache.axis.encoding.ser.BeanDeserializerFactory(CustomFieldModel.class, qnCustomField)); 99 QName qnCustomFieldValue = new QName ("urn:itracker", "customfieldvalue"); 100 call.registerTypeMapping(CustomFieldValueModel.class, qnCustomFieldValue, 101 new org.apache.axis.encoding.ser.BeanSerializerFactory(CustomFieldValueModel.class, qnCustomFieldValue), 102 new org.apache.axis.encoding.ser.BeanDeserializerFactory(CustomFieldValueModel.class, qnCustomFieldValue)); 103 104 QName qnUser = new QName ("urn:itracker", "user"); 105 call.registerTypeMapping(UserModel.class, qnUser, 106 new org.apache.axis.encoding.ser.BeanSerializerFactory(UserModel.class, qnUser), 107 new org.apache.axis.encoding.ser.BeanDeserializerFactory(UserModel.class, qnUser)); 108 109 QName qnPermission = new QName ("urn:itracker", "permission"); 110 call.registerTypeMapping(PermissionModel.class, qnPermission, 111 new org.apache.axis.encoding.ser.BeanSerializerFactory(PermissionModel.class, qnPermission), 112 new org.apache.axis.encoding.ser.BeanDeserializerFactory(PermissionModel.class, qnPermission)); 113 114 QName qnPreferences = new QName ("urn:itracker", "preferences"); 115 call.registerTypeMapping(UserPreferencesModel.class, qnPreferences, 116 new org.apache.axis.encoding.ser.BeanSerializerFactory(UserPreferencesModel.class, qnPreferences), 117 new org.apache.axis.encoding.ser.BeanDeserializerFactory(UserPreferencesModel.class, qnPreferences)); 118 119 System.out.println("Setting service to " + args[0] + "/ITrackerIssueService"); 120 call.setTargetEndpointAddress(new java.net.URL (args[0] + "/ITrackerIssueService")); 121 call.setOperationName("getAllIssues"); 122 call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN ); 123 call.addParameter("authentication", XMLType.XSD_STRING, ParameterMode.IN ); 124 call.addParameter("authType", XMLType.XSD_INTEGER, ParameterMode.IN ); 125 call.setReturnType(XMLType.SOAP_ARRAY); 126 127 IssueModel[] values = (IssueModel[]) call.invoke( new Object [] { args[1], args[2], new Integer (AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) }); 128 129 if(values != null) { 130 for(int i = 0; i < values.length; i++) { 131 System.out.println("Issue " + values[i].getId() + ":"); 132 System.out.println(" Project: " + values[i].getProjectName()); 133 System.out.println(" Description: " + values[i].getDescription()); 134 System.out.println(" Severity: " + IssueUtilities.getSeverityName(values[i].getSeverity())); 135 System.out.println(" Status: " + IssueUtilities.getStatusName(values[i].getStatus())); 136 if(values[i].getStatus() >= IssueUtilities.STATUS_RESOLVED) { 137 System.out.println(" Resolution: " + values[i].getResolution()); 138 } 139 System.out.println(" Created: " + values[i].getCreateDate()); 140 System.out.println(" Last Modified: " + values[i].getLastModifiedDate()); 141 System.out.println(""); 142 } 143 if(values.length > 0) { 144 call.setOperationName("getIssue"); 145 call.removeAllParameters(); 146 call.addParameter("issueId", XMLType.XSD_INTEGER, ParameterMode.IN ); 147 call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN ); 148 call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN ); 149 call.addParameter("passwordEnc", XMLType.XSD_BOOLEAN, ParameterMode.IN ); 150 call.setReturnType(qnIssue); 151 152 IssueModel issue = (IssueModel) call.invoke( new Object [] { values[0].getId(), args[1], args[2], new Integer (AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) }); 153 System.out.println("\n"); 154 System.out.println("Issue " + issue.getId() + ":"); 155 System.out.println(" Project: " + issue.getProjectName()); 156 System.out.println(" Description: " + issue.getDescription()); 157 System.out.println(" Severity: " + IssueUtilities.getSeverityName(issue.getSeverity())); 158 System.out.println(" Status: " + IssueUtilities.getStatusName(issue.getStatus())); 159 if(values[0].getStatus() >= IssueUtilities.STATUS_RESOLVED) { 160 System.out.println(" Resolution: " + issue.getResolution()); 161 } 162 System.out.println(" Created: " + issue.getCreateDate()); 163 System.out.println(" Last Modified: " + issue.getLastModifiedDate()); 164 System.out.println(" Components: "); 165 for(int i = 0; i < issue.getComponents().length; i++) { 166 System.out.println(" " + issue.getComponents()[i].getName() + " [" + issue.getComponents()[i].getId() + "]"); 167 } 168 System.out.println(" Versions: "); 169 for(int i = 0; i < issue.getVersions().length; i++) { 170 System.out.println(" " + issue.getVersions()[i].getNumber() + " [" + issue.getVersions()[i].getId() + "]"); 171 } 172 System.out.println(" History: "); 173 for(int i = 0; i < issue.getHistory().length; i++) { 174 System.out.println(" " + i + ") " + issue.getHistory()[i].getDescription()); 175 } 176 } 177 } 178 179 call.setTargetEndpointAddress(new java.net.URL (args[0] + "/ITrackerProjectService")); 180 call.setOperationName("getAllProjects"); 181 call.removeAllParameters(); 182 call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN ); 183 call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN ); 184 call.addParameter("passwordEnc", XMLType.XSD_BOOLEAN, ParameterMode.IN ); 185 call.setReturnType(XMLType.SOAP_ARRAY); 186 187 188 System.out.println("\n\nTesting create issue..."); 189 ProjectModel[] projects = (ProjectModel[]) call.invoke( new Object [] { args[1], args[2], new Integer (AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) }); 190 if(projects != null && projects.length > 0) { 191 IssueModel newIssue = new IssueModel(); 192 newIssue.setProject(projects[0]); 193 newIssue.setStatus(IssueUtilities.STATUS_NEW); 194 newIssue.setSeverity(1); 195 newIssue.setDescription("New web services test issue."); 196 newIssue.setHistory(new IssueHistoryModel[] { new IssueHistoryModel("Test issue history entry.") }); 197 198 File fileAttachment = new File("C:\\Books.doc"); 199 String contentType = "UNKNOWN"; 200 try { 201 contentType = fileAttachment.toURL().openConnection().getContentType(); 202 } catch(Exception e) { 203 e.printStackTrace(); 204 } 205 newIssue.setAttachments(new IssueAttachmentModel[] { new IssueAttachmentModel("Books.doc", contentType, "Test word doc attachment", fileAttachment.length()) }); 206 207 call.setTargetEndpointAddress(new java.net.URL (args[0] + "/ITrackerIssueService")); 208 call.setOperationName("createIssue"); 209 call.removeAllParameters(); 210 AttachmentPart attachment = new AttachmentPart(new DataHandler(new FileDataSource("C:\\Books.doc"))); 211 attachment.setContentId("Books.doc"); 212 call.addAttachmentPart(attachment); 213 call.addParameter("issue", XMLType.XSD_QNAME, newIssue.getClass(), ParameterMode.IN ); 214 call.addParameter("login", XMLType.XSD_STRING, ParameterMode.IN ); 215 call.addParameter("password", XMLType.XSD_STRING, ParameterMode.IN ); 216 call.addParameter("passwordEnc", XMLType.XSD_BOOLEAN, ParameterMode.IN ); 217 call.setReturnType(qnIssue); 218 IssueModel createdIssue = (IssueModel) call.invoke( new Object [] { newIssue, args[1], args[2], new Integer (AuthenticationConstants.AUTH_TYPE_PASSWORD_PLAIN) }); 219 220 System.out.println("Created Issue " + createdIssue.getId() + ":"); 221 System.out.println(" Project: " + createdIssue.getProjectName()); 222 System.out.println(" Description: " + createdIssue.getDescription()); 223 System.out.println(" Severity: " + IssueUtilities.getSeverityName(createdIssue.getSeverity())); 224 System.out.println(" Status: " + IssueUtilities.getStatusName(createdIssue.getStatus())); 225 System.out.println(" Created: " + createdIssue.getCreateDate()); 226 System.out.println(" Last Modified: " + createdIssue.getLastModifiedDate()); 227 System.out.println(" Components: "); 228 for(int i = 0; i < createdIssue.getComponents().length; i++) { 229 System.out.println(" " + createdIssue.getComponents()[i].getName() + " [" + createdIssue.getComponents()[i].getId() + "]"); 230 } 231 System.out.println(" Versions: "); 232 for(int i = 0; i < createdIssue.getVersions().length; i++) { 233 System.out.println(" " + createdIssue.getVersions()[i].getNumber() + " [" + createdIssue.getVersions()[i].getId() + "]"); 234 } 235 System.out.println(" History: "); 236 for(int i = 0; i < createdIssue.getHistory().length; i++) { 237 System.out.println(" " + i + ") " + createdIssue.getHistory()[i].getDescription()); 238 } 239 } 240 241 } catch (AxisFault fault) { 242 System.out.println("Error : " + fault.toString()); 243 return; 244 } 245 } 246 } | Popular Tags |