ClientResource cr = new ClientResource("http://.../getlistofobjects"); cr.accept(MediaType.APPLICATION_JSON); MyService myService = cr.wrap(MyService.class); List<MyObject> objs = myService.getObjs();
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
public static ClientResource createAuthenticatedClientResource(String url, String userName, String password) { ClientResource cr = new ClientResource(url); cr.setNext(client); cr.accept(MediaType.APPLICATION_JSON); if (!StringUtils.isNullOrEmpty(userName) && !StringUtils.isNullOrEmpty(password)) { cr.setChallengeResponse(ChallengeScheme.HTTP_BASIC, userName, password); } return cr; }
@Override public ResponseEntity uploadOctetStream(String urn, java.io.File file, MediaType mediaType) throws ServiceException { ResponseEntity response; FileRepresentation fileRepresentation = new FileRepresentation(file, mediaType); fileRepresentation.setMediaType(MediaType.APPLICATION_OCTET_STREAM); ClientResource service = createClient(FileEndpoints.uploadContentsAsOctetStream(urn)); service.accept(MediaType.APPLICATION_JSON); try { Representation result = service.post(fileRepresentation); JsonRepresentation jsonRepresentation = new JsonRepresentation(result); JSONObject jsonResult = jsonRepresentation.getJsonObject(); response = JsonUtil.fromJson(jsonResult, ResponseEntity.class); if (service.getStatus().equals(Status.SUCCESS_OK)) { LOGGER.info("Successfully uploaded file to path {}", FileEndpoints.uploadContentsAsMultipart(urn)); } else { LOGGER.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode()); throw new ServiceException(response); } } catch (JSONException | IOException e) { LOGGER.error("Unexpected Exception", e); throw new ServiceException(e); } return response; }
service.accept(MediaType.APPLICATION_JSON);
clientResource.accept(MediaType.APPLICATION_JSON);
clientResource.accept(MediaType.APPLICATION_JSON);
clientResource.accept(MediaType.APPLICATION_JSON);
clientResource.accept(MediaType.APPLICATION_JSON);
clientResource.accept(MediaType.APPLICATION_JSON);
service.accept(MediaType.APPLICATION_JSON);