KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > http > WsdlRoundtripTest


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.http;
18
19 import java.io.StringWriter JavaDoc;
20
21 import javax.servlet.http.HttpServletResponse JavaDoc;
22 import javax.wsdl.Binding;
23 import javax.wsdl.BindingOperation;
24 import javax.wsdl.Definition;
25 import javax.wsdl.extensions.ExtensibilityElement;
26 import javax.wsdl.extensions.soap.SOAPOperation;
27 import javax.wsdl.factory.WSDLFactory;
28 import javax.wsdl.xml.WSDLReader;
29
30 import org.apache.commons.httpclient.HttpClient;
31 import org.apache.commons.httpclient.methods.GetMethod;
32 import org.apache.servicemix.jbi.jaxp.SourceTransformer;
33 import org.apache.servicemix.jbi.jaxp.StringSource;
34 import org.apache.servicemix.tck.SpringTestSupport;
35 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
36 import org.springframework.context.support.AbstractXmlApplicationContext;
37 import org.w3c.dom.Document JavaDoc;
38
39 public class WsdlRoundtripTest extends SpringTestSupport {
40
41     protected AbstractXmlApplicationContext createBeanFactory() {
42         return new ClassPathXmlApplicationContext("org/apache/servicemix/http/wsdlroundtrip.xml");
43     }
44     
45     public void test() throws Exception JavaDoc {
46         GetMethod get = new GetMethod("http://localhost:8192/Service/?wsdl");
47         int state = new HttpClient().executeMethod(get);
48         assertEquals(HttpServletResponse.SC_OK, state);
49         Document JavaDoc doc = (Document JavaDoc) new SourceTransformer().toDOMNode(new StringSource(get.getResponseBodyAsString()));
50         
51         // Test WSDL
52
WSDLFactory factory = WSDLFactory.newInstance();
53         WSDLReader reader = factory.newWSDLReader();
54         Definition def;
55         def = reader.readWSDL("http://localhost:8192/Service/?wsdl", doc);
56
57         StringWriter JavaDoc writer = new StringWriter JavaDoc();
58         factory.newWSDLWriter().writeWSDL(def, writer);
59         System.err.println(writer.toString());
60         Binding b = (Binding) def.getBindings().values().iterator().next();
61         BindingOperation bop = (BindingOperation) b.getBindingOperations().iterator().next();
62         assertEquals(1, bop.getExtensibilityElements().size());
63         ExtensibilityElement ee = (ExtensibilityElement) bop.getExtensibilityElements().iterator().next();
64         assertTrue(ee instanceof SOAPOperation);
65         assertEquals("", ((SOAPOperation) ee).getSoapActionURI());
66     }
67
68 }
69
Popular Tags