@Test public void parseSubmitRequestWithXMLEncodedOptionalParamsV11() throws Exception { StringBuilder string0 = new StringBuilder(200) .append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") .append("<operation type=\"submit\">\n") .append(" <account username=\"customer1\" password=\"test1\"/>\n") .append(" <submitRequest referenceId=\"MYREF102020022\">\n") .append(" <operatorId>10</operatorId>\n") .append(" <destinationAddress type=\"push_destination\">abcd01234fghij</destinationAddress>\n") .append(" <text encoding=\"ISO-8859-1\">48656c6c6f20576f726c64</text>\n") .append(" <optionalParams>{\"A\":42,\"b\":\"&gt;\\r&lt;\\n&amp;\\\"'\"}</optionalParams>\n") .append(" </submitRequest>\n") .append("</operation>\n") .append(""); ByteArrayInputStream is = new ByteArrayInputStream(string0.toString().getBytes("UTF-8")); SxmpParser parser = new SxmpParser(SxmpParser.VERSION_1_1); Operation operation = parser.parse(is); logger.debug("{}", operation); Assert.assertEquals(Operation.Type.SUBMIT, operation.getType()); Assert.assertEquals(true, operation.isRequest()); SubmitRequest submitReq = (SubmitRequest)operation; Assert.assertEquals("customer1", submitReq.getAccount().getUsername()); Assert.assertEquals("test1", submitReq.getAccount().getPassword()); Assert.assertNull(submitReq.getApplication()); Assert.assertEquals("MYREF102020022", submitReq.getReferenceId()); Assert.assertEquals(new Integer(10), submitReq.getOperatorId()); Assert.assertEquals(new Boolean(false), submitReq.getDeliveryReport()); Assert.assertEquals(null, submitReq.getSourceAddress()); Assert.assertEquals(MobileAddress.Type.PUSH_DESTINATION, submitReq.getDestinationAddress().getType()); Assert.assertEquals("abcd01234fghij", submitReq.getDestinationAddress().getAddress()); Assert.assertEquals("Hello World", submitReq.getText()); Map<String, Object> opts = submitReq.getOptionalParams(); Assert.assertEquals(opts.get("A"), new Integer(42)); Assert.assertEquals(opts.get("b"), ">\r<\n&\"'"); }
public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } SxmpParser();  SxmpParser(final String version); }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } SxmpParser();  SxmpParser(final String version); Operation parse(InputStream in); }
SxmpParser { public Operation parse(InputStream in) throws SxmpParsingException, IOException, SAXException, ParserConfigurationException { SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParser parser = factory.newSAXParser(); parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: parser.getXMLReader().setFeature("http: Handler handler = new Handler(); XMLReader reader = parser.getXMLReader(); reader.setContentHandler(handler); reader.setErrorHandler(handler); reader.setEntityResolver(handler); try { parser.parse(new InputSource(in), handler); } catch (com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException e) { throw new SxmpParsingException(SxmpErrorCode.INVALID_XML, "XML encoding mismatch", null); } if (handler.error != null) { throw handler.error; } if (handler.getOperation() == null) { throw new SxmpParsingException(SxmpErrorCode.MISSING_REQUIRED_ELEMENT, "The operation type [" + handler.operationType.getValue() + "] requires a request element", new PartialOperation(handler.operationType)); } try { handler.getOperation().validate(); } catch (SxmpErrorException e) { throw new SxmpParsingException(e.getErrorCode(), e.getErrorMessage(), handler.getOperation()); } return handler.getOperation(); } SxmpParser();  SxmpParser(final String version); Operation parse(InputStream in); static final String VERSION_1_0; static final String VERSION_1_1; static final String VERSION_1_2; }