/**
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations under
* the License.
*
* The Original Code is OpenELIS code.
*
* Copyright (C) CIRG, University of Washington, Seattle WA. All Rights Reserved.
*
*/
package us.mn.state.health.lims.dataexchange.connectionTest;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import us.mn.state.health.lims.common.util.StringUtil;
import us.mn.state.health.lims.dataexchange.common.ITransmissionResponseHandler;
import us.mn.state.health.lims.dataexchange.common.ReportTransmission;
import us.mn.state.health.lims.dataexchange.common.ReportTransmission.HTTP_TYPE;
public class ConnectionTest {
public String testURL( String url) {
boolean sendAsychronously = false;
TestFailHandler responseHandler = new TestFailHandler();
new ReportTransmission().sendRawReport(null, url, sendAsychronously, responseHandler, HTTP_TYPE.GET);
return responseHandler.getResponse();
}
public class TestFailHandler implements ITransmissionResponseHandler {
private String response;
@Override
public void handleResponse(int httpReturnStatus, List<String> errors, String msg) {
if (httpReturnStatus == HttpServletResponse.SC_OK) {
response = StringUtil.getMessageForKey("http.success");
} else {
if( !errors.isEmpty()){
response = errors.get(0);
}
}
}
public String getResponse(){
return response;
}
}
}