@Test public void processResponseThrowsUnsupportedOperation() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\"?>\n") .append("<operation type=\"submit\">\n") .append(" <submitResponse>\n") .append(" <error code=\"0\" message=\"OK\"/>\n") .append(" <ticketId>000:20090118002220948:000</ticketId>\n") .append(" </submitResponse>\n") .append("</operation>\n") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes()); MockSxmpRequestProcessor processor = new MockSxmpRequestProcessor(); SxmpSession session = new SxmpSession(processor, SxmpParser.VERSION_1_0); ErrorResponse response = (ErrorResponse)session.process(is); Assert.assertEquals(Operation.Type.SUBMIT, response.getType()); Assert.assertEquals(SxmpErrorCode.UNSUPPORTED_OPERATION.getIntValue(), response.getErrorCode().intValue()); }
public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException { SxmpParser parser = new SxmpParser(version); Operation operation = null; try { operation = parser.parse(is); } catch (SxmpParsingException e) { if (e.getOperation() != null && e.getOperation().getType() != null) { logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation()); return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } else { throw new SAXException(e.getMessage(), e); } } try { if (!(operation instanceof Request)) { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests"); } Request req = (Request)operation; if (req.getAccount() == null) { throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials"); } if (!processor.authenticate(req.getAccount())) { throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure"); } if (operation instanceof SubmitRequest) { return processor.submit(req.getAccount(), (SubmitRequest)operation); } else if (operation instanceof DeliverRequest) { return processor.deliver(req.getAccount(), (DeliverRequest)operation); } else if (operation instanceof DeliveryReportRequest) { return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation); } else { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type"); } } catch (SxmpErrorException e) { logger.warn(e.getMessage()); return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } catch (Throwable t) { logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t); return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request"); } }
SxmpSession { public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException { SxmpParser parser = new SxmpParser(version); Operation operation = null; try { operation = parser.parse(is); } catch (SxmpParsingException e) { if (e.getOperation() != null && e.getOperation().getType() != null) { logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation()); return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } else { throw new SAXException(e.getMessage(), e); } } try { if (!(operation instanceof Request)) { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests"); } Request req = (Request)operation; if (req.getAccount() == null) { throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials"); } if (!processor.authenticate(req.getAccount())) { throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure"); } if (operation instanceof SubmitRequest) { return processor.submit(req.getAccount(), (SubmitRequest)operation); } else if (operation instanceof DeliverRequest) { return processor.deliver(req.getAccount(), (DeliverRequest)operation); } else if (operation instanceof DeliveryReportRequest) { return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation); } else { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type"); } } catch (SxmpErrorException e) { logger.warn(e.getMessage()); return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } catch (Throwable t) { logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t); return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request"); } } }
SxmpSession { public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException { SxmpParser parser = new SxmpParser(version); Operation operation = null; try { operation = parser.parse(is); } catch (SxmpParsingException e) { if (e.getOperation() != null && e.getOperation().getType() != null) { logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation()); return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } else { throw new SAXException(e.getMessage(), e); } } try { if (!(operation instanceof Request)) { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests"); } Request req = (Request)operation; if (req.getAccount() == null) { throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials"); } if (!processor.authenticate(req.getAccount())) { throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure"); } if (operation instanceof SubmitRequest) { return processor.submit(req.getAccount(), (SubmitRequest)operation); } else if (operation instanceof DeliverRequest) { return processor.deliver(req.getAccount(), (DeliverRequest)operation); } else if (operation instanceof DeliveryReportRequest) { return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation); } else { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type"); } } catch (SxmpErrorException e) { logger.warn(e.getMessage()); return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } catch (Throwable t) { logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t); return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request"); } } SxmpSession(final SxmpProcessor processor, final String version); }
SxmpSession { public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException { SxmpParser parser = new SxmpParser(version); Operation operation = null; try { operation = parser.parse(is); } catch (SxmpParsingException e) { if (e.getOperation() != null && e.getOperation().getType() != null) { logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation()); return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } else { throw new SAXException(e.getMessage(), e); } } try { if (!(operation instanceof Request)) { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests"); } Request req = (Request)operation; if (req.getAccount() == null) { throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials"); } if (!processor.authenticate(req.getAccount())) { throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure"); } if (operation instanceof SubmitRequest) { return processor.submit(req.getAccount(), (SubmitRequest)operation); } else if (operation instanceof DeliverRequest) { return processor.deliver(req.getAccount(), (DeliverRequest)operation); } else if (operation instanceof DeliveryReportRequest) { return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation); } else { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type"); } } catch (SxmpErrorException e) { logger.warn(e.getMessage()); return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } catch (Throwable t) { logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t); return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request"); } } SxmpSession(final SxmpProcessor processor, final String version); Response process(InputStream is); }
SxmpSession { public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException { SxmpParser parser = new SxmpParser(version); Operation operation = null; try { operation = parser.parse(is); } catch (SxmpParsingException e) { if (e.getOperation() != null && e.getOperation().getType() != null) { logger.warn("Unable to fully parse XML into a request, returning ErrorResponse; error: "+e.getMessage()+", parsed: "+e.getOperation()); return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } else { throw new SAXException(e.getMessage(), e); } } try { if (!(operation instanceof Request)) { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests"); } Request req = (Request)operation; if (req.getAccount() == null) { throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials"); } if (!processor.authenticate(req.getAccount())) { throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure"); } if (operation instanceof SubmitRequest) { return processor.submit(req.getAccount(), (SubmitRequest)operation); } else if (operation instanceof DeliverRequest) { return processor.deliver(req.getAccount(), (DeliverRequest)operation); } else if (operation instanceof DeliveryReportRequest) { return processor.deliveryReport(req.getAccount(), (DeliveryReportRequest)operation); } else { throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type"); } } catch (SxmpErrorException e) { logger.warn(e.getMessage()); return new ErrorResponse(operation.getType(), e.getErrorCode().getIntValue(), e.getErrorMessage()); } catch (Throwable t) { logger.error("Major uncaught throwable while processing request, generating an ErrorResponse", t); return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request"); } } SxmpSession(final SxmpProcessor processor, final String version); Response process(InputStream is);  }