本文整理汇总了Java中org.jboss.resteasy.client.ClientResponse类的典型用法代码示例。如果您正苦于以下问题:Java ClientResponse类的具体用法?Java ClientResponse怎么用?Java ClientResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClientResponse类属于org.jboss.resteasy.client包,在下文中一共展示了ClientResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomerResource
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@Test
public void testCustomerResource() throws Exception
{
//RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
ClientRequest request = new ClientRequest("http://localhost:9095/customers/1");
ClientResponse<Customer> response = request.get(Customer.class);
Assert.assertEquals(200, response.getStatus());
Customer cust = response.getEntity();
String etag = response.getResponseHeaders().getFirst("ETag");
System.out.println("Doing a conditional GET with ETag: " + etag);
request.clear();
request.header("If-None-Match", etag);
response = request.get(Customer.class);
Assert.assertEquals(304, response.getStatus());
// Update and send a bad etag with conditional PUT
cust.setCity("Bedford");
request.clear();
request.header("If-Match", "JUNK");
request.body("application/xml", cust);
ClientResponse response2 = request.put();
Assert.assertEquals(412, response2.getStatus());
}
示例2: verifyGoogleRecaptcha
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
public static boolean verifyGoogleRecaptcha(String gRecaptchaResponse, String secretKey) {
boolean result = false;
try {
ClientRequest request = new ClientRequest("https://www.google.com/recaptcha/api/siteverify");
request.formParameter("secret", secretKey);
request.formParameter("response", gRecaptchaResponse);
request.accept("application/json");
ClientResponse<String> response = request.post(String.class);
ObjectMapper mapper = new ObjectMapper();
Map<String, String> map = mapper.readValue(new ByteArrayInputStream(
response.getEntity().getBytes()), new TypeReference<Map<String, String>>() {});
return Boolean.parseBoolean(map.get("success"));
} catch (Exception e) {
log.error("Exception happened while verifying recaptcha ", e);
return result;
}
}
示例3: executeCommand
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private List<JaxbCommandResponse<?>> executeCommand(List<Command> commands)
throws Exception {
URL address = new URL(APP_URL + "/rest/execute");
ClientRequest request = createRequest(address);
// NEEDED ON 6.1
request.header(JaxbSerializationProvider.EXECUTE_DEPLOYMENT_ID_HEADER,
DEPLOYMENT_ID);
JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
commandMessage.setCommands(commands);
commandMessage.setDeploymentId(DEPLOYMENT_ID);
String body = convertJaxbObjectToString(commandMessage);
System.out.println(body);
request.body(MediaType.APPLICATION_XML, body);
ClientResponse<String> responseObj = request.post(String.class);
String strResponse = responseObj.getEntity();
System.out.println("RESPONSE FROM THE SERVER: \n" + strResponse);
JaxbCommandsResponse cmdsResp = convertStringToJaxbObject(strResponse);
return cmdsResp.getResponses();
}
示例4: testMetadataVisibility
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@Test
public void testMetadataVisibility() throws Exception {
Client client = mockClient2();
MockProvider.CLIENT = client;
StringWriter sw = new StringWriter();
EdmxFormatWriter.write(client.getMetadata(), sw);
ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/$metadata"));
ClientResponse<String> response = request.get(String.class);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(sw.toString(), response.getEntity());
String edm = "<?xml version=\"1.0\" encoding=\"utf-8\"?><edmx:Edmx Version=\"1.0\" xmlns:edmx=\"http://schemas.microsoft.com/ado/2007/06/edmx\"><edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\"></edmx:DataServices></edmx:Edmx>";
Assert.assertEquals(edm, response.getEntity());
}
示例5: testProjectedColumns
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@Test
public void testProjectedColumns() throws Exception {
Client client = mockClient();
MockProvider.CLIENT = client;
ArgumentCaptor<Query> sql = ArgumentCaptor.forClass(Query.class);
ArgumentCaptor<EdmEntitySet> entitySet = ArgumentCaptor.forClass(EdmEntitySet.class);
OEntity entity = createCustomersEntity(client.getMetadata());
ArrayList<OEntity> list = new ArrayList<OEntity>();
list.add(entity);
EntityList result = Mockito.mock(EntityList.class);
when(result.get(0)).thenReturn(entity);
when(result.size()).thenReturn(1);
when(result.iterator()).thenReturn(list.iterator());
when(client.executeSQL(any(Query.class), anyListOf(SQLParam.class), any(EdmEntitySet.class), (LinkedHashMap<String, Boolean>) any(), any(QueryInfo.class))).thenReturn(result);
ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/Customers?$select=CustomerID,CompanyName,Address"));
ClientResponse<String> response = request.get(String.class);
verify(client).executeSQL(sql.capture(), anyListOf(SQLParam.class), entitySet.capture(), (LinkedHashMap<String, Boolean>) any(), any(QueryInfo.class));
Assert.assertEquals("SELECT g0.CustomerID, g0.CompanyName, g0.Address FROM nw.Customers AS g0 ORDER BY g0.CustomerID", sql.getValue().toString());
Assert.assertEquals(200, response.getStatus());
//Assert.assertEquals("", response.getEntity());
}
示例6: testProcedure
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@Test
public void testProcedure() throws Exception {
Client client = mockClient();
MockProvider.CLIENT = client;
ArgumentCaptor<String> sql = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<List> params = ArgumentCaptor.forClass(List.class);
when(client.executeCall(any(String.class), anyListOf(SQLParam.class), any(EdmType.class))).thenReturn(Responses.simple(EdmSimpleType.INT32, "return", null));
ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/getCustomers?p2=datetime'2011-09-11T00:00:00'&p3=2.0M"));
ClientResponse<String> response = request.get(String.class);
verify(client).executeCall(sql.capture(), params.capture(), any(EdmType.class));
Assert.assertEquals("{? = call nw.getCustomers(p2=>?,p3=>?)}", sql.getValue().toString());
Assert.assertEquals(TimestampUtil.createTimestamp(111, 8, 11, 0, 0, 0, 0), ((SQLParam)params.getValue().get(0)).value);
Assert.assertEquals(BigDecimal.valueOf(2.0), ((SQLParam)params.getValue().get(1)).value);
Assert.assertEquals(200, response.getStatus());
}
示例7: testSelect
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@Test
public void testSelect() throws Exception {
Client client = mockClient();
MockProvider.CLIENT = client;
ArgumentCaptor<Query> sql = ArgumentCaptor.forClass(Query.class);
ArgumentCaptor<EdmEntitySet> entitySet = ArgumentCaptor.forClass(EdmEntitySet.class);
OEntity entity = createCustomersEntity(client.getMetadata());
ArrayList<OEntity> list = new ArrayList<OEntity>();
list.add(entity);
EntityList result = Mockito.mock(EntityList.class);
when(result.get(0)).thenReturn(entity);
when(result.size()).thenReturn(1);
when(result.iterator()).thenReturn(list.iterator());
when(client.executeSQL(any(Query.class), anyListOf(SQLParam.class), any(EdmEntitySet.class), (LinkedHashMap<String, Boolean>) any(), any(QueryInfo.class))).thenReturn(result);
ClientRequest request = new ClientRequest(TestPortProvider.generateURL("/odata/northwind/Customers?$select=CustomerID,CompanyName,Address"));
ClientResponse<String> response = request.get(String.class);
verify(client).executeSQL(sql.capture(), anyListOf(SQLParam.class), entitySet.capture(), (LinkedHashMap<String, Boolean>) any(), any(QueryInfo.class));
Assert.assertEquals("SELECT g0.CustomerID, g0.CompanyName, g0.Address FROM nw.Customers AS g0 ORDER BY g0.CustomerID", sql.getValue().toString());
Assert.assertEquals(200, response.getStatus());
}
示例8: main
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// first get the create URL for the shipping queue
ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
ClientResponse res = request.head();
Link create = res.getHeaderAsLink("msg-create");
System.out.println("Send order...");
Order order = new Order();
order.setName("Bill");
order.setItem("iPhone4");
order.setAmount("$199.99");
res = create.request().body("application/xml", order).post();
if (res.getStatus() != 201)
throw new RuntimeException("Failed to post");
}
示例9: NubankImportador
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
public NubankImportador(){
ClientConnectionManager cm = new ThreadSafeClientConnManager();
DefaultHttpClient httpClient = new DefaultHttpClient(cm);
ClientExecutor executor = new ApacheHttpClient4Executor(httpClient);
authApi = ProxyFactory.create(NubankAPI.class, "https://prod-auth.nubank.com.br", executor);
costumersApi = ProxyFactory.create(NubankAPI.class, "https://prod-customers.nubank.com.br", executor);
accountsApi = ProxyFactory.create(NubankAPI.class, "https://prod-accounts.nubank.com.br", executor);
ClientResponse<RegistrationResp> resp = authApi.register(RegistrationReq.asNubank());
if(resp.getStatus() != RegistrationResp.SUCCESS_CODE){
throw new RuntimeException("Erro registrando api. Status code = "+resp.getStatus());
// System.out.println(resp.getEntity().getClient_id());
// System.out.println(resp.getEntity().getClient_secret());
}
this.regResp = resp.getEntity();
// api.token(TokenReq.create(resp.getEntity()));
}
示例10: executeCommand
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
static List<JaxbCommandResponse<?>> executeCommand(String deploymentId,
List<Command> commands) throws Exception {
URL address = new URL(APP_URL + "/execute");
ClientRequest request = createRequest(address);
// NEEDED ON 6.1
request.header(JaxbSerializationProvider.EXECUTE_DEPLOYMENT_ID_HEADER, DEPLOYMENT_ID);
JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
commandMessage.setCommands(commands);
commandMessage.setDeploymentId(DEPLOYMENT_ID);
String body = convertJaxbObjectToString(commandMessage);
request.body(MediaType.APPLICATION_XML, body);
ClientResponse<String> responseObj = request.post(String.class);
String strResponse = responseObj.getEntity();
System.out.println("RESPONSE FROM THE SERVER: \n" + strResponse);
JaxbCommandsResponse cmdsResp = convertStringToJaxbObject(strResponse);
return cmdsResp.getResponses();
}
示例11: initialize
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
protected void initialize() throws Exception {
super.start();
initialized = true;
initAuthentication();
ClientRequest request = executor.createRequest(registration.getTarget().getHref());
for (XmlHttpHeader header : registration.getHeaders()) {
request.header(header.getName(), header.getValue());
}
ClientResponse<?> res = request.head();
if (res.getStatus() != 200) {
throw new RuntimeException("Failed to query REST destination for init information. Status: " + res.getStatus());
}
String url = (String) res.getHeaders().getFirst("msg-create-with-id");
if (url == null) {
if (res.getLinkHeader() == null) {
throw new RuntimeException("Could not find create-with-id URL");
}
Link link = res.getLinkHeader().getLinkByTitle("create-with-id");
if (link == null) {
throw new RuntimeException("Could not find create-with-id URL");
}
url = link.getHref();
}
targetUri = ResteasyUriBuilder.fromTemplate(url);
}
示例12: handle
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
public void handle(ClientResponse response) throws RuntimeException {
try {
BaseClientResponse r = (BaseClientResponse) response;
InputStream stream = r.getStreamFactory().getInputStream();
if (stream != null) {
stream.reset();
}
if ((response.getResponseStatus() != null) && (response.getResponseStatus().getStatusCode() == 404)
&& !(r.getException() instanceof ItemNotFoundException)) {
throw new WebApplicationException(Response
.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(new ApiError("Error at " + response.getHeaders().get("full-path")))
.build());
}
} catch (IOException e){
//...
}
}
示例13: executeCommand
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
static List<JaxbCommandResponse<?>> executeCommand(String deploymentId,
List<Command> commands) throws Exception {
URL address = new URL(APP_URL + "/rest/execute");
ClientRequest request = createRequest(address);
// NEEDED ON 6.1
request.header(JaxbSerializationProvider.EXECUTE_DEPLOYMENT_ID_HEADER, DEPLOYMENT_ID);
JaxbCommandsRequest commandMessage = new JaxbCommandsRequest();
commandMessage.setCommands(commands);
commandMessage.setDeploymentId(DEPLOYMENT_ID);
String body = convertJaxbObjectToString(commandMessage);
request.body(MediaType.APPLICATION_XML, body);
ClientResponse<String> responseObj = request.post(String.class);
String strResponse = responseObj.getEntity();
System.out.println("RESPONSE FROM THE SERVER: \n" + strResponse);
JaxbCommandsResponse cmdsResp = convertStringToJaxbObject(strResponse);
return cmdsResp.getResponses();
}
示例14: main
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
// first get the create URL for the shipping queue
ClientRequest request = new ClientRequest("http://localhost:8080/queues/orders");
ClientResponse res = request.head();
Link pullConsumers = res.getHeaderAsLink("msg-pull-consumers");
res.releaseConnection();
res = pullConsumers.request().post();
Link consumeNext = res.getHeaderAsLink("msg-consume-next");
res.releaseConnection();
while (true) {
System.out.println("Waiting...");
res = consumeNext.request().header("Accept-Wait", "10").post();
if (res.getStatus() == 503) {
System.out.println("Timeout...");
consumeNext = res.getHeaderAsLink("msg-consume-next");
} else if (res.getStatus() == 200) {
Order order = (Order) res.getEntity(Order.class);
System.out.println(order);
consumeNext = res.getHeaderAsLink("msg-consume-next");
} else {
throw new RuntimeException("Failure! " + res.getStatus());
}
res.releaseConnection();
}
}
示例15: bioViaJson
import org.jboss.resteasy.client.ClientResponse; //导入依赖的package包/类
@Test
public void bioViaJson() throws Exception{
String jsonBodyRequest = "{\n" +
" \"id\": \"303021\",\n" +
" \"names\": [\n" +
" {\n" +
" \"firstName\": \"You First\",\n" +
" \"lastName\": \"Me Last\"\n" +
" }\n" +
" ]\n" +
"}";
givenThat(WireMock.get(urlEqualTo("/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", APPLICATION_JSON)
.withBody(jsonBodyRequest)));
ApacheHttpClientExecutor httpClientExecutor = new ApacheHttpClientExecutor();
ClientRequest clientExecutor = httpClientExecutor.createRequest("http://localhost:9073/identitymanagement-services/identitymanagement-services/person/internalHandle/person_id_009/biographics/default");
clientExecutor.setHttpMethod("GET");
ClientResponse serverResponse = clientExecutor.execute();
final String respBodyAsString = (String)serverResponse.getEntity(String.class);
JSONAssert.assertEquals(jsonBodyRequest, respBodyAsString, true);
System.out.println("### bio response from mapping: \n" + respBodyAsString);
}