List of usage examples for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST
int SC_BAD_REQUEST
To view the source code for org.apache.commons.httpclient HttpStatus SC_BAD_REQUEST.
Click Source Link
From source file:oscar.oscarEncounter.oscarMeasurements.hl7.MeasurementHL7UploaderAction.java
public ActionForward upload(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {/*from w w w . j a v a2s . c om*/ Date dateEntered = new Date(); String hl7msg = null; try { boolean checkPassword = StringUtils.isNotBlank(hl7UploadPassword); // file is encrypted using RSA public keys if no password enforced hl7msg = checkPassword ? IOUtils.toString(((LabUploadForm) form).getImportFile().getInputStream()) : extractEncryptedMessage((LabUploadForm) form, request); if (checkPassword && hl7UploadPassword.length() < 16) throw new RuntimeException( "Upload password length is too weak, please check oscar property file and make sure it's more than 16 letters."); Parser p = new GenericParser(); p.setValidationContext(new NoValidation()); ORU_R01 msg = (ORU_R01) p.parse(hl7msg); MSH msh = msg.getMSH(); String msgType = msh.getMessageType().getMessageType().getValue() + "_" + msh.getMessageType().getTriggerEvent().getValue(); if (!"ORU_R01".equals(msgType)) throw new RuntimeException("Message type is not ORU_R01 - " + msgType); if (checkPassword && !hl7UploadPassword.equals(msh.getSecurity().getValue())) throw new RuntimeException("Password in MSH is invalid."); String sender = msh.getSendingApplication().getNamespaceID().getValue(); String receiver = msh.getReceivingApplication().getNamespaceID().getValue(); String msgId = msh.getMessageControlID().getValue(); logger.info("HL7 message [" + msgId + "] received from: " + sender + " to: " + receiver + " on " + dateEntered); // TODO: handle multiple responses in one upload, right now only // assumes 1 per upload ORU_R01_RESPONSE resp = msg.getRESPONSE(); PID patient = resp.getPATIENT().getPID(); String hcn = patient.getPatientIDInternalID(0).getID().getValue(); String hcnType = patient.getPatientIDInternalID(0).getAssigningAuthority().getNamespaceID().getValue(); // get demographic no from hcn org.oscarehr.common.dao.DemographicDao demographicDao = (org.oscarehr.common.dao.DemographicDao) SpringUtils .getBean("demographicDao"); List<Demographic> demos = demographicDao.getActiveDemosByHealthCardNo(hcn, hcnType); if (demos == null || demos.size() == 0) throw new RuntimeException( "There is no active patient with the supplied health card number: " + hcn + " " + hcnType); // try to get consult doctor's providerID String providerNo = resp.getPATIENT().getVISIT().getPV1().getConsultingDoctor(0).getIDNumber() .getValue(); if (providerNo == null) providerNo = defaultProviderNo; // now handle OBR ORU_R01_ORDER_OBSERVATION obr = resp.getORDER_OBSERVATION(); CE univId = obr.getOBR().getUniversalServiceIdentifier(); // now get all observation data int len = obr.getOBSERVATIONReps(); for (int i = 0; i < len; i++) { logger.info("Processing OBX no." + i); OBX obx = obr.getOBSERVATION(i).getOBX(); Date dateObserved = sdf.parse(obx.getDateTimeOfTheObservation().getTimeOfAnEvent().getValue()); CE obvId = obx.getObservationIdentifier(); // the 1st part of obvId is the unique short name String measurementType = obvId.getIdentifier().getValue(); String unit = obx.getUnits().getIdentifier().getValue(); if (unit == null) // oscar does not allow unit to be null unit = ""; String range = obx.getReferencesRange().getValue(); if (range != null) unit += " Range:" + range; String data = obx.getObservationValue(0).getData().toString(); String abnormal = StringUtils.join(obx.getAbnormalFlags(), "|"); if (StringUtils.isNotEmpty(abnormal)) abnormal = " Abnormal:" + abnormal; logger.info( measurementType + " : " + data + " : " + unit + " : " + dateObserved + " : " + abnormal); // since oscar may have duplicate patient records, just add to // all of them. for (Demographic demo : demos) { Integer demographicNo = demo.getDemographicNo(); // add to oscar measurements table Measurements m = new Measurements(); m.setComments(abnormal + " by " + sender); m.setDataField(data); m.setDateEntered(dateEntered); m.setDateObserved(dateObserved); m.setDemographicNo(demographicNo); m.setMeasuringInstruction(unit); m.setProviderNo(providerNo); m.setType(measurementType); measurementsDao.addMeasurements(m); } } } catch (Exception e) { logger.error("Failed to parse HL7 ORU_R01 messages:\n" + hl7msg, e); response.setStatus(HttpStatus.SC_BAD_REQUEST); try { response.getWriter().println("Invalid HL7 ORU_R01 format/request: " + e.getMessage()); } catch (IOException e1) { // TODO Auto-generated catch blockMiscUtils.getLogger().error("Error", e1); } return null; } response.setStatus(HttpStatus.SC_OK); return null; }
From source file:pl.nask.hsn2.service.task.WebClientObjectTreeNode.java
private void processSingleResource(EmbeddedResource resource) { boolean requestFailed = resource.isRequestFailed(); if (!requestFailed) { String failureReason = resource.getFailureMessage(); String url = resource.getAbsoluteUrl(); WebResponse webResponse = null;/*from www . j a v a 2 s.c o m*/ try { Page page = webClientWorker.getInsecurePage(url); webResponse = page.getWebResponse(); int serverRespStatus = webResponse.getStatusCode(); int resourceRedirLimit = contextHeight(); while (resourceRedirLimit++ < params.getRedirectDepthLimit() && serverRespStatus >= HttpStatus.SC_MULTIPLE_CHOICES && serverRespStatus < HttpStatus.SC_BAD_REQUEST) { String redirect = webResponse.getResponseHeaderValue("Location"); String newUrl = UrlUtils.resolveUrl(url, redirect); LOGGER.debug("Resource '{}' redirected to: {}", url, newUrl); page = webClientWorker.getInsecurePage(newUrl); webResponse = page.getWebResponse(); serverRespStatus = webResponse.getStatusCode(); } // Status message can be used as a failure message. failureReason = webResponse.getStatusMessage(); } catch (ConnectTimeoutException e) { // Set proper message and log it. failureReason = getReasonAndLogWarn(e, "Connection timeout for URL: " + url); requestFailed = true; } catch (SocketTimeoutException e) { // Set proper message and log it. failureReason = getReasonAndLogWarn(e, "Socket timeout for URL: " + url); requestFailed = true; } catch (UnknownHostException e) { // Set proper message and log it. failureReason = getReasonAndLogWarn(e, "Unknown host for URL: url"); requestFailed = true; } catch (ClientProtocolException e) { // Set proper message and log it. failureReason = getReasonAndLogError(e, "Unsupported protocol. Probably not a resource: " + url); requestFailed = true; } catch (IOException e) { // Set proper message and log it. failureReason = getReasonAndLogError(e, "IOException for URL: " + url); requestFailed = true; } catch (Exception e) { // Set proper message and log it. failureReason = getReasonAndLogError(e, "Exception for URL: " + url); requestFailed = true; } finally { webClientWorker.closeAllWindows(); LOGGER.debug("Trying to close all windows for url: {}", url); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Updating resource:{},[{},{},{}]", new Object[] { resource.getAbsoluteUrl(), webResponse != null ? webResponse.getContentType() : "no response", failureReason, requestFailed }); } resource.update(webResponse, failureReason, requestFailed); } }
From source file:podd.tab.TabImporter.java
private PoddTabException createPoddTabException(PoddWebServiceException e) { boolean isUserError = false; switch (e.getStatus()) { case HttpStatus.SC_BAD_REQUEST: isUserError = true;//from ww w.j a v a2 s . c om } PoddTabException tabE = new PoddTabException(e, isUserError); return tabE; }
From source file:ru.org.linux.user.AddPhotoWebTest.java
@Test /**//from ww w . ja va 2 s .c o m * ? */ public void testInvalidImage() throws IOException { String auth = WebHelper.doLogin(resource, "JB", "passwd"); ClientResponse cr = WebHelper.addPhoto(resource, "src/test/resources/database.xml", auth); assertEquals(HttpStatus.SC_BAD_REQUEST, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); assertEquals("! Invalid image", doc.select(".error").text()); // ? }
From source file:ru.org.linux.user.AddPhotoWebTest.java
@Test /**/*from www . java 2 s . com*/ * ? */ public void testInvalid2Image() throws IOException { String auth = WebHelper.doLogin(resource, "JB", "passwd"); ClientResponse cr = WebHelper.addPhoto(resource, "src/main/webapp/img/tux.png", auth); assertEquals(HttpStatus.SC_BAD_REQUEST, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); assertEquals( "! ?: ? ", doc.select(".error").text()); // ? }
From source file:ru.org.linux.user.AddPhotoWebTest.java
@Test /**/*from w w w . j av a 2 s.c om*/ * ? */ public void testInvalid3Image() throws IOException { String auth = WebHelper.doLogin(resource, "JB", "passwd"); ClientResponse cr = WebHelper.addPhoto(resource, "src/main/webapp/img/twitter.png", auth); assertEquals(HttpStatus.SC_BAD_REQUEST, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); assertEquals( "! ?: ? ", doc.select(".error").text()); // ? }
From source file:ru.org.linux.user.AddPhotoWebTest.java
@Test /**//from ww w . j av a 2s .c o m * ? */ public void testInvalid4Image() throws IOException { String auth = WebHelper.doLogin(resource, "JB", "passwd"); ClientResponse cr = WebHelper.addPhoto(resource, "src/test/resources/images/animated.gif", auth); assertEquals(HttpStatus.SC_BAD_REQUEST, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); assertEquals( "! ?: ? ?", doc.select(".error").text()); // ? }
From source file:ru.org.linux.user.AddPhotoWebTest.java
@Test /**/* w w w . ja va 2 s . c o m*/ * ? ? apng * image source via http://tamalesyatole.deviantart.com/art/I-want-to-be-a-Hero-APNG-Animated-332248278 */ public void testAPNGImage() throws IOException { String auth = WebHelper.doLogin(resource, "JB", "passwd"); ClientResponse cr = WebHelper.addPhoto(resource, "src/test/resources/images/i_want_to_be_a_hero__apng_animated__by_tamalesyatole-d5ht8eu.png", auth); assertEquals(HttpStatus.SC_BAD_REQUEST, cr.getStatus()); Document doc = Jsoup.parse(cr.getEntityInputStream(), "UTF-8", resource.getURI().toString()); assertEquals( "! ?: ? ?", doc.select(".error").text()); // ? }