All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.meschbach.psi.util.rest.PutRequest Maven / Gradle / Ivy

Go to download

Reusable utility classes for interacting with PSI components. This includes a series of components which are utilized in testing the system.

The newest version!
/*
 *  Copyright 2011 Mark Eschbach
 *
 *  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.
 *
 * $HeadURL: https://phunctional-system-integration.googlecode.com/svn/tags/psi-reactor-2.4/trunk/psi-util/src/main/java/com/meschbach/psi/util/rest/PutRequest.java $
 * $Id: PutRequest.java 242 2011-03-07 02:48:48Z [email protected] $
 */
package com.meschbach.psi.util.rest;

import java.io.UnsupportedEncodingException;
import java.net.URI;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;

/**
 * A PutRequest encapsulates an HTTP PUT request with an HTTP
 * entity possibility attached.
 * 
 * @author "Mark Eschbach" [email protected]
 * @since 1.2.0 (PSI 2.3.0)
 * @version  1.0.0
 */
public class PutRequest implements RequestBuilder {

    /**
     * The entity to be attached, or null if no entity is to be attached.
     */
    String entity;

    /**
     * Constructs a new PUT request without an HTTP entity with the request
     */
    public PutRequest() {
    }

    /**
     * Constructs a new PUT request builder with the specified entity
     * @param entity
     */
    public PutRequest(String entity) {
        this.entity = entity;
    }

    /**
     * @see RequestBuilder#buildRequest(java.lang.String) 
     */
    public HttpUriRequest buildRequest(URI resource) {
        HttpPut put = new HttpPut(resource);
        if (entity != null) {
            try {
                put.setEntity(new StringEntity(entity));
            } catch (UnsupportedEncodingException uee) {
                throw new IllegalStateException(uee);
            }
        }
        return put;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy