Search in sources :

Example 36 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class paloconnection method sendToServerSingleRC.

// Retrieves only true or false based on the given connection
public boolean sendToServerSingleRC(List<NameValuePair> qparams, String strAPIUrl) throws paloexception {
    try {
        HttpEntity entity = sendToServer(qparams, strAPIUrl);
        CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
        // CsvReader csv = new CsvReader(sendToServer(qparams, strAPIUrl).getContent(), Charset.defaultCharset());
        csv.setQuoteChar('"');
        csv.readNext();
        boolean bStatus = Boolean.getBoolean(csv.get(0));
        csv.close();
        entity.consumeContent();
        return bStatus;
    } catch (Exception e) {
        throw new paloexception(e.getMessage());
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader)

Example 37 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class paloconnection method sendToServer.

public HttpEntity sendToServer(List<NameValuePair> qparams, String strAPIUrl) throws paloexception {
    try {
        URI uri = URIUtils.createURI("http", strServer, Integer.valueOf(strPort), strAPIUrl, URLEncodedUtils.format(qparams, "UTF-8"), null);
        HttpGet req = new HttpGet(uri);
        // System.out.println(req.getURI());
        // Send to Server
        HttpResponse rsp = paloHttpClient.execute(paloTargetHost, req);
        HttpEntity entity = rsp.getEntity();
        if (rsp.getStatusLine().getStatusCode() != 200) {
            // Error had been occured
            // Close Connection and thend raise paloexception error
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            csv.readNext();
            paloexception plX = new paloexception(csv.get(0), csv.get(1), csv.get(2));
            csv.close();
            entity.consumeContent();
            // paloHttpClient.getConnectionManager().shutdown();
            throw (plX);
        } else {
            return entity;
        }
    } catch (Exception e) {
        // if(paloHttpClient!=null)paloHttpClient.getConnectionManager().shutdown();
        throw new paloexception(e.getMessage());
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) URI(java.net.URI)

Example 38 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class palocube method refreshCubeInfo.

public void refreshCubeInfo() throws paloexception {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
    qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
    qparams.add(new BasicNameValuePair("cube", String.valueOf(iCubeId)));
    try {
        HttpEntity entity = this.plConn.sendToServer(qparams, "/cube/info");
        CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
        csv.setQuoteChar('"');
        csv.readNext();
        this.iCubeId = palohelpers.StringToInt(csv.get(0));
        this.strCubeName = csv.get(1);
        this.iNumberOfDimensions = palohelpers.StringToInt(csv.get(2));
        this.iArrDimensionsIdentifier = palohelpers.StringToIntArray(csv.get(3), palohelpers.StringToInt(csv.get(2)));
        this.iNumberOfCells = palohelpers.StringToLong(csv.get(4));
        this.lNumberOfFilledCells = palohelpers.StringToLong(csv.get(5));
        this.iCubeStatus = palohelpers.StringToInt(csv.get(6));
        this.iCubeType = palohelpers.StringToInt(csv.get(7));
        this.iCubeToken = palohelpers.StringToInt(csv.get(8));
        csv.close();
        entity.consumeContent();
    } catch (Exception e) {
        throw new paloexception(e.getMessage());
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 39 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class palocube method rename.

public void rename(String strCubeNewName) throws paloexception {
    if (null != strCubeNewName && strCubeNewName.length() > 0 && !strCubeName.equals(strCubeNewName)) {
        List<NameValuePair> qparams = new ArrayList<NameValuePair>();
        qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
        qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
        qparams.add(new BasicNameValuePair("cube", String.valueOf(iCubeId)));
        qparams.add(new BasicNameValuePair("new_name", strCubeNewName));
        try {
            HttpEntity entity = this.plConn.sendToServer(qparams, "/cube/rename");
            CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
            csv.setQuoteChar('"');
            csv.readNext();
            this.strCubeName = csv.get(1);
            csv.close();
            entity.consumeContent();
        } catch (Exception e) {
            throw new paloexception(e.getMessage());
        }
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Example 40 with HttpEntity

use of org.apache.http.HttpEntity in project tdi-studio-se by Talend.

the class palodimension method refreshDimensionInfo.

public void refreshDimensionInfo() throws paloexception {
    List<NameValuePair> qparams = new ArrayList<NameValuePair>();
    qparams.add(new BasicNameValuePair("sid", this.plConn.getPaloToken()));
    qparams.add(new BasicNameValuePair("database", String.valueOf(lDatabaseId)));
    qparams.add(new BasicNameValuePair("dimension", String.valueOf(this.iDimensionId)));
    try {
        HttpEntity entity = this.plConn.sendToServer(qparams, "/dimension/info");
        CSVReader csv = new CSVReader(entity.getContent(), ';', "UTF-8");
        csv.setQuoteChar('"');
        csv.readNext();
        this.strDimensionName = csv.get(1);
        this.iDimensionId = Integer.valueOf(csv.get(0));
        this.iAssocDimension = palohelpers.StringToInt(csv.get(7));
        this.iAttributCube = palohelpers.StringToInt(csv.get(8));
        this.iRightsCube = palohelpers.StringToInt(csv.get(9));
        this.iNumberOfElements = palohelpers.StringToInt(csv.get(2));
        this.iMaximumLevel = palohelpers.StringToInt(csv.get(3));
        this.iMaximumIndent = palohelpers.StringToInt(csv.get(4));
        this.iMaximumDepth = palohelpers.StringToInt(csv.get(5));
        this.iDimensionToken = palohelpers.StringToInt(csv.get(10));
        csv.close();
        entity.consumeContent();
    } catch (Exception e) {
        throw new paloexception(e.getMessage());
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) HttpEntity(org.apache.http.HttpEntity) CSVReader(com.talend.csv.CSVReader) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList)

Aggregations

HttpEntity (org.apache.http.HttpEntity)1391 HttpResponse (org.apache.http.HttpResponse)509 IOException (java.io.IOException)483 HttpGet (org.apache.http.client.methods.HttpGet)391 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)315 HttpPost (org.apache.http.client.methods.HttpPost)305 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)284 Test (org.junit.Test)259 ArrayList (java.util.ArrayList)248 HashMap (java.util.HashMap)177 MultipartEntityBuilder (org.apache.http.entity.mime.MultipartEntityBuilder)164 InputStream (java.io.InputStream)163 URI (java.net.URI)153 StatusLine (org.apache.http.StatusLine)149 StringEntity (org.apache.http.entity.StringEntity)148 Header (org.apache.http.Header)136 HttpClient (org.apache.http.client.HttpClient)127 VolleyError (com.android.volley.VolleyError)120 ApiException (io.swagger.client.ApiException)120 Pair (io.swagger.client.Pair)120