public static String testUpdateAssetAttributes_invalidAsset() { UpdateAssetAttributesConsumer updateAssetAttributesConsumer = new UpdateAssetAttributesConsumer(); int updatedAttributesCount = 3; Properties props = CommonUtil.loadPropertyFile("properties/common.properties"); Library library = new Library(); String libraryId = props.getProperty("libraryId"); String libraryName = props.getProperty("libraryName", "GovernedAssets"); library.setLibraryId(libraryId); library.setLibraryName(libraryName); AssetKey assetKey = new AssetKey(); assetKey.setAssetId(RepositoryServiceClientConstants.INVALID_ASSET_ID); assetKey.setAssetName(RepositoryServiceClientConstants.INVALID_ASSET_NAME); assetKey.setLibrary(library); List<AttributeNameValue> attributeNameValues = new ArrayList<AttributeNameValue>(); AttributeNameValue attributeNameValue = new AttributeNameValue(); attributeNameValue.setAttributeName(RepositoryServiceClientConstants.ATTRIBUTE1_NAME); attributeNameValue.setAttributeValueString(RepositoryServiceClientConstants.ATTRIBUTE1_VALUE); attributeNameValues.add(attributeNameValue); ExtendedAssetInfo extendedAssetInfo = new ExtendedAssetInfo(); extendedAssetInfo.getAttribute().addAll(attributeNameValues); UpdateAssetAttributesRequest updateAssetAttributesRequest = new UpdateAssetAttributesRequest(); updateAssetAttributesRequest.setAssetKey(assetKey); updateAssetAttributesRequest.setExtendedAssetInfo(extendedAssetInfo); updateAssetAttributesRequest.setPartialUpdate(true); updateAssetAttributesRequest.setReplaceCurrent(true); try { UpdateAssetAttributesResponse updateAssetAttributesResponse = updateAssetAttributesConsumer .getProxy() .updateAssetAttributes(updateAssetAttributesRequest); if (updateAssetAttributesResponse == null) { throw new ServiceException(null, "Response object can not be null", null); } if (validateUpdateAssetAttributesResponse(updateAssetAttributesResponse, "negativeCase", 0) .equalsIgnoreCase("success")) { List<CommonErrorData> errorDatas = updateAssetAttributesResponse.getErrorMessage().getError(); System.out.println("The following list of errors occured"); for (CommonErrorData errorData : errorDatas) { System.out.println( "Error id: " + errorData.getErrorId() + " Error message: " + errorData.getMessage()); } return "PASSED"; } else { return "FAILED"; } } catch (ServiceException se) { se.getMessage(); se.printStackTrace(); return "FAILED"; } catch (Exception e) { e.printStackTrace(); return "FAILED"; } }
/* (non-Javadoc) * @see javax.servlet.http.HttpServlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse) */ @SuppressWarnings("unchecked") public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { HttpServletRequest request = (HttpServletRequest) req; HttpServletResponse response = (HttpServletResponse) res; String result = (String) request.getAttribute("RESULT"); Boolean error = (Boolean) request.getAttribute("ERROR"); if (result == null && error == null) { String tmp = request.getRequestURI(); if (request.getQueryString() == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid or empty url"); } else { tmp += "?"; } // eg: admin&admin String[] params = request.getQueryString().split("&"); if (params.length < 2) { response.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid url: " + request.getQueryString()); } final ByteArrayOutputStream importData = parseInputStream(request, response); try { final BasePolicyServiceConsumer consumer = new BasePolicyServiceConsumer(); consumer.getService().getInvokerOptions().setTransportName("HTTP11"); consumer.getService().setSessionTransportHeader(SECURITY_TOKEN_HEADER, SECURITY_TOKEN); if (importData != null) { if (tmp.startsWith(impPolicyPrefix)) { String partialURL = getPartialUrl("createPolicy", RequestFormat.JSON, params); URL url = new URL( policyServiceURL + tmp.substring(impPolicyPrefix.length()).toString() + partialURL); consumer.getService().setServiceLocation(url); PolicySet policySet = unmarshalXmlPolicyData(importData); StringBuffer policiesNotStored = new StringBuffer(); if (policySet.getPolicy().isEmpty()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "No policies to import"); } CreatePolicyResponse createPolicyResponse; for (Policy policy : policySet.getPolicy()) { policy.setPolicyId(null); if ("RL".equalsIgnoreCase(policy.getPolicyType())) { List<Rule> rules = policy.getRule(); for (Rule rule : rules) { rule.setRuleName(policy.getPolicyName()); } } CreatePolicyRequest createPolicyRequest = new CreatePolicyRequest(); createPolicyRequest.setPolicy(policy); createPolicyResponse = (CreatePolicyResponse) consumer .getService() .createDispatch("createPolicy") .invoke(createPolicyRequest); if (createPolicyResponse.getErrorMessage() != null) { policiesNotStored.append(policy.getPolicyName() + ": "); for (CommonErrorData error2 : createPolicyResponse.getErrorMessage().getError()) { policiesNotStored.append(error2.getMessage() + "\n"); } } } if (policiesNotStored.length() > 0) { response.sendError( HttpServletResponse.SC_CONFLICT, "The following policies have not been stored: \n" + policiesNotStored.toString()); } } else if (tmp.startsWith(impSGPrefix)) { String partialURL = getPartialUrl("createSubjectGroups", RequestFormat.JSON, params); URL url = new URL( policyServiceURL + tmp.substring(impSGPrefix.length()).toString() + partialURL); consumer.getService().setServiceLocation(url); List<SubjectGroup> subjectGroups = unmarshalXmlSGData(importData); StringBuffer sgNotStored = new StringBuffer(); if (subjectGroups.isEmpty()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, "No Subject Group to import"); } CreateSubjectGroupsResponse createSGResponse; for (SubjectGroup subjectGroup : subjectGroups) { subjectGroup.setSubjectMatch(null); CreateSubjectGroupsRequest createSGRequest = new CreateSubjectGroupsRequest(); createSGRequest.getSubjectGroups().add(subjectGroup); createSGResponse = consumer.createSubjectGroups(createSGRequest); if (createSGResponse.getErrorMessage() != null) { sgNotStored.append(subjectGroup.getSubjectGroupName() + ": "); for (CommonErrorData error2 : createSGResponse.getErrorMessage().getError()) { sgNotStored.append(error2.getMessage() + "\n"); } } } if (sgNotStored.length() > 0) { response.sendError( HttpServletResponse.SC_CONFLICT, "The following Subject Groups have not been stored: \n" + sgNotStored.toString()); } } else { response.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid url for download: " + tmp); return; } return; } } catch (JAXBException e) { response.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to parse imported file"); } catch (ServiceException e1) { response.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Unable to invoke PolicyService"); } } if (error != null) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }