Java tutorial
/* * Copyright (c) 2006-2007 Massachusetts General Hospital * All rights reserved. This program and the accompanying materials * are made available under the terms of the i2b2 Software License v1.0 * which accompanies this distribution. * * Contributors: * Raj Kuttan * Lori Phillips */ package edu.harvard.i2b2.eclipse.plugins.fr.ws; import java.io.StringWriter; import javax.xml.bind.JAXBElement; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import edu.harvard.i2b2.common.util.jaxb.JAXBUnWrapHelper; import edu.harvard.i2b2.common.util.jaxb.JAXBUtilException; import edu.harvard.i2b2.crc.loader.datavo.loader.query.LoadType; import edu.harvard.i2b2.crc.loader.datavo.i2b2message.BodyType; import edu.harvard.i2b2.crc.loader.datavo.i2b2message.ResponseHeaderType; import edu.harvard.i2b2.crc.loader.datavo.i2b2message.ResponseMessageType; import edu.harvard.i2b2.crc.loader.datavo.i2b2message.StatusType; import edu.harvard.i2b2.fr.datavo.fr.query.SendfileResponseType; abstract public class FrResponseData { public static final String THIS_CLASS_NAME = FrResponseData.class.getName(); private Log log = LogFactory.getLog(THIS_CLASS_NAME); private ResponseMessageType respMessageType = null; public FrResponseData() { } public StatusType processResult(String response) { StatusType status = null; try { JAXBElement jaxbElement = FRJAXBUtil.getJAXBUtil().unMashallFromString(response); respMessageType = (ResponseMessageType) jaxbElement.getValue(); // Get response message status ResponseHeaderType responseHeader = respMessageType.getResponseHeader(); status = responseHeader.getResultStatus().getStatus(); String procStatus = status.getType(); String procMessage = status.getValue(); if (procStatus.equals("ERROR")) { log.error("Error reported by FR web Service " + procMessage); } else if (procStatus.equals("WARNING")) { log.error("Warning reported by FR web Service" + procMessage); } } catch (JAXBUtilException e) { log.error(e.getMessage()); } return status; } public SendfileResponseType doReadSendfile() { SendfileResponseType loads = null; try { BodyType bodyType = respMessageType.getMessageBody(); JAXBUnWrapHelper helper = new JAXBUnWrapHelper(); if (bodyType != null) loads = (SendfileResponseType) helper.getObjectByClass(bodyType.getAny(), SendfileResponseType.class); //loads = (LoadDataResponseType)helper.getObjectByClass(bodyType.getAny(), LoadType.class); } catch (JAXBUtilException e) { log.error(e.getMessage()); ; } return loads; } public String getXMLString(LoadType load) throws Exception { StringWriter strWriter = new StringWriter(); try { FRJAXBUtil.getJAXBUtil().marshaller(load, strWriter); } catch (JAXBUtilException e) { log.error("Error marshalling Ont concept"); throw new JAXBUtilException(e.getMessage(), e); } return strWriter.toString(); } }