package test.encoding; import junit.framework.TestCase; import org.apache.axis.MessageContext; import org.apache.axis.encoding.DeserializationContext; import org.apache.axis.message.RPCElement; import org.apache.axis.message.RPCParam; import org.apache.axis.server.AxisServer; import org.xml.sax.InputSource; import javax.xml.soap.SOAPMessage; import javax.xml.soap.MessageFactory; import java.io.ByteArrayOutputStream; import java.io.ByteArrayInputStream; /** * line feed normalization and character reference processing */ public class TestString3 extends TestCase { public static final String myNS = "urn:myNS"; public TestString3(String name) { super(name); } static String xml1 = "" + "" + "" + ""; static String xml2 = "" + "" + "" + ""; private void runtest(String value, String expected) throws Exception { MessageContext msgContext = new MessageContext(new AxisServer()); String requestEncoding = "UTF-8"; msgContext.setProperty(SOAPMessage.CHARACTER_SET_ENCODING, requestEncoding); String xml = xml1 + value + xml2; ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes()); DeserializationContext dser = new DeserializationContext( new InputSource(bais), msgContext, org.apache.axis.Message.REQUEST); dser.parse(); org.apache.axis.message.SOAPEnvelope env = dser.getEnvelope(); RPCElement rpcElem = (RPCElement)env.getFirstBody(); RPCParam output = rpcElem.getParam("testParam"); assertNotNull("No param", output); String nodeValue = (String) output.getObjectValue(); assertNotNull("No node value for testParam param", nodeValue); assertEquals(expected, nodeValue); } public void testEntitizedCRLF() throws Exception { runtest(" Hello World ", "\r\nHello\r\nWorld\r\n"); } public void testPlainCRLF() throws Exception { runtest("\r\nHello\r\nWorld\r\n", "\nHello\nWorld\n"); } public void testEntitizedCR() throws Exception { runtest(" Hello World ", "\rHello\rWorld\r"); } public void testPlainCR() throws Exception { runtest("\rHello\rWorld\r", "\nHello\nWorld\n"); } }