KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > http > HttpSoapWsTest


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.components.http;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22 import java.io.OutputStream JavaDoc;
23 import java.net.URL JavaDoc;
24 import java.net.URLConnection JavaDoc;
25
26 import javax.xml.namespace.QName JavaDoc;
27
28 import org.apache.servicemix.tck.TestSupport;
29 import org.springframework.context.support.AbstractXmlApplicationContext;
30 import org.w3c.dom.Node JavaDoc;
31 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
32
33 /**
34  * @version $Revision: 359186 $
35  */

36 public class HttpSoapWsTest extends TestSupport {
37
38     protected String JavaDoc quote = "SUNW";
39
40     public void testWithURLConnection() throws Exception JavaDoc {
41         URLConnection JavaDoc connection = new URL JavaDoc("http://localhost:8912").openConnection();
42         connection.setDoOutput(true);
43         connection.setDoInput(true);
44         OutputStream JavaDoc os = connection.getOutputStream();
45
46         // Post the request file.
47
InputStream JavaDoc fis = getClass().getResourceAsStream("soap-request.xml");
48         int c;
49         while ((c = fis.read()) >= 0) {
50             os.write(c);
51         }
52         os.flush();
53         os.close();
54         fis.close();
55
56         // Read the response.
57
BufferedReader JavaDoc in = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(connection.getInputStream()));
58         String JavaDoc inputLine;
59         while ((inputLine = in.readLine()) != null) {
60             System.out.println(inputLine);
61         }
62         in.close();
63     }
64
65     protected AbstractXmlApplicationContext createBeanFactory() {
66         return new ClassPathXmlApplicationContext("org/apache/servicemix/components/http/ws-example.xml");
67     }
68 }
69
Popular Tags