当前位置: 首页>>代码示例>>Java>>正文


Java ClientResponse类代码示例

本文整理汇总了Java中org.apache.wink.client.ClientResponse的典型用法代码示例。如果您正苦于以下问题:Java ClientResponse类的具体用法?Java ClientResponse怎么用?Java ClientResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ClientResponse类属于org.apache.wink.client包,在下文中一共展示了ClientResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: genericRestRequestPut

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
/**
 * Generic rest client for basic rest PUT calls over REST based on Apache Wink
 *
 * @param resourceUrl     Resource endpoint Url
 * @param contentType     ContentType of request
 * @param acceptMediaType ContentType for response
 * @param postBody        Body
 * @param queryParamMap   Map of Query parameters
 * @param headerMap       Map of headers
 * @param cookie          jSessionID in form of JSESSIONID=<ID>
 * @return                Returns the response from the REST client
 */
public ClientResponse genericRestRequestPut(String resourceUrl, String contentType, String acceptMediaType,
        Object postBody, Map<String, String> queryParamMap, Map<String, String> headerMap, String cookie) {

    Resource resource = client.resource(resourceUrl);

    if (!(queryParamMap.size() <= 0)) {
        for (Map.Entry<String, String> queryParamEntry : queryParamMap.entrySet()) {
            resource.queryParam(queryParamEntry.getKey(), queryParamEntry.getValue());
        }
    }
    if (!(headerMap.size() <= 0)) {
        for (Map.Entry<String, String> headerEntry : headerMap.entrySet()) {
            resource.header(headerEntry.getKey(), headerEntry.getValue());
        }
    }
    if (cookie != null) {
        resource.cookie(cookie);
    }
    response = resource.contentType(contentType).
            accept(acceptMediaType).put(postBody);
    return response;
}
 
开发者ID:wso2,项目名称:product-es,代码行数:35,代码来源:GenericRestClient.java

示例2: getServiceProviderCatalog

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
public static ServiceProviderCatalog getServiceProviderCatalog() throws Exception {
    OslcClient client = new OslcClient();
    ClientResponse response = null;
    ServiceProviderCatalog catalog = null;

    // Start of user code getServiceProviderCatalog_init
    // End of user code

    response = client.getResource(serviceProviderCatalogURI,OSLCConstants.CT_RDF);
    if (response != null) {
        catalog = response.getEntity(ServiceProviderCatalog.class);
    }
    // Start of user code getServiceProviderCatalog_final
    // End of user code
    return catalog;
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:17,代码来源:GenericRequiredAdaptorClient.java

示例3: getMission

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
public static Mission getMission(String resourceURI) throws Exception {
    OslcClient client = new OslcClient();
    ClientResponse response = null;
    Mission resource = null;

    // Start of user code getMission_init
    // End of user code

    response = client.getResource(resourceURI, OSLCConstants.CT_RDF);
    if (response != null) {
        resource = response.getEntity(Mission.class);
    }
    // Start of user code getMission_final
    // End of user code
    return resource;
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:17,代码来源:GenericRequiredAdaptorClient.java

示例4: getPlan

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
public static Plan getPlan(String resourceURI) throws Exception {
    OslcClient client = new OslcClient();
    ClientResponse response = null;
    Plan resource = null;

    // Start of user code getPlan_init
    // End of user code

    response = client.getResource(resourceURI, OSLCConstants.CT_RDF);
    if (response != null) {
        resource = response.getEntity(Plan.class);
    }
    // Start of user code getPlan_final
    // End of user code
    return resource;
}
 
开发者ID:EricssonResearch,项目名称:scott-eu,代码行数:17,代码来源:GenericRequiredAdaptorClient.java

示例5: testCreateMessage

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test
@InSequence(1)
public void testCreateMessage(){
	
	final String testUrl = String.format("http://localhost:9080/%s/messages", contextRoot);
	
	RestClient client = new RestClient();
	Message message = new Message();
	message.setValue(testMessage);
	
	ClientResponse response = client.resource(testUrl)
								.accept(MediaType.APPLICATION_JSON)
								.contentType(MediaType.APPLICATION_JSON)
								.post(message);	
	
	assertEquals("The status code of the response is not the expected value.", Status.CREATED.getStatusCode(), response.getStatusCode());

	Message respMsg = response.getEntity(Message.class);
	
	assertNotNull("The message id was not set by the service.", respMsg.getId());
	
	messageId = respMsg.getId();
	
	assertNotNull("The message modified date was not set by the service.", respMsg.getLastUpdated());
	assertEquals("The value of the message does not match what was provided.",  message.getValue(), respMsg.getValue());
}
 
开发者ID:tglawless,项目名称:jee,代码行数:27,代码来源:MessageResourceTest.java

示例6: testFindMessageById

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test
@InSequence(2)
public void testFindMessageById(){
	
	final String testUrl = String.format("http://localhost:9080/%s/messages/%d", contextRoot, messageId);
	
	RestClient client = new RestClient();
	ClientResponse response = client.resource(testUrl)
								.accept(MediaType.APPLICATION_JSON)
								.get();	
	
	assertEquals("The status code of the response is not the expected value.", Status.OK.getStatusCode(), response.getStatusCode());

	Message respMsg = response.getEntity(Message.class);
	assertNotNull("The message id was not set by the service.", respMsg.getId());
	assertNotNull("The message modified date was not set by the service.", respMsg.getLastUpdated());
	assertEquals("The value of the message does not match what was provided.",  testMessage, respMsg.getValue());
}
 
开发者ID:tglawless,项目名称:jee,代码行数:19,代码来源:MessageResourceTest.java

示例7: testUpdateMessage

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test
@InSequence(3)
public void testUpdateMessage(){
	
	final String testUrl = String.format("http://localhost:9080/%s/messages/%d", contextRoot, messageId);
	
	RestClient client = new RestClient();
	Message message = new Message();
	message.setValue(testMessage + " - updated: " + new Date());
	
	ClientResponse response = client.resource(testUrl)
								.accept(MediaType.APPLICATION_JSON)
								.contentType(MediaType.APPLICATION_JSON)
								.put(message);	
	
	assertEquals("The status code of the response is not the expected value.", Status.OK.getStatusCode(), response.getStatusCode());

	Message respMsg = response.getEntity(Message.class);
	assertNotNull("The message id was not set by the service.", respMsg.getId());
	assertNotNull("The message modified date was not set by the service.", respMsg.getLastUpdated());
	assertEquals("The value of the message does not match what was provided.",  message.getValue(), respMsg.getValue());
}
 
开发者ID:tglawless,项目名称:jee,代码行数:23,代码来源:MessageResourceTest.java

示例8: testFindAllMessages

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test
@InSequence(4)
public void testFindAllMessages(){
	
	final String testUrl = String.format("http://localhost:9080/%s/messages", contextRoot);
	
	RestClient client = new RestClient();
	ClientResponse response = client.resource(testUrl)
							.accept(MediaType.APPLICATION_JSON)
							.get();
	
	Message[] messages = response.getEntity(Message[].class);
	
	assertNotNull("The list of messages returned by the service was null.", messages);
	assertTrue("Test expected at least 1 message to be contained within the list.", messages.length > 0);
}
 
开发者ID:tglawless,项目名称:jee,代码行数:17,代码来源:MessageResourceTest.java

示例9: geneticRestRequestDelete

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
public ClientResponse geneticRestRequestDelete(String resourceUrl, String contentType,
                                               String acceptMediaType,
                                               Map<String, String> queryParamMap,
                                               Map<String, String> headerMap,
                                               String cookie) {
    Resource resource = client.resource(resourceUrl);
    if (!(queryParamMap.size() <= 0)) {
        for (Map.Entry<String, String> queryParamEntry : queryParamMap.entrySet()) {
            resource.queryParam(queryParamEntry.getKey(), queryParamEntry.getValue());
        }
    }
    if (!(headerMap.size() <= 0)) {
        for (Map.Entry<String, String> headerEntry : headerMap.entrySet()) {
            resource.header(headerEntry.getKey(), headerEntry.getValue());
        }
    }
    if (cookie != null) {
        resource.cookie(cookie);
    }

    response = resource.contentType(contentType).
            accept(acceptMediaType).delete();
    return response;
}
 
开发者ID:wso2,项目名称:product-es,代码行数:25,代码来源:GenericRestClient.java

示例10: createTestRestServices

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Create Test Rest Service",
        dependsOnMethods = {"authenticatePublisher"})
public void createTestRestServices() throws JSONException, IOException {
    queryParamMap.put("type", "restservice");
    String dataBody = readFile(resourcePath + "json" + File.separator + "publisherPublishRestResource.json");
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/assets",
                    MediaType.APPLICATION_JSON,
                    MediaType.APPLICATION_JSON, dataBody
                    , queryParamMap, headerMap, cookieHeader);
    JSONObject obj = new JSONObject(response.getEntity(String.class));
    assertTrue((response.getStatusCode() == Response.Status.CREATED.getStatusCode()),
            "Wrong status code ,Expected 201 Created ,Received " +
                    response.getStatusCode()
    );
    testAssetId = obj.get("id").toString();
    assertNotNull(testAssetId, "Empty asset resource id available" +
            response.getEntity(String.class));
}
 
开发者ID:wso2,项目名称:product-es,代码行数:20,代码来源:GregRestResourceAssociationTestCase.java

示例11: geneticRestRequestGet

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
public ClientResponse geneticRestRequestGet(String resourceUrl,
                                            Map<String, String> queryParamMap,
                                            String acceptMediaType,
                                            Map<String, String> headerMap,
                                            String cookie) {
    Resource resource = client.resource(resourceUrl);
    MultivaluedMap<String, String> queryParamInMap = new MultivaluedHashMap<>();
    if (!(queryParamMap.size() <= 0)) {
        for (Map.Entry<String, String> queryParamEntry : queryParamMap.entrySet()) {
            queryParamInMap.add(queryParamEntry.getKey(), queryParamEntry.getValue());
        }
        resource.queryParams(queryParamInMap);
    }
    if (!(headerMap.size() <= 0)) {
        for (Map.Entry<String, String> headerEntry : headerMap.entrySet()) {
            resource.header(headerEntry.getKey(), headerEntry.getValue());
        }
    }
    if (cookie != null) {
        resource.cookie(cookie);
    }
    response = resource.accept(acceptMediaType).get();
    return response;
}
 
开发者ID:wso2,项目名称:product-es,代码行数:25,代码来源:GenericRestClient.java

示例12: createAsset

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
/**
 * Create Asset
 *
 * @param resourcePath
 * @param publisherUrl
 * @param cookieHeader
 * @param genericRestClient
 * @return
 * @throws JSONException
 * @throws IOException
 */
public ClientResponse createAsset(String resourcePath,
                                  String publisherUrl,
                                  String cookieHeader,
                                  String assetType,
                                  GenericRestClient genericRestClient)
        throws JSONException, IOException {
    queryParamMap.put("type", assetType);
    String dataBody = readFile(resourcePath);
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/assets",
                                                     MediaType.APPLICATION_JSON,
                                                     MediaType.APPLICATION_JSON, dataBody
                    , queryParamMap, headerMap, cookieHeader);

    return response;
}
 
开发者ID:wso2,项目名称:product-es,代码行数:28,代码来源:ESTestBaseTest.java

示例13: updateCustomAsset

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Update Custom Asset in Publisher",
        dependsOnMethods = {"searchCustomAsset"})
public void updateCustomAsset() throws JSONException, IOException {
    Map<String, String> queryParamMap = new HashMap<>();
    queryParamMap.put("type", "applications");
    String customTemplate = readFile(resourcePath + "json" + File.separator + "custom-application-update.json");
    String dataBody = String.format(customTemplate, "Test update asset");
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/assets/" + assetId,
                    MediaType.APPLICATION_JSON,
                    MediaType.APPLICATION_JSON, dataBody
                    , queryParamMap, headerMap, cookieHeader);
    JSONObject obj = new JSONObject(response.getEntity(String.class));
    assertTrue((response.getStatusCode() == 202),
            "Wrong status code ,Expected 202 Created ,Received " +
                    response.getStatusCode()
    );
    assertTrue(obj.getJSONObject("attributes").get("overview_description")
            .equals("Test update asset"));
}
 
开发者ID:wso2,项目名称:product-es,代码行数:21,代码来源:CustomAssetCRUDTestCase.java

示例14: createCustomAsset

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Create Custom Asset in Publisher")
public void createCustomAsset() throws JSONException, IOException, InterruptedException {
    Map<String, String> queryParamMap = new HashMap<>();
    queryParamMap.put("type", "applications");
    String customTemplate = readFile(resourcePath + "json" + File.separator + "custom-applications-sample.json");
    assetName = "application12345";
    String dataBody = String.format(customTemplate, assetName, "1.2.3", "Test asset");
    ClientResponse response =
            genericRestClient.geneticRestRequestPost(publisherUrl + "/assets",
                    MediaType.APPLICATION_JSON,
                    MediaType.APPLICATION_JSON, dataBody
                    , queryParamMap, headerMap, cookieHeader);
    JSONObject obj = new JSONObject(response.getEntity(String.class));
    assertTrue((response.getStatusCode() == 201),
            "Wrong status code ,Expected 201 Created ,Received " +
                    response.getStatusCode()
    );
    assetId = (String)obj.get("id");
    assertNotNull(assetId, "Empty asset resource id available" +
            response.getEntity(String.class));
}
 
开发者ID:wso2,项目名称:product-es,代码行数:22,代码来源:CustomAssetCRUDTestCase.java

示例15: authenticateStore

import org.apache.wink.client.ClientResponse; //导入依赖的package包/类
@Test(groups = {"wso2.greg", "wso2.greg.es"}, description = "Authenticate Store",
        dependsOnMethods = "createTestRestServices")
public void authenticateStore() throws JSONException, XPathExpressionException {

    ClientResponse response =
            genericRestClient.geneticRestRequestPost(storeUrl + "/authenticate/",
                    MediaType.APPLICATION_FORM_URLENCODED,
                    MediaType.APPLICATION_JSON,
                    "username=" + automationContext.getContextTenant().getContextUser().getUserName() +
                            "&password=" + automationContext.getContextTenant().getContextUser().getPassword()
                    , queryParamMap, headerMap, null
            );
    JSONObject obj = new JSONObject(response.getEntity(String.class));
    assertTrue((response.getStatusCode() == Response.Status.OK.getStatusCode()),
            "Wrong status code ,Expected 200 OK ,Received " +
                    response.getStatusCode()
    );
    String jSessionId = obj.getJSONObject("data").getString("sessionId");
    storeCookieHeader = "JSESSIONID=" + jSessionId;
    assertNotNull(jSessionId, "Invalid JSessionID received");
}
 
开发者ID:wso2,项目名称:product-es,代码行数:22,代码来源:RestResourceStoreSearchTestCase.java


注:本文中的org.apache.wink.client.ClientResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。