Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/HttpXBeanDeployerTest.java Fri Apr 27 05:23:20 2007 @@ -31,6 +31,8 @@ import javax.wsdl.factory.WSDLFactory; import javax.xml.namespace.QName; +import org.w3c.dom.Document; + import junit.framework.TestCase; import org.apache.commons.logging.Log; @@ -41,14 +43,13 @@ import org.apache.servicemix.jbi.container.JBIContainer; import org.apache.servicemix.jbi.jaxp.SourceTransformer; import org.apache.servicemix.jbi.jaxp.StringSource; -import org.w3c.dom.Document; public class HttpXBeanDeployerTest extends TestCase { - private static Log logger = LogFactory.getLog(HttpXBeanDeployerTest.class); + private static Log logger = LogFactory.getLog(HttpXBeanDeployerTest.class); protected JBIContainer container; - + protected void setUp() throws Exception { container = new JBIContainer(); container.setUseMBeanServer(false); @@ -56,7 +57,7 @@ container.setEmbedded(true); container.init(); } - + protected void tearDown() throws Exception { if (container != null) { container.shutDown(); @@ -67,7 +68,7 @@ // HTTP Component HttpComponent component = new HttpComponent(); container.activateComponent(component, "HTTPComponent"); - + // Add a receiver component ActivationSpec asEcho = new ActivationSpec("echo", new EchoComponent() { public Document getServiceDescription(ServiceEndpoint endpoint) { @@ -101,7 +102,7 @@ asEcho.setEndpoint("myConsumer"); asEcho.setService(new QName("http://test", "MyConsumerService")); container.activateComponent(asEcho); - + // Start container container.start(); @@ -111,19 +112,19 @@ path = path.getParentFile(); component.getServiceUnitManager().deploy("xbean", path.getAbsolutePath()); component.getServiceUnitManager().start("xbean"); - + // Test wsdls assertNotNull(container.getRegistry().getEndpointDescriptor( - container.getRegistry().getEndpoint( - new QName("http://test", "MyProviderService"), "myProvider"))); + container.getRegistry() + .getEndpoint(new QName("http://test", "MyProviderService"), "myProvider"))); assertNotNull(container.getRegistry().getEndpointDescriptor( - container.getRegistry().getExternalEndpointsForService( - new QName("http://test", "MyConsumerService"))[0])); + container.getRegistry().getExternalEndpointsForService( + new QName("http://test", "MyConsumerService"))[0])); assertNotNull(container.getRegistry().getEndpointDescriptor( - container.getRegistry().getExternalEndpointsForService( - new QName("http://test", "MySoapService"))[0])); - - // Test + container.getRegistry().getExternalEndpointsForService( + new QName("http://test", "MySoapService"))[0])); + + // Test DefaultServiceMixClient client = new DefaultServiceMixClient(container); InOut me = client.createInOutExchange(); me.setService(new QName("http://test", "MyProviderService")); @@ -142,5 +143,5 @@ } client.done(me); } - + }
Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/ServerManagerTest.java Fri Apr 27 05:23:20 2007 @@ -16,12 +16,6 @@ */ package org.apache.servicemix.http; -import java.io.ByteArrayOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; - import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -34,14 +28,13 @@ import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.servicemix.components.http.InvalidStatusResponseException; import org.apache.servicemix.http.jetty.JettyContextManager; -import org.apache.servicemix.jbi.util.FileUtil; import org.mortbay.thread.BoundedThreadPool; public class ServerManagerTest extends TestCase { protected JettyContextManager server; protected HttpConfiguration configuration; - + protected void setUp() throws Exception { System.setProperty("DEBUG", "true"); System.setProperty("java.protocol.handler.pkgs", "HTTPClient"); @@ -49,22 +42,22 @@ server = new JettyContextManager(); server.setConfiguration(configuration); } - + protected void tearDown() throws Exception { server.shutDown(); } - + public void test() throws Exception { server.init(); server.start(); - - // Test first context + + // Test first context checkFail("http://localhost:8192/Service1/echo", null); Object ctx1 = server.createContext("http://localhost:8192/Service1", new TestHttpProcessor()); request("http://localhost:8192/Service1/echo", null); server.remove(ctx1); checkFail("http://localhost:8192/Service1/echo", null); - + // Test second context on the same host/port checkFail("http://localhost:8192/Service2/echo", null); Object ctx2 = server.createContext("http://localhost:8192/Service2", new TestHttpProcessor()); @@ -79,29 +72,29 @@ server.remove(ctx3); checkFail("http://localhost:8193/echo", null); } - + public void testOverlappingPath() throws Exception { server.init(); server.start(); - + server.createContext("http://localhost:8192/Service1/test1", new TestHttpProcessor()); - + server.createContext("http://localhost:8192/Service1/test1ex", new TestHttpProcessor()); - + try { server.createContext("http://localhost:8192/Service1/test1", new TestHttpProcessor()); fail("Contexts are overlapping, an exception should have been thrown"); } catch (Exception e) { // ok } - + try { server.createContext("http://localhost:8192/Service1/test1/test", new TestHttpProcessor()); fail("Contexts are overlapping, an exception should have been thrown"); } catch (Exception e) { // ok } - + try { server.createContext("http://localhost:8192/Service1", new TestHttpProcessor()); fail("Contexts are overlapping, an exception should have been thrown"); @@ -109,7 +102,7 @@ // ok } } - + public void testSetMaxThreads() throws Exception { int maxThreads = 512; configuration.setJettyThreadPoolSize(maxThreads); @@ -118,24 +111,20 @@ int threads = ((BoundedThreadPool) server.getThreadPool()).getMaxThreads(); assertEquals("The max number of threads is incorrect!", maxThreads, threads); } - + protected void checkFail(String url, String content) { try { request(url, content); fail("Request should have failed: " + url); } catch (Exception e) { - //System.out.println(e); + // System.out.println(e); } } - + protected String request(String url, String content) throws Exception { - if (true) { - return requestWithHttpClient(url, content); - } else { - return requestWithUrlConnection(url, content); - } + return requestWithHttpClient(url, content); } - + private String requestWithHttpClient(String url, String content) throws Exception { HttpMethod method; if (content != null) { @@ -152,36 +141,19 @@ } return method.getResponseBodyAsString(); } - - private String requestWithUrlConnection(String url, String content) throws Exception { - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); - try { - connection.setDoInput(true); - if (content != null) { - connection.setDoOutput(true); - OutputStream os = connection.getOutputStream(); - os.write(content.getBytes()); - os.close(); - } - InputStream is = connection.getInputStream(); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - FileUtil.copyInputStream(is, baos); - return baos.toString(); - } finally { - connection.disconnect(); - } - } public static class TestHttpProcessor implements HttpProcessor { public SslParameters getSsl() { return null; } + public String getAuthMethod() { return null; } + public void process(HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println(request); } - + } } Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/WsdlRoundtripTest.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/WsdlRoundtripTest.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/WsdlRoundtripTest.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/WsdlRoundtripTest.java Fri Apr 27 05:23:20 2007 @@ -27,6 +27,8 @@ import javax.wsdl.factory.WSDLFactory; import javax.wsdl.xml.WSDLReader; +import org.w3c.dom.Document; + import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.servicemix.jbi.jaxp.SourceTransformer; @@ -34,20 +36,19 @@ import org.apache.servicemix.tck.SpringTestSupport; import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.springframework.context.support.AbstractXmlApplicationContext; -import org.w3c.dom.Document; public class WsdlRoundtripTest extends SpringTestSupport { protected AbstractXmlApplicationContext createBeanFactory() { return new ClassPathXmlApplicationContext("org/apache/servicemix/http/wsdlroundtrip.xml"); } - + public void test() throws Exception { GetMethod get = new GetMethod("http://localhost:8192/Service/?wsdl"); int state = new HttpClient().executeMethod(get); assertEquals(HttpServletResponse.SC_OK, state); Document doc = (Document) new SourceTransformer().toDOMNode(new StringSource(get.getResponseBodyAsString())); - + // Test WSDL WSDLFactory factory = WSDLFactory.newInstance(); WSDLReader reader = factory.newWSDLReader(); Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/Person.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/Person.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/Person.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/Person.java Fri Apr 27 05:23:20 2007 @@ -1,18 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.servicemix.http.endpoints; public interface Person { - String getGivenName(); - - void setGivenName(String givenName); - - String getSurName(); - - void setSurName(String surName); - - int getAge(); - - void setAge(int age); - - String toString(); + String getGivenName(); + + void setGivenName(String givenName); + + String getSurName(); + + void setSurName(String surName); + + int getAge(); + + void setAge(int age); + + String toString(); } Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/PersonImpl.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/PersonImpl.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/PersonImpl.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/PersonImpl.java Fri Apr 27 05:23:20 2007 @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.servicemix.http.endpoints; import java.io.Serializable; @@ -8,48 +24,48 @@ import com.thoughtworks.xstream.io.xml.DomDriver; public class PersonImpl implements Person, Serializable { - - protected String givenName; - protected String surName; - protected int age; - - public PersonImpl(String givenName, String surName, int age) { - this.givenName = givenName; - this.surName = surName; - this.age = age; - } - - public String getGivenName() { - return givenName; - } - - public String getSurName() { - return surName; - } - - public void setGivenName(String givenName) { - this.givenName = givenName; - } - - public void setSurName(String surName) { - this.surName = surName; - } - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String toString() { - Writer w = new StringWriter(); - XStream xstream = new XStream(new DomDriver()); - xstream.alias("person", PersonImpl.class); - xstream.aliasField("given-name", PersonImpl.class, "givenName"); - xstream.aliasField("sur-name", PersonImpl.class, "surName"); - xstream.toXML(this, w); - return w.toString(); - } + + protected String givenName; + protected String surName; + protected int age; + + public PersonImpl(String givenName, String surName, int age) { + this.givenName = givenName; + this.surName = surName; + this.age = age; + } + + public String getGivenName() { + return givenName; + } + + public String getSurName() { + return surName; + } + + public void setGivenName(String givenName) { + this.givenName = givenName; + } + + public void setSurName(String surName) { + this.surName = surName; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String toString() { + Writer w = new StringWriter(); + XStream xstream = new XStream(new DomDriver()); + xstream.alias("person", PersonImpl.class); + xstream.aliasField("given-name", PersonImpl.class, "givenName"); + xstream.aliasField("sur-name", PersonImpl.class, "surName"); + xstream.toXML(this, w); + return w.toString(); + } } Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/endpoints/SerializedMarshalerTest.java Fri Apr 27 05:23:20 2007 @@ -24,6 +24,9 @@ import junit.framework.TestCase; +import com.thoughtworks.xstream.XStream; +import com.thoughtworks.xstream.io.xml.DomDriver; + import org.apache.servicemix.components.util.TransformComponentSupport; import org.apache.servicemix.http.HttpComponent; import org.apache.servicemix.http.HttpEndpointType; @@ -38,8 +41,6 @@ import org.springframework.remoting.support.RemoteInvocation; import org.springframework.remoting.support.RemoteInvocationResult; -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomDriver; public class SerializedMarshalerTest extends TestCase { @@ -63,26 +64,27 @@ public void testUsingSpringHttpRemoting() throws Exception { final Person person = new PersonImpl("Hunter", "Thompson", 67); - // Create a consumer endpoint + // Create a consumer endpoint HttpConsumerEndpoint ep = new HttpConsumerEndpoint(); ep.setService(new QName("urn:HttpConsumer", "HttpConsumer")); ep.setEndpoint("HttpConsumer"); ep.setLocationURI("http://localhost:8192/service/"); ep.setTargetService(new QName("urn:HttpInvoker", "Endpoint")); - // Configure the SerializedMarshaler and specifiy it on the endpoint + // Configure the SerializedMarshaler and specifiy it on the endpoint SerializedMarshaler marshaler = new SerializedMarshaler(); marshaler.setDefaultMep(MessageExchangeSupport.IN_OUT); ep.setMarshaler(marshaler); // Add the endpoint to the component and activate it HttpComponent component = new HttpComponent(); - component.setEndpoints(new HttpEndpointType[] { ep }); + component.setEndpoints(new HttpEndpointType[] {ep}); container.activateComponent(component, "HttpConsumer"); // Dummy up a component as a receiver and route it to urn:HttpInvoker/Endpoint TransformComponentSupport rmiComponent = new TransformComponentSupport() { - protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) throws MessagingException { + protected boolean transform(MessageExchange exchange, NormalizedMessage in, NormalizedMessage out) + throws MessagingException { try { // Deserialize rmi invocation XStream xstream = new XStream(new DomDriver()); @@ -90,13 +92,13 @@ Object rmi = xstream.fromXML(st.toString(in.getContent())); DefaultRemoteInvocationExecutor executor = new DefaultRemoteInvocationExecutor(); - Object result = executor.invoke((RemoteInvocation)rmi, person); + Object result = executor.invoke((RemoteInvocation) rmi, person); // Convert result to an rmi invocation RemoteInvocationResult rmiResult = new RemoteInvocationResult(result); out.setContent(new StringSource(xstream.toXML(rmiResult))); } catch (Exception e) { - throw new MessagingException (e); + throw new MessagingException(e); } return true; @@ -105,7 +107,7 @@ ActivationSpec asReceiver = new ActivationSpec("rmiComponent", rmiComponent); asReceiver.setService(new QName("urn:HttpInvoker", "Endpoint")); container.activateComponent(asReceiver); - + // Start the JBI container container.start(); @@ -116,8 +118,8 @@ pfb.setHttpInvokerRequestExecutor(new SimpleHttpInvokerRequestExecutor()); pfb.afterPropertiesSet(); - // Grab the object via the proxy factory bean - Person test = (Person)pfb.getObject(); + // Grab the object via the proxy factory bean + Person test = (Person) pfb.getObject(); // Test getters assertEquals("Hunter", test.getGivenName()); Modified: incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java?view=diff&rev=533074&r1=533073&r2=533074 ============================================================================== --- incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java (original) +++ incubator/servicemix/trunk/deployables/bindingcomponents/servicemix-http/src/test/java/org/apache/servicemix/http/security/HttpSecurityTest.java Fri Apr 27 05:23:20 2007 @@ -22,6 +22,8 @@ import javax.servlet.http.HttpServletResponse; +import org.w3c.dom.Element; + import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.UsernamePasswordCredentials; import org.apache.commons.httpclient.auth.AuthScope; @@ -35,10 +37,9 @@ import org.apache.servicemix.tck.SpringTestSupport; import org.apache.xbean.spring.context.ClassPathXmlApplicationContext; import org.springframework.context.support.AbstractXmlApplicationContext; -import org.w3c.dom.Element; public class HttpSecurityTest extends SpringTestSupport { - private static Log logger = LogFactory.getLog(HttpSecurityTest.class); + private static final Log LOGGER = LogFactory.getLog(HttpSecurityTest.class); static { String path = System.getProperty("java.security.auth.login.config"); @@ -49,7 +50,7 @@ System.setProperty("java.security.auth.login.config", path); } } - logger.info("Path to login config: " + path); + LOGGER.info("Path to login config: " + path); } protected void setUp() throws Exception { @@ -85,9 +86,8 @@ protected void testAuthenticate(final String username, final String password) throws Exception { HttpClient client = new HttpClient(); client.getState().setCredentials( - new AuthScope(AuthScope.ANY), - new UsernamePasswordCredentials(username, password) - ); + new AuthScope(AuthScope.ANY), + new UsernamePasswordCredentials(username, password)); PostMethod method = new PostMethod("http://localhost:8192/Service/"); try { @@ -133,7 +133,7 @@ method.setRequestEntity(new StringRequestEntity(request)); int state = client.executeMethod(method); String str = method.getResponseBodyAsString(); - logger.info(str); + LOGGER.info(str); assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state); Element e = new SourceTransformer().toDOMElement(new StringSource(str)); assertEquals("Envelope", e.getLocalName()); @@ -157,7 +157,7 @@ method.setRequestEntity(new StringRequestEntity(request)); int state = client.executeMethod(method); String str = method.getResponseBodyAsString(); - logger.info(str); + LOGGER.info(str); assertEquals(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, state); Element e = new SourceTransformer().toDOMElement(new StringSource(str)); assertEquals("Envelope", e.getLocalName());
