test_class.declarator: logger = LoggerFactory.getLogger(SxmpSessionTest.class)
test_class.modifier: private static final
test_class.original_string: private static final Logger logger = LoggerFactory.getLogger(SxmpSessionTest.class);
test_class.type: Logger
test_class.var_name: logger
test_class.file: ch-sxmp/src/test/java/com/cloudhopper/sxmp/SxmpSessionTest.java
test_class.identifier: SxmpSessionTest
test_case.body: @Test
      public void processThrowsSxmpParsingExceptionWithNoOperationType() throws Exception {
          StringBuilder string0 = new StringBuilder(200)
              .append("<?xml version=\"1.0\"?>\n")
              .append("<operation2 type=\"submit\">\n")
              .append("</operation2>\n")
              .append("");
  
          ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes());
  
          MockSxmpRequestProcessor processor = new MockSxmpRequestProcessor();
          SxmpSession session = new SxmpSession(processor, SxmpParser.VERSION_1_0);
  
          Response response = null;
          try {
              response = session.process(is);
              Assert.fail();
          } catch (SAXException e) {
              // correct behavior
              //Assert.assertEquals(SxmpErrorCode.INVALID_XML, e.getErrorCode());
              Assert.assertThat(e.getMessage(), CoreMatchers.containsString("Root element must be an [operation]"));
              //Assert.assertNull(e.getOperation());
          }
      }
test_case.class_method_signature: SxmpSessionTest.processThrowsSxmpParsingExceptionWithNoOperationType()
test_case.full_signature: @Test public void processThrowsSxmpParsingExceptionWithNoOperationType()
test_case.identifier: processThrowsSxmpParsingExceptionWithNoOperationType
test_case.invocations: append append append append getBytes toString process fail assertThat getMessage containsString
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void processThrowsSxmpParsingExceptionWithNoOperationType()
focal_class.declarator: logger = LoggerFactory.getLogger(SxmpSession.class)
focal_class.modifier: private static final
focal_class.original_string: private static final Logger logger = LoggerFactory.getLogger(SxmpSession.class);
focal_class.type: Logger
focal_class.var_name: logger
focal_class.declarator: processor
focal_class.modifier: private final
focal_class.original_string: private final SxmpProcessor processor;
focal_class.type: SxmpProcessor
focal_class.var_name: processor
focal_class.declarator: version
focal_class.modifier: private final
focal_class.original_string: private final String version;
focal_class.type: String
focal_class.var_name: version
focal_class.file: ch-sxmp/src/main/java/com/cloudhopper/sxmp/SxmpSession.java
focal_class.identifier: SxmpSession
focal_class.class_method_signature: SxmpSession.SxmpSession(final SxmpProcessor processor, final String version)
focal_class.full_signature: public  SxmpSession(final SxmpProcessor processor, final String version)
focal_class.identifier: SxmpSession
focal_class.modifiers: public
focal_class.parameters: (final SxmpProcessor processor, final String version)
focal_class.signature:  SxmpSession(final SxmpProcessor processor, final String version)
focal_class.class_method_signature: SxmpSession.process(InputStream is)
focal_class.full_signature: public Response process(InputStream is)
focal_class.identifier: process
focal_class.modifiers: public
focal_class.parameters: (InputStream is)
focal_class.return: Response
focal_class.signature: Response process(InputStream is)
focal_method.body: public Response process(InputStream is) throws IOException, SAXException, ParserConfigurationException {
          // create a new XML parser
          SxmpParser parser = new SxmpParser(version);
  
          // an instance of an operation we'll be processing as a request
          Operation operation = null;
  
          try {
              // parse input stream into an operation (this may
              operation = parser.parse(is);
          } catch (SxmpParsingException e) {
              // major issue parsing the request into something valid -- this
              // exception may contain a partially parsed operation -- if it does
              // then we want to return valid XML back to the caller of this session
              // don't dump stack trace; instead just log error message and what of the operation we parsed
              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());
                  // we'll actually return a generic ErrorResponse back
                  return new ErrorResponse(e.getOperation().getType(), e.getErrorCode().getIntValue(), e.getErrorMessage());
              } else {
                  // otherwise, we should just return a generic error since nothing
                  // really was parsed in the XML document
                  throw new SAXException(e.getMessage(), e);
              }
          }
  
          // at this point, we'll catch any SxmpErrorExceptions and make sure they
          // are always converted into an ErrorResponse object, rather than
          // the exception ever being thrown
          try {
              // can only handle requests
              if (!(operation instanceof Request)) {
                  throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "A session can only process requests");
              }
  
              // convert to a request
              Request req = (Request)operation;
  
              // was an account included?
              if (req.getAccount() == null) {
                  throw new SxmpErrorException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "A request must include account credentials");
              }
  
              // authenticate the request
              if (!processor.authenticate(req.getAccount())) {
                  throw new SxmpErrorException(SxmpErrorCode.AUTHENTICATION_FAILURE, "Authentication failure");
              }
  
              // handle request type
              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 {
                  // if we got here, then a request we don't support occurred
                  throw new SxmpErrorException(SxmpErrorCode.UNSUPPORTED_OPERATION, "Unsupported operation request type");
              }
          } catch (SxmpErrorException e) {
              // because this is a mostly normal error in the course of processing a message
              // we don't want to print the full stacktrace -- we just want to print the message
              logger.warn(e.getMessage());
              // we'll actually return a generic ErrorResponse back
              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);
              // we'll actually return a generic ErrorResponse back
              return new ErrorResponse(operation.getType(), SxmpErrorCode.GENERIC.getIntValue(), "Generic error while processing request");
          }
      }
focal_method.class_method_signature: SxmpSession.process(InputStream is)
focal_method.full_signature: public Response process(InputStream is)
focal_method.identifier: process
focal_method.invocations: parse getOperation getType getOperation warn getMessage getOperation getType getOperation getIntValue getErrorCode getErrorMessage getMessage getAccount authenticate getAccount submit getAccount deliver getAccount deliveryReport getAccount warn getMessage getType getIntValue getErrorCode getErrorMessage error getType getIntValue
focal_method.modifiers: public
focal_method.parameters: (InputStream is)
focal_method.return: Response
focal_method.signature: Response process(InputStream is)