protected Object deserialize(Object root) throws ResourceException { Object result = null; if (root != null) { if (String.class.isAssignableFrom(root.getClass())) { try { result = getRequest().getEntity().getText(); } catch (IOException e) { throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "Cannot get the representation!", e); } } XStreamRepresentation representation = createRepresentation(getRequest().getEntity()); if (representation != null) { try { result = representation.getPayload(root); } catch (XStreamException e) { logger.warn( "Invalid XML, unable to parse using XStream {}", (delegate == null ? "" : delegate.getClass()), e); throw new ResourceException( Status.CLIENT_ERROR_BAD_REQUEST, "Invalid XML, unable to parse using XStream", e); } } } return result; }
public Object sendMessage(Method method, String url, NexusResponse nexusResponse) throws NexusConnectionException { XStreamRepresentation representation = new XStreamRepresentation(this.xstream, "", MediaType.APPLICATION_XML); // now set the payload representation.setPayload(nexusResponse); return this.sendMessage(method, url, representation); }
private boolean isEnabled() throws Exception { String responseText = RequestFacade.doGetForText("service/local/lvo_config"); XStreamRepresentation representation = new XStreamRepresentation(getXMLXStream(), responseText, MediaType.APPLICATION_XML); LvoConfigResponse resp = (LvoConfigResponse) representation.getPayload(new LvoConfigResponse()); return resp.getData().isEnabled(); }
public LdapConnectionInfoDTO getResourceFromResponse(Response response) throws IOException { String responseString = response.getEntity().getText(); LOG.debug(" getResourceFromResponse: " + responseString); XStreamRepresentation representation = new XStreamRepresentation(xstream, responseString, mediaType); LdapConnectionInfoResponse resourceResponse = (LdapConnectionInfoResponse) representation.getPayload(new LdapConnectionInfoResponse()); return resourceResponse.getData(); }
public RepositoryRouteResource getResourceFromText(String responseString) { assertThat(responseString, not(IsEmptyString.isEmptyOrNullString())); XStreamRepresentation representation = new XStreamRepresentation(xstream, responseString, mediaType); RepositoryRouteResourceResponse resourceResponse = (RepositoryRouteResourceResponse) representation.getPayload(new RepositoryRouteResourceResponse()); return resourceResponse.getData(); }
public RepositoryTargetResource getResourceFromResponse(String responseText) throws IOException { LOG.debug(" getResourceFromResponse: " + responseText); XStreamRepresentation representation = new XStreamRepresentation(xstream, responseText, mediaType); RepositoryTargetResourceResponse resourceResponse = (RepositoryTargetResourceResponse) representation.getPayload(new RepositoryTargetResourceResponse()); return resourceResponse.getData(); }
private List<PlexusComponentListResource> getResult( String role, XStream xstream, MediaType mediaType) throws IOException { String responseString = this.sendMessage(role, xstream, mediaType).getEntity().getText(); XStreamRepresentation representation = new XStreamRepresentation(xstream, responseString, mediaType); PlexusComponentListResourceResponse resourceResponse = (PlexusComponentListResourceResponse) representation.getPayload(new PlexusComponentListResourceResponse()); return resourceResponse.getData(); }
@SuppressWarnings("unchecked") public static List<RepositoryRouteListResource> getList() throws IOException { String serviceURI = "service/local/repo_routes"; String entityText = RequestFacade.doGetForText(serviceURI); XStreamRepresentation representation = new XStreamRepresentation( XStreamFactory.getXmlXStream(), entityText, MediaType.APPLICATION_XML); RepositoryRouteListResourceResponse resourceResponse = (RepositoryRouteListResourceResponse) representation.getPayload(new RepositoryRouteListResourceResponse()); return resourceResponse.getData(); }
public Response sendMessage(Method method, RepositoryTargetResource resource) throws IOException { XStreamRepresentation representation = new XStreamRepresentation(xstream, "", mediaType); String repoTargetId = (resource.getId() == null) ? "?undefined" : "/" + resource.getId(); String serviceURI = "service/local/repo_targets" + repoTargetId; RepositoryTargetResourceResponse requestResponse = new RepositoryTargetResourceResponse(); requestResponse.setData(resource); // now set the payload representation.setPayload(requestResponse); return RequestFacade.sendMessage(serviceURI, method, representation); }
public static RepositoryTargetResource get(String targetId) throws IOException { String responseText = RequestFacade.doGetRequest("service/local/repo_targets/" + targetId).getEntity().getText(); LOG.debug("responseText: \n" + responseText); XStreamRepresentation representation = new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML); RepositoryTargetResourceResponse resourceResponse = (RepositoryTargetResourceResponse) representation.getPayload(new RepositoryTargetResourceResponse()); return resourceResponse.getData(); }
public RepositoryBaseResource getTemplate(String id) throws IOException { String responseText = RequestFacade.doGetForText("service/local/templates/repositories/" + id, not(inError())); LOG.debug("responseText: \n" + responseText); XStreamRepresentation representation = new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML); RepositoryResourceResponse resourceResponse = (RepositoryResourceResponse) representation.getPayload(new RepositoryResourceResponse()); return resourceResponse.getData(); }
public Response sendTestMessage(LdapConnectionInfoDTO resource) throws IOException { XStreamRepresentation representation = new XStreamRepresentation(xstream, "", mediaType); String serviceURI = RequestFacade.SERVICE_LOCAL + "ldap/test_auth"; LdapConnectionInfoResponse repoResponseRequest = new LdapConnectionInfoResponse(); repoResponseRequest.setData(resource); // now set the payload representation.setPayload(repoResponseRequest); LOG.debug("sendMessage: " + representation.getText()); return RequestFacade.sendMessage(serviceURI, Method.PUT, representation); }
public static Status changePassword(String username, String newPassword) throws Exception { String serviceURI = "service/local/users_setpw"; UserChangePasswordResource resource = new UserChangePasswordResource(); resource.setUserId(username); resource.setNewPassword(newPassword); UserChangePasswordRequest request = new UserChangePasswordRequest(); request.setData(resource); XStreamRepresentation representation = new XStreamRepresentation(xstream, "", MediaType.APPLICATION_XML); representation.setPayload(request); return RequestFacade.doPostForStatus(serviceURI, representation); }
/** IMPORTANT: Make sure to release the Response in a finally block when you are done with it. */ public Response sendMessage(Method method, RepositoryRouteResource resource) throws IOException { XStreamRepresentation representation = new XStreamRepresentation(xstream, "", mediaType); String resourceId = (resource.getId() == null) ? "" : "/" + resource.getId(); String serviceURI = "service/local/repo_routes" + resourceId; if (method != Method.GET || method != Method.DELETE) { RepositoryRouteResourceResponse requestResponse = new RepositoryRouteResourceResponse(); requestResponse.setData(resource); // now set the payload representation.setPayload(requestResponse); } return RequestFacade.sendMessage(serviceURI, method, representation); }
protected Representation serialize(Variant variant, Object payload) throws ResourceException { if (payload == null) { return null; } XStreamRepresentation result = createRepresentation(variant); if (result == null) { throw new ResourceException( Status.CLIENT_ERROR_NOT_ACCEPTABLE, "The requested mediaType='" + variant.getMediaType() + "' is unsupported!"); } result.setPayload(payload); return result; }
private void updateConfig(boolean enabled) throws Exception { XStreamRepresentation representation = new XStreamRepresentation(getJsonXStream(), "", MediaType.APPLICATION_JSON); LvoConfigRequest request = new LvoConfigRequest(); LvoConfigDTO dto = new LvoConfigDTO(); dto.setEnabled(enabled); request.setData(dto); representation.setPayload(request); Assert.assertTrue( RequestFacade.sendMessage("service/local/lvo_config", Method.PUT, representation) .getStatus() .isSuccess()); }
public UserAccount updateAccount(UserAccount dto) throws IOException { String serviceURI = BASE_URL + dto.getUserId(); XStreamRepresentation representation = new XStreamRepresentation(xmlXstream, "", MediaType.APPLICATION_XML); UserAccountRequestResponseWrapper requestDTO = new UserAccountRequestResponseWrapper(); requestDTO.setData(dto); representation.setPayload(requestDTO); LOGGER.info("HTTP PUT: '" + serviceURI + "'"); Response response = RequestFacade.sendMessage(serviceURI, Method.PUT, representation); return readAccount(response); }
public Response sendMessage(Method method, LdapUserAndGroupConfigurationDTO resource) throws IOException { XStreamRepresentation representation = new XStreamRepresentation(xstream, "", mediaType); String serviceURI = SERVICE_PART; LdapUserAndGroupConfigurationResponse repoResponseRequest = new LdapUserAndGroupConfigurationResponse(); repoResponseRequest.setData(resource); // now set the payload representation.setPayload(repoResponseRequest); LOG.debug("sendMessage: " + representation.getText()); return RequestFacade.sendMessage(serviceURI, method, representation); }
private UserAccount readAccount(Response response) throws IOException { if (response.getStatus().isSuccess()) { String responseText = response.getEntity().getText(); LOGGER.debug("Response Text: \n" + responseText); XStreamRepresentation representation = new XStreamRepresentation(xmlXstream, responseText, MediaType.APPLICATION_XML); UserAccountRequestResponseWrapper responseDTO = (UserAccountRequestResponseWrapper) representation.getPayload(new UserAccountRequestResponseWrapper()); return responseDTO.getData(); } else { LOGGER.warn("HTTP Error: '" + response.getStatus().getCode() + "'"); LOGGER.warn(response.getEntity().getText()); return null; } }
private List<ClientPermission> getPermissions() throws IOException { Response response = RequestFacade.sendMessage(RequestFacade.SERVICE_LOCAL + "authentication/login", Method.GET); String responseText = response.getEntity().getText(); if (response.getStatus().isError()) { Assert.fail(response.getStatus() + "\n" + responseText); } XStreamRepresentation representation = new XStreamRepresentation( XStreamFactory.getXmlXStream(), responseText, MediaType.APPLICATION_XML); AuthenticationLoginResourceResponse resourceResponse = (AuthenticationLoginResourceResponse) representation.getPayload(new AuthenticationLoginResourceResponse()); AuthenticationLoginResource resource = resourceResponse.getData(); return resource.getClientPermissions().getPermissions(); }
private void test(String query, String expected) throws IOException { String serviceURIpart = "service/local/lucene/search?q=" + URLEncoder.encode(query, "UTF-8"); log.info("Testing query {}: {}", query, serviceURIpart); String errorPayload = RequestFacade.doGetForText(serviceURIpart, respondsWithStatusCode(400)); log.info("Received 'Bad Request' error: " + errorPayload); MediaType type = MediaType.APPLICATION_XML; XStreamRepresentation representation = new XStreamRepresentation(getXMLXStream(), errorPayload, type); ErrorResponse payload = (ErrorResponse) representation.getPayload(new ErrorResponse()); List errors = payload.getErrors(); assertThat((Collection<?>) errors, hasSize(1)); ErrorMessage error = (ErrorMessage) errors.get(0); String msg = error.getMsg(); msg = msg.replaceAll("Cannot parse '([^']*)':.*", "$1"); log.info("msg: " + msg); assertThat(msg, equalTo(expected)); }