Example usage for org.apache.commons.httpclient.methods PutMethod PutMethod

List of usage examples for org.apache.commons.httpclient.methods PutMethod PutMethod

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.methods PutMethod PutMethod.

Prototype

public PutMethod(String paramString) 

Source Link

Usage

From source file:lucee.commons.net.http.httpclient3.HTTPEngine3Impl.java

public static HTTPResponse put(URL url, String username, String password, int timeout, int maxRedirect,
        String charset, String useragent, ProxyData proxy, Header[] headers, Object body) throws IOException {
    return _invoke(new PutMethod(url.toExternalForm()), url, username, password, timeout, maxRedirect, charset,
            useragent, proxy, headers, null, body);
}

From source file:eu.learnpad.core.impl.cw.XwikiBridgeInterfaceRestResource.java

@Override
public void modelSetImported(String modelSetId, ModelSetType type) throws LpRestExceptionXWikiImpl {

    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/cw/bridge/modelsetimported/%s", DefaultRestResource.REST_URI,
            modelSetId);/*  ww  w  .j a  v  a2 s .c  om*/
    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", "application/xml");
    NameValuePair[] queryString = new NameValuePair[1];
    queryString[0] = new NameValuePair("type", type.toString());
    putMethod.setQueryString(queryString);
    try {
        httpClient.executeMethod(putMethod);
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e);
    }
}

From source file:eu.learnpad.core.impl.dash.XwikiBridgeInterfaceRestResource.java

@Override
public void loadKPIValues(String modelSetId, KPIValuesFormat format, String businessActorId,
        InputStream cockpitContent) throws LpRestException {
    String contentType = "application/xml";

    HttpClient httpClient = this.getAnonymousClient();
    String uri = String.format("%s/learnpad/dash/bridge/loadkpivalues/%s", this.restPrefix, modelSetId);
    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Content-Type", contentType);

    NameValuePair[] queryString = new NameValuePair[2];
    queryString[0] = new NameValuePair("format", format.toString());
    queryString[1] = new NameValuePair("businessactor", businessActorId);
    putMethod.setQueryString(queryString);

    RequestEntity requestEntity = new InputStreamRequestEntity(cockpitContent);
    putMethod.setRequestEntity(requestEntity);

    try {//from  w  w  w.j  a  va 2  s. c  o m
        httpClient.executeMethod(putMethod);
    } catch (IOException e) {
        throw new LpRestExceptionXWikiImpl(e.getMessage(), e);
    }
}

From source file:cz.muni.fi.pa165.creatures.rest.client.services.impl.WeaponCRUDServiceImpl.java

@Override
public void update(WeaponDTO dto) {
    PutMethod putMethod = new PutMethod(uri);
    StringWriter writer = new StringWriter();

    try {/*from  www .  ja  v a  2s  . c om*/
        context.createMarshaller().marshal(weaponMapping.DTOtoEntity(dto), writer);
    } catch (JAXBException ex) {
        logger.log(Level.INFO, "Unable to marshall WeaponDTO {0}", dto);
        return;
    }

    RequestEntity entity = new InputStreamRequestEntity(new ByteArrayInputStream(writer.toString().getBytes()));
    putMethod.setRequestEntity(entity);
    CRUDServiceHelper.send(putMethod);
}

From source file:com.agile_coder.poker.server.stories.steps.BaseSteps.java

protected void reveal(int session) throws IOException {
    HttpClient client = new HttpClient();
    String revealUrl = BASE_URL + "/" + session + "/reveal";
    PutMethod put = new PutMethod(revealUrl);
    int result = executeMethod(client, put);
    assertEquals(HttpStatus.SC_NO_CONTENT, result);

}

From source file:com.owncloud.android.lib.resources.files.ChunkedUploadRemoteFileOperation.java

@Override
protected int uploadFile(OwnCloudClient client) throws HttpException, IOException {
    int status = -1;

    FileChannel channel = null;/*from w  ww .j  a  v a 2s  . co m*/
    RandomAccessFile raf = null;
    try {
        File file = new File(mLocalPath);
        raf = new RandomAccessFile(file, "r");
        channel = raf.getChannel();
        mEntity = new ChunkFromFileChannelRequestEntity(channel, mMimeType, CHUNK_SIZE, file);
        //((ProgressiveDataTransferer)mEntity).addDatatransferProgressListeners(getDataTransferListeners());
        synchronized (mDataTransferListeners) {
            ((ProgressiveDataTransferer) mEntity).addDatatransferProgressListeners(mDataTransferListeners);
        }

        long offset = 0;
        String uriPrefix = client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath) + "-chunking-"
                + Math.abs((new Random()).nextInt(9000) + 1000) + "-";
        long chunkCount = (long) Math.ceil((double) file.length() / CHUNK_SIZE);
        for (int chunkIndex = 0; chunkIndex < chunkCount; chunkIndex++, offset += CHUNK_SIZE) {
            if (mPutMethod != null) {
                mPutMethod.releaseConnection(); // let the connection available for other methods
            }
            mPutMethod = new PutMethod(uriPrefix + chunkCount + "-" + chunkIndex);
            mPutMethod.addRequestHeader(OC_CHUNKED_HEADER, OC_CHUNKED_HEADER);
            ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
            mPutMethod.setRequestEntity(mEntity);
            status = client.executeMethod(mPutMethod);
            client.exhaustResponse(mPutMethod.getResponseBodyAsStream());
            Log_OC.d(TAG, "Upload of " + mLocalPath + " to " + mRemotePath + ", chunk index " + chunkIndex
                    + ", count " + chunkCount + ", HTTP result status " + status);
            if (!isSuccess(status))
                break;
        }

    } finally {
        if (channel != null)
            channel.close();
        if (raf != null)
            raf.close();
        if (mPutMethod != null)
            mPutMethod.releaseConnection(); // let the connection available for other methods
    }
    return status;
}

From source file:de.mpg.escidoc.http.UserGroup.java

@SuppressWarnings("deprecation")
public Boolean createUserGroups() {
    String userGroupName = Util.input("Name of the UserGroup to create: ");
    String userGroupLabel = Util.input("Label of the UserGroup to create: ");
    Document responseXML = null;/*from  w  w w  .  j  av  a 2 s .co m*/
    if (this.USER_HANDLE != null) {
        PutMethod put = new PutMethod(this.FRAMEWORK_URL + "/aa/user-group");
        put.setRequestHeader("Cookie", "escidocCookie=" + this.USER_HANDLE);
        try {
            System.out.println("Request body sent to Server: ");
            put.setRequestEntity(new StringRequestEntity(Util.getCreateXml(userGroupName, userGroupLabel)));
            this.client.executeMethod(put);
            if (put.getStatusCode() != 200) {
                System.out.println("Server StatusCode: " + put.getStatusCode());
                return false;
            }
            System.out.println("Server response: ");
            responseXML = Util.inputStreamToXmlDocument(put.getResponseBodyAsStream());
            Util.xmlToString(responseXML);
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Error in creatUserGroup: No userHandle available");
    }
    return true;
}

From source file:at.ac.tuwien.auto.sewoa.http.HttpRetrieverImpl.java

public byte[] putData(String url, String data) {
    byte[] result = new byte[] {};
    HttpClient httpClient = httpClientFactory.createClient();
    PutMethod putmethod = new PutMethod(url);
    putmethod.setRequestEntity(new StringRequestEntity(data));

    HttpConnectionManagerParams params = httpClient.getHttpConnectionManager().getParams();
    params.setConnectionTimeout((int) TimeUnit.SECONDS.toMillis(CONNECTION_TO));
    params.setSoTimeout((int) TimeUnit.SECONDS.toMillis(SOCKET_TO));
    putmethod.addRequestHeader("Content-Type", "application/xml");
    putmethod.addRequestHeader("Accept", "application/xml");

    try {//from w  ww  . ja v a 2  s  . c  o  m
        result = send(httpClient, putmethod);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}

From source file:com.kylinolap.common.restclient.RestClient.java

public void wipeCache(String type, String action, String name) throws IOException {
    String url = baseUrl + "/cache/" + type + "/" + name + "/" + action;
    HttpMethod get = new PutMethod(url);

    try {/*  w  w w . j  a  va2s . co  m*/
        int code = client.executeMethod(get);
        String msg = Bytes.toString(get.getResponseBody());

        if (code != 200)
            throw new IOException("Invalid response " + code + " with cache wipe url " + url + "\n" + msg);

    } catch (HttpException ex) {
        throw new IOException(ex);
    } finally {
        get.releaseConnection();
    }
}

From source file:eu.learnpad.core.impl.qm.XwikiCoreFacadeRestResource.java

@Override
public void generationCompleted(String questionnairesId) throws LpRestException {
    // Now actually notifying the CP via REST
    HttpClient httpClient = this.getClient();
    String uri = String.format("%s/learnpad/qm/corefacade/generationcompleted/%s", DefaultRestResource.REST_URI,
            questionnairesId);/* w  ww  .  jav a2s  .c o  m*/
    PutMethod putMethod = new PutMethod(uri);
    putMethod.addRequestHeader("Accept", MediaType.TEXT_PLAIN);
    try {
        httpClient.executeMethod(putMethod);
    } catch (IOException e) {
        LpRestExceptionXWikiImpl e1 = new LpRestExceptionXWikiImpl(e.getMessage(), e.getCause());
        throw e1;
    }
}