hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r180108 - in /jakarta/httpclient/trunk/http-common/src/contrib: ./ org/ org/apache/ org/apache/http/ org/apache/http/contrib/ org/apache/http/contrib/spring/ org/apache/http/contrib/spring/SpringHttpDemo.java org/apache/http/contrib/spring/http-beans.xml
Date Sun, 05 Jun 2005 16:53:39 GMT
Author: olegk
Date: Sun Jun  5 09:53:38 2005
New Revision: 180108

URL: http://svn.apache.org/viewcvs?rev=180108&view=rev
Log:
Spring beans descriptor for HttpCommon components

Added:
    jakarta/httpclient/trunk/http-common/src/contrib/
    jakarta/httpclient/trunk/http-common/src/contrib/org/
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
  (with props)
    jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
  (with props)

Added: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java?rev=180108&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
(added)
+++ jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
Sun Jun  5 09:53:38 2005
@@ -0,0 +1,91 @@
+/*
+ * $HeadURL$
+ * $Revision$
+ * $Date$
+ *
+ * ====================================================================
+ *
+ *  Copyright 1999-2004 The Apache Software Foundation
+ *
+ *  Licensed 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.
+ * ====================================================================
+ *
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation.  For more
+ * information on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ *
+ */
+package org.apache.http.contrib.spring;
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpMutableRequest;
+import org.apache.http.HttpRequestFactory;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.Protocol;
+import org.apache.http.entity.EntityConsumer;
+import org.apache.http.executor.HttpRequestExecutor;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.springframework.beans.factory.xml.XmlBeanFactory;
+import org.springframework.core.io.ClassPathResource;
+
+public class SpringHttpDemo {
+
+    public static void main(String[] args) throws Exception {
+
+        ClassPathResource res = new ClassPathResource("org/apache/http/contrib/spring/http-beans.xml");
+        XmlBeanFactory beanfactory = new XmlBeanFactory(res);
+        
+        // Set global params if desired
+        HttpParams globalparams = (HttpParams) beanfactory.getBean("global-params");
+        
+        HttpParams params = (HttpParams) beanfactory.getBean("params");
+        
+        HttpProtocolParams protocolparams = new HttpProtocolParams(params)
+            .setVersion(HttpVersion.HTTP_1_1)
+            .setContentCharset("UTF-8")
+            .setUseExpectContinue(true)
+            .setUserAgent("Jakarta HTTP Demo");
+        
+        HttpRequestExecutor httpexec = (HttpRequestExecutor)beanfactory.getBean("http-executor");
+        httpexec.setParams(params);
+        
+        Protocol http = (Protocol) beanfactory.getBean("http-protocol");
+        HttpHost host = new HttpHost("www.yahoo.com", 80, http);
+
+        HttpRequestFactory requestfactory = (HttpRequestFactory) beanfactory.getBean("http-request-factory");
+        HttpClientConnection conn = (HttpClientConnection) beanfactory.getBean("http-connection");
+        conn.setTargetHost(host);
+        try {
+            HttpMutableRequest request1 = requestfactory.newHttpRequest("GET", "/");
+            HttpResponse response1 = httpexec.execute(request1, conn);
+            System.out.println("<< Response: " + response1.getStatusLine());
+            System.out.println(EntityConsumer.toString(response1.getEntity()));
+            System.out.println("==============");
+            if (conn.isOpen()) {
+                System.out.println("Connection kept alive...");
+            }
+            HttpMutableRequest request2 = requestfactory.newHttpRequest("GET", "/stuff");
+            HttpResponse response2 = httpexec.execute(request2, conn);
+            System.out.println("<< Response: " + response2.getStatusLine());
+            System.out.println(EntityConsumer.toString(response2.getEntity()));
+            System.out.println("==============");
+        } finally {
+            conn.close();
+        }
+    }
+    
+}

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/SpringHttpDemo.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml?rev=180108&view=auto
==============================================================================
--- jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
(added)
+++ jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
Sun Jun  5 09:53:38 2005
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+
+  <bean id="global-params" 
+    class="org.apache.http.impl.DefaultHttpParams" 
+    singleton="true" />
+
+  <bean id="params" 
+    class="org.apache.http.impl.DefaultHttpParams" 
+    singleton="false">
+    <property name="defaults"><ref bean="global-params"/></property>
+  </bean>
+
+  <bean id="socket-factory" 
+    class="org.apache.http.impl.io.NIOSocketFactory" 
+    singleton="true" />
+    
+  <bean id="http-protocol" 
+    class="org.apache.http.Protocol">
+    <constructor-arg index="0"><value>http</value></constructor-arg>
+    <constructor-arg index="1"><ref bean="socket-factory"/></constructor-arg>
+    <constructor-arg index="2"><value>80</value></constructor-arg>
+  </bean>
+  
+  <bean id="http-executor" 
+    class="org.apache.http.executor.HttpRequestExecutor" 
+    singleton="true" >
+    <property name="interceptors">
+      <set>
+        <!-- Required request interceptors -->
+        <bean class="org.apache.http.interceptor.RequestContent" />
+        <bean class="org.apache.http.interceptor.RequestTargetHost" />
+        <!-- Recommended request interceptors -->
+        <bean class="org.apache.http.interceptor.RequestConnControl" />
+        <bean class="org.apache.http.interceptor.RequestUserAgent" />
+        <bean class="org.apache.http.interceptor.RequestExpectContinue" />
+      </set>
+    </property>
+  </bean>
+  
+  <bean id="http-data-trx-factory" 
+    class="org.apache.http.impl.io.DefaultHttpDataTransmitterFactory" 
+    singleton="true" />
+  
+  <bean id="http-data-rcv-factory" 
+    class="org.apache.http.impl.io.DefaultHttpDataReceiverFactory" 
+    singleton="true" />
+  
+  <bean id="http-request-factory"
+    class="org.apache.http.impl.DefaultHttpRequestFactory" 
+    singleton="true" />
+  
+  <bean id="http-response-factory"
+    class="org.apache.http.impl.DefaultHttpResponseFactory" 
+    singleton="true" />
+  
+  <bean id="http-connection" 
+    class="org.apache.http.impl.DefaultHttpClientConnection" 
+    singleton="false">
+    <property name="receiverFactory"><ref bean="http-data-rcv-factory"/></property>
+    <property name="transmitterFactory"><ref bean="http-data-trx-factory"/></property>
+    <property name="responseFactory"><ref bean="http-response-factory"/></property>
+  </bean>
+  
+</beans>

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/http-common/src/contrib/org/apache/http/contrib/spring/http-beans.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml



Mime
View raw message