Revision: 4651
          http://sourceforge.net/p/vexi/code/4651
Author:   mkpg2
Date:     2014-02-05 00:35:02 +0000 (Wed, 05 Feb 2014)
Log Message:
-----------
3rd http implementation. jre_http - Uses internal jre classes.
- hopefully auto detect proxy settings

Modified Paths:
--------------
    branches/vexi3/org.vexi-core.download/meta/product-assembly.xml
    branches/vexi3/org.vexi-library.net/meta/module-build.xml

Added Paths:
-----------
    branches/vexi3/org.vexi-library.net/src/main/jpp/org/ibex/net/JreHTTP.jpp

Modified: branches/vexi3/org.vexi-core.download/meta/product-assembly.xml
===================================================================
--- branches/vexi3/org.vexi-core.download/meta/product-assembly.xml     
2014-02-04 09:29:51 UTC (rev 4650)
+++ branches/vexi3/org.vexi-core.download/meta/product-assembly.xml     
2014-02-05 00:35:02 UTC (rev 4651)
@@ -5,7 +5,7 @@
                <!-- Turn off debugging information, breaks shrinker -->
                <module-selection conf-mapping="!noshrink->nodebug" 
artifact="java_classes.jar">
                        <include source="local" name="core.main"/>
-                       <include source="local" name="library.net"    
conf-mapping="apache_http->apache_http"/>
+                       <include source="local" name="library.net"    
conf-mapping="apache_http->apache_http,jre_http->jre_http"/>
                        <include source="local" name="core.devtools"  
conf="devtools"/>
                        <exclude source="maven-public" 
org="org.apache.httpcomponents" name="httpclient"/>
                        <exclude source="system" name="jre"/>

Modified: branches/vexi3/org.vexi-library.net/meta/module-build.xml
===================================================================
--- branches/vexi3/org.vexi-library.net/meta/module-build.xml   2014-02-04 
09:29:51 UTC (rev 4650)
+++ branches/vexi3/org.vexi-library.net/meta/module-build.xml   2014-02-05 
00:35:02 UTC (rev 4651)
@@ -6,6 +6,9 @@
                        <property key="defines" conf="apache_http">
                        { "APACHE_HTTP": "true" }
                        </property>
+                       <property key="defines" conf="jre_http">
+            { "JRE_HTTP": "true" }
+            </property>
                </builder>
                <builder refid="javac" />
                <builder refid="javaexport" />

Added: branches/vexi3/org.vexi-library.net/src/main/jpp/org/ibex/net/JreHTTP.jpp
===================================================================
--- branches/vexi3/org.vexi-library.net/src/main/jpp/org/ibex/net/JreHTTP.jpp   
                        (rev 0)
+++ branches/vexi3/org.vexi-library.net/src/main/jpp/org/ibex/net/JreHTTP.jpp   
2014-02-05 00:35:02 UTC (rev 4651)
@@ -0,0 +1,123 @@
+//#ifdef JRE_HTTP
+package org.ibex.net;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+
+import org.ibex.util.IOUtil;
+import org.ibex.util.Logger;
+
+public class JreHTTP implements HTTP {
+
+       static synchronized JreHTTP create(Logger logger, String url) throws 
IOException{
+               if (url.indexOf("://") == -1)
+                       throw new IOException("URLs must contain a ://");
+               return new JreHTTP(logger, url);
+       }
+       
+       final Logger logger;
+       final String url;
+       boolean ssl;
+
+
+       public JreHTTP(Logger logger, String url) throws IOException {
+               this.logger = logger;
+               this.url = url;
+               if (url.startsWith("https:")) {
+                       ssl = true;
+               } else if (!url.startsWith("http:")) {
+
+                       throw new IOException("HTTP only supports http/https 
urls");
+               }
+       }
+
+       public HTTPResponse GET() throws IOException {
+               HttpURLConnection connection = null;  
+               try {
+                       //Create connection
+                       connection = newConnection();
+                       connection.setRequestMethod("GET");
+                       connection.setUseCaches (false);
+                       connection.setDoInput(true);
+                       connection.setDoOutput(false);
+
+                       //Get Response
+                       return readResponse(connection);
+               } catch (IOException e) {
+                       throw e;
+               } finally{
+//                     if(connection!=null){
+//                             connection.disconnect();
+//                     }
+               }
+       }
+
+       public HTTPResponse POST(String contentType, byte[] content) throws 
IOException {
+               HttpURLConnection connection = null;  
+               try {
+                       //Create connection
+                       connection = newConnection();
+                       connection.setRequestMethod("POST");
+                       connection.setRequestProperty("Content-Type", 
+                                       contentType);
+
+                       connection.setRequestProperty("Content-Length", "" + 
Integer.toString(content.length));
+                       connection.setRequestProperty("Content-Language", 
"en-US");  
+
+                       connection.setUseCaches (false);
+                       connection.setDoInput(true);
+                       connection.setDoOutput(true);
+
+                       //Send request
+                       OutputStream wr = connection.getOutputStream();
+                       wr.write(content);
+                       wr.flush ();
+                       wr.close ();
+
+                       //Get Response
+                       return readResponse(connection);
+               } catch (IOException e) {
+                       throw e;
+               } finally{
+//                     if(connection!=null){
+//                             connection.disconnect();
+//                     }
+               }
+       }
+       
+       private HttpURLConnection newConnection() throws IOException{
+               URL url = new URL(this.url);
+               return (HttpURLConnection)url.openConnection();
+       }
+       
+       public HTTPResponse readResponse(HttpURLConnection connection) throws 
IOException{
+               InputStream is = connection.getInputStream();
+               int statusCode = connection.getResponseCode();
+               if(statusCode>=400){
+                       byte[] bytes = IOUtil.toByteArray(is); // HACK doesn't 
seem to work unless we read this here
+                       HTTPEntityInfo info = new 
HTTPEntityInfo((int)bytes.length,"",connection.getContentType());
+                       throw new 
HTTPErrorResponse(connection.getResponseMessage(), statusCode+"", bytes, info);
+               }else{
+
+                       String lastmod = 
connection.getHeaderField("Last-Modified");
+                       String lengthStr = 
connection.getHeaderField("Content-Length");
+                       String contentTypeR = 
connection.getHeaderField("Content-Type");
+                       int length;
+                       if(lengthStr!=null){
+                               length = Integer.parseInt(lengthStr);
+                       }else{
+                               length = -1;
+                       }
+                       HTTPEntityInfo info = new HTTPEntityInfo(length, 
lastmod, contentTypeR);
+                       return new HTTPResponse(info, is);//new 
ByteArrayInputStream(bytes));
+               }
+       }
+
+}
+//#endif JRE_HTTP
+
+

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Managing the Performance of Cloud-Based Applications
Take advantage of what the Cloud has to offer - Avoid Common Pitfalls.
Read the Whitepaper.
http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to