Source Code Cross Referenced for PostSOAP.java in  » Net » Apache-common-HttpClient » examples » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » Apache common HttpClient » examples 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header$
003:         * $Revision: 480424 $
004:         * $Date: 2006-11-29 06:56:49 +0100 (Wed, 29 Nov 2006) $
005:         * ====================================================================
006:         *
007:         *  Licensed to the Apache Software Foundation (ASF) under one or more
008:         *  contributor license agreements.  See the NOTICE file distributed with
009:         *  this work for additional information regarding copyright ownership.
010:         *  The ASF licenses this file to You under the Apache License, Version 2.0
011:         *  (the "License"); you may not use this file except in compliance with
012:         *  the License.  You may obtain a copy of the License at
013:         *
014:         *      http://www.apache.org/licenses/LICENSE-2.0
015:         *
016:         *  Unless required by applicable law or agreed to in writing, software
017:         *  distributed under the License is distributed on an "AS IS" BASIS,
018:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019:         *  See the License for the specific language governing permissions and
020:         *  limitations under the License.
021:         * ====================================================================
022:         *
023:         * This software consists of voluntary contributions made by many
024:         * individuals on behalf of the Apache Software Foundation.  For more
025:         * information on the Apache Software Foundation, please see
026:         * <http://www.apache.org/>.
027:         */
028:
029:        import java.io.File;
030:
031:        import org.apache.commons.httpclient.HttpClient;
032:        import org.apache.commons.httpclient.methods.FileRequestEntity;
033:        import org.apache.commons.httpclient.methods.PostMethod;
034:        import org.apache.commons.httpclient.methods.RequestEntity;
035:
036:        /**
037:         *
038:         * This is a sample application that demonstrates
039:         * how to use the Jakarta HttpClient API.
040:         *
041:         * This application sends an XML document
042:         * to a remote web server using HTTP POST
043:         *
044:         * @author Sean C. Sullivan
045:         * @author Ortwin Glueck
046:         * @author Oleg Kalnichevski
047:         * @author Paul King
048:         */
049:        public class PostSOAP {
050:
051:            /**
052:             *
053:             * Usage:
054:             *          java PostSOAP http://mywebserver:80/ SOAPAction c:\foo.xml
055:             *
056:             *  @param args command line arguments
057:             *                 Argument 0 is a URL to a web server
058:             *                 Argument 1 is the SOAP Action
059:             *                 Argument 2 is a local filename
060:             *
061:             */
062:            public static void main(String[] args) throws Exception {
063:                if (args.length != 3) {
064:                    System.out
065:                            .println("Usage: java -classpath <classpath> [-Dorg.apache.commons.logging.simplelog.defaultlog=<loglevel>] PostSOAP <url> <soapaction> <filename>]");
066:                    System.out
067:                            .println("<classpath> - must contain the commons-httpclient.jar and commons-logging.jar");
068:                    System.out
069:                            .println("<loglevel> - one of error, warn, info, debug, trace");
070:                    System.out.println("<url> - the URL to post the file to");
071:                    System.out
072:                            .println("<soapaction> - the SOAP action header value");
073:                    System.out.println("<filename> - file to post to the URL");
074:                    System.out.println();
075:                    System.exit(1);
076:                }
077:                // Get target URL
078:                String strURL = args[0];
079:                // Get SOAP action
080:                String strSoapAction = args[1];
081:                // Get file to be posted
082:                String strXMLFilename = args[2];
083:                File input = new File(strXMLFilename);
084:                // Prepare HTTP post
085:                PostMethod post = new PostMethod(strURL);
086:                // Request content will be retrieved directly
087:                // from the input stream
088:                RequestEntity entity = new FileRequestEntity(input,
089:                        "text/xml; charset=ISO-8859-1");
090:                post.setRequestEntity(entity);
091:                // consult documentation for your web service
092:                post.setRequestHeader("SOAPAction", strSoapAction);
093:                // Get HTTP client
094:                HttpClient httpclient = new HttpClient();
095:                // Execute request
096:                try {
097:                    int result = httpclient.executeMethod(post);
098:                    // Display status code
099:                    System.out.println("Response status code: " + result);
100:                    // Display response
101:                    System.out.println("Response body: ");
102:                    System.out.println(post.getResponseBodyAsString());
103:                } finally {
104:                    // Release current connection to the connection pool once you are done
105:                    post.releaseConnection();
106:                }
107:            }
108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.