From jboss-remoting-commits at lists.jboss.org Mon Aug 31 22:54:01 2009 Content-Type: multipart/mixed; boundary="===============1253660112873938387==" MIME-Version: 1.0 From: jboss-remoting-commits at lists.jboss.org To: jboss-remoting-commits at lists.jboss.org Subject: [jboss-remoting-commits] JBoss Remoting SVN: r5412 - remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/contenttype. Date: Mon, 31 Aug 2009 22:54:01 -0400 Message-ID: <200909010254.n812s1NZ028895@svn01.web.mwc.hst.phx2.redhat.com> --===============1253660112873938387== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: ron.sigal(a)jboss.com Date: 2009-08-31 22:54:00 -0400 (Mon, 31 Aug 2009) New Revision: 5412 Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http/= contenttype/ContentTypeTestCase.java Log: JBREM-1101: Added new test methods. Modified: remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transpor= t/http/contenttype/ContentTypeTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http= /contenttype/ContentTypeTestCase.java 2009-09-01 02:52:51 UTC (rev 5411) +++ remoting2/branches/2.x/src/tests/org/jboss/test/remoting/transport/http= /contenttype/ContentTypeTestCase.java 2009-09-01 02:54:00 UTC (rev 5412) @@ -28,6 +28,7 @@ import java.net.HttpURLConnection; import java.net.InetAddress; import java.net.URL; +import java.util.HashMap; import java.util.Map; = import javax.management.MBeanServer; @@ -42,15 +43,14 @@ import org.jboss.remoting.InvokerLocator; import org.jboss.remoting.ServerInvocationHandler; import org.jboss.remoting.ServerInvoker; -import org.jboss.remoting.callback.Callback; -import org.jboss.remoting.callback.HandleCallbackException; import org.jboss.remoting.callback.InvokerCallbackHandler; import org.jboss.remoting.transport.Connector; import org.jboss.remoting.transport.PortUtil; +import org.jboss.remoting.transport.web.WebUtil; = = /** - * Unit test for JBREM-653. + * Unit test for JBREM-653 and JBREM-1101. * = * @author Ron Sigal * @version $Revision$ @@ -64,13 +64,17 @@ = private static boolean firstTime =3D true; private static String CONTENT_TYPE =3D "test/testContentType"; + private static String INVALID_CONTENT_TYPE_CR =3D "test/x" + '\r' + "y"; + private static String INVALID_CONTENT_TYPE_LF =3D "test/x" + '\n' + "y"; private static String REQUEST =3D "testRequest"; private static String RESPONSE =3D "testResponse"; = - // remoting server connector - private Connector connector; - private InvokerLocator serverLocator; - private TestInvocationHandler invocationHandler; + protected String host; + protected int port; + protected String locatorURI; + protected InvokerLocator serverLocator; + protected Connector connector; + protected TestInvocationHandler invocationHandler; = = public void setUp() throws Exception @@ -101,16 +105,7 @@ log.info("entering " + getName()); = // Start server. - String host =3D InetAddress.getLocalHost().getHostAddress(); - int port =3D PortUtil.findFreePort(host); - String locatorURI =3D "http://" + host + ":" + port; = - serverLocator =3D new InvokerLocator(locatorURI); - log.info("Starting remoting server with locator uri of: " + locatorU= RI); - connector =3D new Connector(serverLocator); - connector.create(); - invocationHandler =3D new TestInvocationHandler(); - connector.addInvocationHandler("sample", invocationHandler); - connector.start(); + setupServer(CONTENT_TYPE); = // Send a message and receive a response using an HttpURLConnection. URL url =3D new URL(locatorURI); @@ -135,27 +130,129 @@ log.info(getName() + " PASSES"); } = + = + /** + * Verifies that content-type with CR supplied by ServerInvocationHandl= er is discarded. + */ + public void testInvalidContentTypeServerCR() throws Throwable + { + log.info("entering " + getName()); = + // Start server. + setupServer(INVALID_CONTENT_TYPE_CR); + + // Send a message and receive a response using an HttpURLConnection. + URL url =3D new URL(locatorURI); + HttpURLConnection conn =3D (HttpURLConnection) url.openConnection(); + conn.setDoOutput(true); + conn.setDoInput(true); + byte[] requestBytes =3D REQUEST.getBytes(); + OutputStream os =3D conn.getOutputStream(); + os.write(requestBytes); + String contentType =3D conn.getContentType(); + log.info("content-type: " + contentType); + InputStream is =3D conn.getInputStream(); + BufferedReader reader =3D new BufferedReader(new InputStreamReader(i= s)); + String response =3D reader.readLine(); + log.info("response: " + response); + + // Verify that content-type is the default value. + log.info("content-type: " + contentType); + assertEquals(WebUtil.HTML, contentType); + assertEquals(RESPONSE, response); + + connector.stop(); + log.info(getName() + " PASSES"); + } + + + /** + * Verifies that content-type with LF supplied by ServerInvocationHandl= er is discarded. + */ + public void testInvalidContentTypeServerLF() throws Throwable + { + log.info("entering " + getName()); + + // Start server. + setupServer(INVALID_CONTENT_TYPE_LF); + + // Send a message and receive a response using an HttpURLConnection. + URL url =3D new URL(locatorURI); + HttpURLConnection conn =3D (HttpURLConnection) url.openConnection(); + conn.setDoOutput(true); + conn.setDoInput(true); + byte[] requestBytes =3D REQUEST.getBytes(); + OutputStream os =3D conn.getOutputStream(); + os.write(requestBytes); + String contentType =3D conn.getContentType(); + log.info("content-type: " + contentType); + InputStream is =3D conn.getInputStream(); + BufferedReader reader =3D new BufferedReader(new InputStreamReader(i= s)); + String response =3D reader.readLine(); + log.info("response: " + response); + + // Verify that content-type is the default value. + log.info("content-type: " + contentType); + assertEquals(WebUtil.HTML, contentType); + assertEquals(RESPONSE, response); + + connector.stop(); + log.info(getName() + " PASSES"); + } + = + = + protected String getTransport() + { + return "http"; + } + = + = + protected void addExtraClientConfig(Map config) {} + protected void addExtraServerConfig(Map config) {} + = + = + protected void setupServer(String contentType) throws Exception + { + host =3D InetAddress.getLocalHost().getHostAddress(); + port =3D PortUtil.findFreePort(host); + locatorURI =3D getTransport() + "://" + host + ":" + port; + String metadata =3D System.getProperty("remoting.metadata"); + if (metadata !=3D null) + { + locatorURI +=3D "/?" + metadata; + } + serverLocator =3D new InvokerLocator(locatorURI); + log.info("Starting remoting server with locator uri of: " + locatorU= RI); + HashMap config =3D new HashMap(); + config.put(InvokerLocator.FORCE_REMOTE, "true"); + addExtraServerConfig(config); + connector =3D new Connector(serverLocator, config); + connector.create(); + invocationHandler =3D new TestInvocationHandler(contentType); + connector.addInvocationHandler("test", invocationHandler); + connector.start(); + } + = + = static class TestInvocationHandler implements ServerInvocationHandler { + String contentType; + public TestInvocationHandler(String contentType) + { + this.contentType =3D contentType; + } public void addListener(InvokerCallbackHandler callbackHandler) {} public Object invoke(final InvocationRequest invocation) throws Thro= wable { Map response =3D invocation.getReturnPayload(); - response.put("Content-Type", CONTENT_TYPE); + if (response !=3D null) + { + response.put("Content-Type", contentType); + } return RESPONSE; } public void removeListener(InvokerCallbackHandler callbackHandler) {} public void setMBeanServer(MBeanServer server) {} public void setInvoker(ServerInvoker invoker) {} } - = - = - static class TestCallbackHandler implements InvokerCallbackHandler - { - public void handleCallback(Callback callback) throws HandleCallbackE= xception - { - log.info("received callback"); - } = - } } \ No newline at end of file --===============1253660112873938387==--