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


Java Entity类代码示例

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


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

示例1: testPost

import javax.ws.rs.client.Entity; //导入依赖的package包/类
/**
 * Tests creating an intent with POST.
 */
@Test
public void testPost() {
    ApplicationId testId = new DefaultApplicationId(2, "myApp");
    expect(mockCoreService.getAppId("myApp"))
            .andReturn(testId);
    replay(mockCoreService);

    mockIntentService.submit(anyObject());
    expectLastCall();
    replay(mockIntentService);

    InputStream jsonStream = IntentsResourceTest.class
            .getResourceAsStream("post-intent.json");
    WebTarget wt = target();

    Response response = wt.path("intents")
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));
    String location = response.getLocation().getPath();
    assertThat(location, Matchers.startsWith("/intents/myApp/"));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:IntentsResourceTest.java

示例2: testNewOwner

import javax.ws.rs.client.Entity; //导入依赖的package包/类
@Test
public void testNewOwner() {
    final Response r1 = target("/owners/new").request().get();
    assertEquals(200, r1.getStatus());
    assertEquals("newowner", ((View) r1.getEntity()).getTemplateName());

    final Form form = new Form()
            .param("name", "Barack Obama")
            .param("address", "1600 Penn Ave")
            .param("city", "Washington DC")
            .param("telephone", "800-555-5555");

    final Response r2 = target("/owners/new").request().post(Entity.form(form));
    assertNotNull(r2);
    assertEquals(303, r2.getStatus());
    assertNotNull(r2.getHeaderString("Location"));

    final Response r3 = target(r2.getHeaderString("Location")).request().get();
    assertNotNull(r3);
    assertEquals(200, r3.getStatus());

    final View view = (View) r3.getEntity();
    final Owner owner = (Owner) view.getModel().get("owner");
    assertEquals("Barack Obama", owner.getName());
}
 
开发者ID:minijax,项目名称:minijax,代码行数:26,代码来源:OwnersResourceTest.java

示例3: getFormPostResponse

import javax.ws.rs.client.Entity; //导入依赖的package包/类
protected final Response getFormPostResponse(String data,
                                             String endpoint,
                                             Class<? extends OutputStream> compressingClass,
                                             String encoding) throws IOException {
  byte[] bytes;
  if (compressingClass == null) {
    bytes = data.getBytes(StandardCharsets.UTF_8);
  } else {
    bytes = compress(data, compressingClass);
  }
  MediaType type =
      encoding == null ? MediaType.TEXT_PLAIN_TYPE : new MediaType("application", encoding);
  InputStream in = new ByteArrayInputStream(bytes);
  StreamDataBodyPart filePart = new StreamDataBodyPart("data", in, "data", type);
  try (MultiPart multiPart = new MultiPart(MediaType.MULTIPART_FORM_DATA_TYPE)) {
    multiPart.getBodyParts().add(filePart);
    return target(endpoint).request().post(
        Entity.entity(multiPart, MediaType.MULTIPART_FORM_DATA_TYPE));
  }
}
 
开发者ID:oncewang,项目名称:oryx2,代码行数:21,代码来源:AbstractServingTest.java

示例4: triggerStationState

import javax.ws.rs.client.Entity; //导入依赖的package包/类
/**
 * Calls a state alteration method for one station.
 * @param station the station to undelete/delete from the REST service.
 * @param path the URL path of the state alteration endpoint.
 * @see <a href="http://www.radio-browser.info/webservice#station_delete">
 *     The API endpoint</a>
 */
private void triggerStationState(final Station station,
                                 final String path) {
    Objects.requireNonNull(station, "station must be non-null");
    MultivaluedMap<String, String> requestParams =
            new MultivaluedHashMap<>();

    Entity entity = Entity.form(requestParams);

    Response response = null;

    try {
        response = builder(webTarget
                    .path(path)
                    .path(station.getId()))
                .post(entity);
        logResponseStatus(response);
        UrlResponse urlResponse = response.readEntity(
                UrlResponse.class);
        if (!urlResponse.isOk()) {
            throw new RadioBrowserException(urlResponse.getMessage());
        }
    } finally {
        close(response);
    }
}
 
开发者ID:sfuhrm,项目名称:radiobrowser4j,代码行数:33,代码来源:RadioBrowser.java

示例5: registerUser

import javax.ws.rs.client.Entity; //导入依赖的package包/类
private static void registerUser(String url, MediaType mediaType) {
    System.out.println("Registering user via " + url);
    User user = new User(1L, "larrypage");
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target(url);
    Response response = target.request().post(Entity.entity(user, mediaType));

    try {
        if (response.getStatus() != 200) {
            throw new RuntimeException("Failed with HTTP error code : " + response.getStatus());
        }
        System.out.println("Successfully got result: " + response.readEntity(String.class));
    } finally {
        response.close();
        client.close();
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:18,代码来源:RestClient.java

示例6: placeOrder

import javax.ws.rs.client.Entity; //导入依赖的package包/类
/**
 * Persists order in database.
 * @param blob Sessionblob
 * @param addressName adress
 * @param address1 adress
 * @param address2 adress
 * @param creditCardCompany creditcard
 * @param creditCardExpiryDate creditcard
 * @param creditCardNumber creditcard
 * @param totalPriceInCents totalPrice
 * @throws NotFoundException If 404 was returned.
 * @throws LoadBalancerTimeoutException On receiving the 408 status code
    * and on repeated load balancer socket timeouts.
 * @return empty SessionBlob
 */
public static SessionBlob placeOrder(SessionBlob blob, String addressName, String address1, 
		String address2, String creditCardCompany, String creditCardExpiryDate, long totalPriceInCents,
		String creditCardNumber) throws NotFoundException, LoadBalancerTimeoutException {
	Response r = ServiceLoadBalancer.loadBalanceRESTOperation(Service.STORE,
			"useractions", Product.class, client -> client.getService().path(client.getApplicationURI())
			.path(client.getEndpointURI()).path("placeorder")
			.queryParam("addressName", addressName)
			.queryParam("address1", address1)
			.queryParam("address2", address2)
			.queryParam("creditCardCompany", creditCardCompany)
			.queryParam("creditCardNumber", creditCardNumber)
			.queryParam("creditCardExpiryDate", creditCardExpiryDate)
			.queryParam("totalPriceInCents", totalPriceInCents)
			.request(MediaType.APPLICATION_JSON)
			.accept(MediaType.APPLICATION_JSON)
			.post(Entity.entity(blob, MediaType.APPLICATION_JSON), Response.class));
	throwCommonExceptions(r);
	return readEntityOrNull(r, SessionBlob.class);
}
 
开发者ID:DescartesResearch,项目名称:Pet-Supply-Store,代码行数:35,代码来源:LoadBalancedStoreOperations.java

示例7: putObject

import javax.ws.rs.client.Entity; //导入依赖的package包/类
/**
 * Execute a PUT method on an object
 *
 * @param object the object to put
 * @return the response
 */
@PublicAtsApi
public RestResponse putObject( Object object ) {

    // execute PUT
    Invocation.Builder invocationBuilder = constructInvocationBuilder("PUT object to");
    RestResponse response;
    if (object != null) {
        if (StringUtils.isNullOrEmpty(requestMediaType)) {
            throw new RestException("Content type is not set! Content type is mandatory for PUT.");
        }
        response = new RestResponse(invocationBuilder.method("PUT",
                                                             Entity.entity(getActualBodyObject(object),
                                                                           RestMediaType.toMediaType(requestMediaType,
                                                                                                     requestMediaCharset)),
                                                             Response.class));
    } else {
        response = new RestResponse(invocationBuilder.method("PUT", Response.class));
    }

    logRESTResponse(response);
    initInternalVariables();

    // return response
    return response;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:32,代码来源:RestClient.java

示例8: testAddRolesWithValidRequestObject

import javax.ws.rs.client.Entity; //导入依赖的package包/类
@Test
public void testAddRolesWithValidRequestObject()
{
    AppCreateDTO request = new AppCreateDTO();

    Set<String> roles = new HashSet<>();
    roles.add(roleName);
    request.setColor("Green");
    request.setRoles(roles);

    Role role = new Role(roleName);
    Mockito.when(rolesDAO.save(role)).thenReturn(role);

    Response response = resources.client().target(rolesUrl).request().post(Entity.json(request));
    ResponseValidator.validate(response, 201);
}
 
开发者ID:tosinoni,项目名称:SECP,代码行数:17,代码来源:AdminResourceTest.java

示例9: executeAction

import javax.ws.rs.client.Entity; //导入依赖的package包/类
private Result executeAction(Action action, Object lraInfo, String lraUri) {
    log.infof("executing action - %s", action);

    Client client = ClientBuilder.newClient();
    URI build = UriBuilder
            .fromUri(servicesLocator.getServiceUri(action.getService()))
            .path(API_PREFIX)
            .path(action.getType().getPath())
            .build();
    log.info("action request url - " + build);
    WebTarget target = client.target(build);

    Response response = target.request().header(LRAClient.LRA_HTTP_HEADER, lraUri).post(Entity.json(lraInfo));
    log.info("Result of action - " + response.readEntity(String.class));

    Result result = response.getStatus() == Response.Status.OK.getStatusCode() ? Result.COMPLETED : Result.NEED_COMPENSATION;

    response.close();

    return result;
}
 
开发者ID:xstefank,项目名称:lra-service,代码行数:22,代码来源:LRAExecutor.java

示例10: resize

import javax.ws.rs.client.Entity; //导入依赖的package包/类
public void resize(String clusterId, Integer minWorkers, Integer maxWorkers) throws HttpException {
    ClusterInfoDTO cluster = new ClusterInfoDTO();
    cluster.ClusterId = clusterId;

    AutoScaleDTO autoScaleDTOSettings = new AutoScaleDTO();
    autoScaleDTOSettings.MinWorkers = minWorkers;
    autoScaleDTOSettings.MaxWorkers = maxWorkers;

    cluster.AutoScale = autoScaleDTOSettings;

    Response response = _target.path("resize")
            .register(Session.Authentication)
            .request(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(cluster));

    // check response status code
    checkResponse(response, "InteractiveCluster " + clusterId + " is not in a RUNNING state");
}
 
开发者ID:level11data,项目名称:databricks-client-java,代码行数:19,代码来源:ClustersClient.java

示例11: testExecute_WithUpdateInspectionPort_ExpectErrorCode

import javax.ws.rs.client.Entity; //导入依赖的package包/类
@Test
public void testExecute_WithUpdateInspectionPort_ExpectErrorCode() {
    // Assume.
    Response response = null;
    try {

        InspectionPortElement inspectionPort = createInspectionPortEntity();
        Entity<InspectionPortElement> entity = Entity.entity(inspectionPort, MediaType.APPLICATION_JSON);

        String badParam = "IdNotMatching";
        // Act.
        response = target("controller/1.2.3.0/inspectionPorts/" + badParam)
                .request()
                .header(this.AUTHORIZATION_HEADER, this.AUTHORIZATION_CREDS)
                .put(entity);
        response.close();

        // Assert.
        assertThat(response.getStatus()).isEqualTo(500);

    } finally {
        if (response != null) {
            response.close();
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:sdn-controller-nsc-plugin,代码行数:27,代码来源:InspectionPortApisTest.java

示例12: testPostVirtualDevice

import javax.ws.rs.client.Entity; //导入依赖的package包/类
/**
 * Tests adding of new virtual device using POST via JSON stream.
 */
@Test
public void testPostVirtualDevice() {
    NetworkId networkId = networkId3;
    DeviceId deviceId = devId2;
    expect(mockVnetAdminService.createVirtualDevice(networkId, deviceId)).andReturn(vdev2);
    expectLastCall();

    replay(mockVnetAdminService);

    WebTarget wt = target();
    InputStream jsonStream = VirtualNetworkWebResourceTest.class
            .getResourceAsStream("post-virtual-device.json");
    String reqLocation = "vnets/" + networkId.toString() + "/devices";
    Response response = wt.path(reqLocation).request(MediaType.APPLICATION_JSON_TYPE)
            .post(Entity.json(jsonStream));
    assertThat(response.getStatus(), is(HttpURLConnection.HTTP_CREATED));

    String location = response.getLocation().getPath();
    assertThat(location, Matchers.startsWith("/" + reqLocation + "/" + vdev2.id().toString()));

    verify(mockVnetAdminService);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:VirtualNetworkWebResourceTest.java

示例13: makePost_checkProcessingExceptionIsThrown

import javax.ws.rs.client.Entity; //导入依赖的package包/类
@Test
public void makePost_checkProcessingExceptionIsThrown() throws IOException, SAXException,
        ParserConfigurationException, URISyntaxException, SOAPRequestError {
    ProcessingException exception = mock(ProcessingException.class);
    when(webResourceBuilder.post(any(Entity.class))).thenThrow(exception);
    Element matchingServiceRequest = XmlUtils.convertToElement("<someElement/>");
    URI matchingServiceUri = new URI("http://heyyeyaaeyaaaeyaeyaa.com/abc1");

    try {
        soapRequestClient.makeSoapRequest(matchingServiceRequest, matchingServiceUri);
        fail("Exception should have been thrown");
    }
    catch(ProcessingException e) {
        assertThat(e).isEqualTo(exception);
    }
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:17,代码来源:SoapRequestClientTest.java

示例14: testTestApis

import javax.ws.rs.client.Entity; //导入依赖的package包/类
@Test
@Ignore // TODO DX-3144
public void testTestApis() {
  doc("Creating test dataset");
  NamespaceService ns = newNamespaceService();
  expectSuccess(getBuilder(getAPIv2().path("/test/create")).buildPost(Entity.json("")));
  assertEquals(4, ns.getSpaces().size());
  assertEquals(1, ns.getHomeSpaces().size());
  doc("Clearing all data");
  expectSuccess(getBuilder(getAPIv2().path("/test/clear")).buildPost(Entity.json("")));
  assertEquals(0, ns.getSpaces().size());
  assertEquals(0, ns.getHomeSpaces().size());
  expectSuccess(getBuilder(getAPIv2().path("/test/create")).buildPost(Entity.json("")));
  assertEquals(4, ns.getSpaces().size());
  assertEquals(1, ns.getHomeSpaces().size());
  expectSuccess(getBuilder(getAPIv2().path("/test/clear")).buildPost(Entity.json("")));
  assertEquals(0, ns.getSpaces().size());
  assertEquals(0, ns.getHomeSpaces().size());
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:20,代码来源:TestServer.java

示例15: portDown

import javax.ws.rs.client.Entity; //导入依赖的package包/类
private boolean portDown(String switchName, String portNo) throws Throwable {
    System.out.println("\n==> Set Port Down");

    long current = System.currentTimeMillis();
    Client client = ClientBuilder.newClient(new ClientConfig());
    Response result = client
            .target(trafficEndpoint)
            .path("/port/down")
            .queryParam("switch", switchName)
            .queryParam("port", portNo)
            .request()
            .post(Entity.json(""));

    System.out.println(String.format("===> Response = %s", result.toString()));
    System.out.println(String.format("===> Set Port Down Time: %,.3f", getTimeDuration(current)));

    return result.getStatus() == 200;
}
 
开发者ID:telstra,项目名称:open-kilda,代码行数:19,代码来源:FlowFFRTest.java


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