03-12-2014 01:48 PM
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.CookieStore;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
   public static void test (String hostname, String port, String user, String password) throws Exception
   {
      try
      {
         URL_BASE="http://'+hostname+':'+port;
         DefaultHttpClient client = new DefaultHttpClient();
         HttpPost post = new HttpPost(URL_BASE+"/share/page/dologin");
         List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
         nameValuePairs.add(new BasicNameValuePair("username", user));
         nameValuePairs.add(new BasicNameValuePair("password", password));
         post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
         client.execute(post);
         setCookieStore(client.getCookieStore());
         executeGET (client.getCookieStore(),"http://localhost:8080/alfresco/service/demo/readonly/prueba");
      }
      catch (Exception ex)
      {
         throw new Exception ("No se pudo realizar la conexión al servidor \""+hostname+ "\" por el puerto "+port+" con el usuario y password indicados.");
      }
      
   }//connect
private static String executeGET (CookieStore cookieStore, String url) throws Exception  
   {
      
      System.out.println(url);
      if (cookieStore==null) 
           throw new Exception("ERR. Cookie Store NULO");
      String result=null;
        InputStream instream=null;
        try
        {
            DefaultHttpClient client = new DefaultHttpClient();
            client.setCookieStore(cookieStore);
            HttpGet  httpget = new HttpGet(url);
            HttpResponse  response = client.execute(httpget);
            HttpEntity entity = response.getEntity();
            if (entity==null) throw new Exception("ERROR. El objeto entity es nulo");
                instream = entity.getContent();
                result = IOUtils.toString(instream);
                System.out.println(result);
               
         }//try
         catch (ClientProtocolException ex){ex.printStackTrace();}
         catch (IOException ex){ex.printStackTrace();}
         catch (Exception ex){ex.printStackTrace();}
         finally{ if (instream!=null) instream.close();}
         return result;
   }//execute
03-12-2014 11:40 PM
      HttpClient client = new HttpClient();
      client.getState().setCredentials(
            new AuthScope("localhost", 8080, "Alfresco"),
            new UsernamePasswordCredentials("admin", "admin"));
      String uid = "1565a32e-7863-45af-a9fa-b68ad206b5e7";
      String apiurl = "http://localhost:8080/alfresco/service/api/node/workspace/SpacesStore/'+uid+'/versions";
      GetMethod get = new GetMethod(apiurl);
      try {
         get.setDoAuthentication(true);
         get.setRequestHeader("Content-Type", "application/json");
   
         int status = client.executeMethod(get);
         if (status != HttpStatus.SC_OK) {
            System.err.println("Method failed: " + get.getStatusLine());
         }
         String resultString = get.getResponseBodyAsString();
         System.out.println(resultString);
         
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         get.releaseConnection();
      }
03-17-2014 12:46 PM
03-19-2014 07:54 AM
03-27-2014 05:22 AM
03-28-2014 12:05 AM
        ScriptRemote scriptRemote = serviceRegistry.getScriptRemote();
        Response response = scriptRemote.connect().get(uri);
04-15-2014 11:34 AM
var urlService3= window.location.protocol + '//' + window.location.host + '/alfresco/service/com/portales/intranet/combos/tipos/listado';
  
    $.ajax({
        type: "GET",
        url: urlService3,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(response3) {
            var results3 = response3;
                                               $( "select[name='prop_prtls_tipo_documento']" ).html("");
            for(var i=0;i<results3.length;i++){
                                                               
                                                               $( "select[name='prop_prtls_tipo_documento']" ).append("<option value='"+results3.valor+"'>"+results3.valor+"</option>");
                                               }                                             
        },
        error: function(xhr, status, error) {
            var errorMessage = error.description != null ? error.description : error;
                                               
                                               $( "select[name='prop_prtls_tipo_documento']" ).html("<option value='"+errorMessage+"'>"+urlService3+"_"+errorMessage+"</option>");
        }
    });
04-21-2014 09:54 AM
Alfresco.util.Ajax.request(
{
   url: Alfresco.constants.PROXY_URI + urlService3,
   method: Alfresco.util.Ajax.GET (if you want to use post method ,please use  Alfresco.util.Ajax.POST)
   dataObj:
   {   
                data1: "data1",
                submitType: "json"
   },
   successCallback:
   {
      fn: this.success, // success callback method 
      scope: this
   },
   failureCallback:
   {
      fn: this.failure, // failure callback method 
      scope: this
   }
});
04-21-2014 08:48 AM
 
					
				
				
			
		
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.