System.out.println("Process Upload Called");
try {
FacesContext facesContext=FacesContext.getCurrentInstance();
Application application = facesContext.getApplication();
ApplicationGlobalContext context = (ApplicationGlobalContext)application.createValueBinding("#{applicationGlobalContext}").getValue(facesContext);
System.out.println("File upload called");
InputStream in = new BufferedInputStream(uploadedFile.getInputStream());
BufferedReader input = new BufferedReader(new InputStreamReader(in));
StringBuffer sb = new StringBuffer();
try {
String line;
while ((line = input.readLine()) != null){
sb.append(line);
sb.append("\r\n");
}
} finally {
in.close();
}
System.out.println("File upload called for "+ documentType );
if(documentType.equals(ServiceConstants.SEARCH_HOST)){
HostUtils.createObject(context.getRegService(), sb.toString());
HostDescriptionType hostDesc = HostDescriptionDocument.Factory.parse(
sb.toString()).getHostDescription();
documentName = hostDesc.getHostName();
}else if(documentType.equals(ServiceConstants.SEARCH_APPLICATION)){
ApplicationUtils.createObject(context.getRegService(), sb.toString());
ApplicationDescriptionType appType = ApplicationDescriptionDocument.Factory.parse(sb.toString()).getApplicationDescription();
documentName = appType.getApplicationName().getStringValue();
}else if(documentType.equals(ServiceConstants.SEARCH_SERVICE)){
ServiceUtils.createObject(context.getRegService(), sb.toString());
ServiceMapType serviceMap = ServiceMapDocument.Factory.parse(sb.toString()).getServiceMap();
documentName = serviceMap.getService().getServiceName().getStringValue();
}else{
throw new Exception("Document type passed '" + documentType + "' is not valid");
}