use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType in project midpoint by Evolveum.
the class Upload method createModelPort.
public static ModelPortType createModelPort(CommandLine cmdLine) {
String endpointUrl = cmdLine.getOptionValue(OPT_URL, DEFAULT_ENDPOINT_URL);
String user = cmdLine.getOptionValue(OPT_USER, ADM_USERNAME);
ClientPasswordHandler.setPassword(cmdLine.getOptionValue(OPT_PASSWORD, ADM_PASSWORD));
System.out.println("Endpoint URL: " + endpointUrl);
ModelService modelService = new ModelService();
ModelPortType modelPort = modelService.getModelPort();
BindingProvider bp = (BindingProvider) modelPort;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointUrl);
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String, Object> outProps = new HashMap<>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, user);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_DIGEST);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
return modelPort;
}
use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType in project midpoint by Evolveum.
the class Upload method uploadFile.
private static void uploadFile(File file, CommandLine cmdline, ModelPortType modelPort) {
System.out.println("Uploading file " + file);
Object content;
try {
content = unmarshalFile(file);
} catch (JAXBException | FileNotFoundException e) {
System.err.println("Cannot read " + file + ": " + e.getMessage());
e.printStackTrace();
error = true;
return;
}
if (content == null) {
System.err.println("Nothing to be uploaded.");
error = true;
return;
}
if (!(content instanceof ObjectType)) {
System.err.println("Expected an ObjectType to be uploaded; found " + content.getClass());
error = true;
return;
}
ObjectType objectType = (ObjectType) content;
ObjectDeltaType objectDeltaType = new ObjectDeltaType();
objectDeltaType.setChangeType(ChangeTypeType.ADD);
objectDeltaType.setObjectType(ModelClientUtil.getTypeQName(objectType.getClass()));
objectDeltaType.setObjectToAdd(objectType);
ObjectDeltaListType objectDeltaListType = new ObjectDeltaListType();
objectDeltaListType.getDelta().add(objectDeltaType);
ModelExecuteOptionsType optionsType = new ModelExecuteOptionsType();
optionsType.setIsImport(true);
optionsType.setReevaluateSearchFilters(true);
optionsType.setRaw(true);
optionsType.setOverwrite(true);
ExecuteChangesType executeChangesType = new ExecuteChangesType();
executeChangesType.setDeltaList(objectDeltaListType);
executeChangesType.setOptions(optionsType);
ObjectDeltaOperationListType response;
try {
response = modelPort.executeChanges(objectDeltaListType, optionsType);
} catch (Exception e) {
System.err.println("Got exception when trying to execute the changes " + e.getMessage());
error = true;
return;
}
System.out.println("-----------------------------------------------------------------");
if (response == null) {
System.err.println("Unexpected empty response");
error = true;
return;
}
OperationResultType overallResult = new OperationResultType();
boolean allSuccess = true;
for (ObjectDeltaOperationType objectDeltaOperation : response.getDeltaOperation()) {
if (objectDeltaOperation.getObjectDelta() != null) {
ObjectDeltaType delta = objectDeltaOperation.getObjectDelta();
System.out.print(delta.getChangeType() + " delta with OID " + delta.getOid() + " ");
}
OperationResultType resultType = objectDeltaOperation.getExecutionResult();
System.out.println("resulted in " + getResultStatus(resultType));
if (resultType == null || resultType.getStatus() != OperationResultStatusType.SUCCESS) {
allSuccess = false;
error = true;
}
overallResult.getPartialResults().add(resultType);
}
if (!cmdline.hasOption(OPT_HIDE_RESULT) && (cmdline.hasOption(OPT_SHOW_RESULT) || !allSuccess)) {
System.out.println("\n\n" + marshalResult(overallResult));
}
if (cmdline.hasOption(OPT_FILE_FOR_RESULT)) {
String filename = cmdline.getOptionValue(OPT_FILE_FOR_RESULT);
try {
FileWriter fileWriter = new FileWriter(filename, true);
IOUtils.write(marshalResult(overallResult), fileWriter);
} catch (IOException e) {
System.err.println("Couldn't write operation result to file " + filename + ": " + e.getMessage());
e.printStackTrace();
error = true;
}
}
}
use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType in project midpoint by Evolveum.
the class AbstractWebserviceTest method createModelPort.
/**
* Creates webservice client connecting to midpoint
* */
protected static ModelPortType createModelPort(String username, String password, String passwordType) {
String endpoint = ENDPOINT;
if (System.getProperty("midpoint.endpoint") != null) {
endpoint = System.getProperty("midpoint.endpoint");
}
LOGGER.info("Creating model client endpoint: {} , username={}, password={}", new Object[] { endpoint, username, password });
ModelService modelService = new ModelService();
ModelPortType modelPort = modelService.getModelPort();
BindingProvider bp = (BindingProvider) modelPort;
Map<String, Object> requestContext = bp.getRequestContext();
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
org.apache.cxf.endpoint.Client client = ClientProxy.getClient(modelPort);
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String, Object> outProps = new HashMap<String, Object>();
if (username != null) {
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
outProps.put(WSHandlerConstants.USER, username);
outProps.put(WSHandlerConstants.PASSWORD_TYPE, passwordType);
ClientPasswordHandler.setPassword(password);
outProps.put(WSHandlerConstants.PW_CALLBACK_CLASS, ClientPasswordHandler.class.getName());
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
}
cxfEndpoint.getInInterceptors().add(new LoggingInInterceptor());
cxfEndpoint.getOutInterceptors().add(new LoggingOutInterceptor());
return modelPort;
}
use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType in project midpoint by Evolveum.
the class BulkAction method executeAction.
@Override
protected void executeAction() throws Exception {
ModelPortType port = createModelPort();
try {
ExecuteScriptsOptionsType options = new ExecuteScriptsOptionsType();
options.setExecuteAsynchronously(getParams().isAsync());
options.setObjectLimit(getParams().getLimit());
options.setOutputFormat(getParams().getOutput());
ExecuteScriptsType parameters = new ExecuteScriptsType();
parameters.setOptions(options);
parameters.setMslScripts(getParams().getMslScript());
//todo implement xml support
//parameters.setXmlScripts(xml);
ExecuteScriptsResponseType response = port.executeScripts(parameters);
//todo implement
} catch (FaultMessage ex) {
handleError("Couldn't execute scripts", ex);
}
}
use of com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType in project midpoint by Evolveum.
the class DeleteAction method executeAction.
@Override
protected void executeAction() throws Exception {
ModelPortType port = createModelPort();
ModelExecuteOptionsType options = new ModelExecuteOptionsType();
options.setForce(getParams().isForce());
options.setRaw(getParams().isRaw());
QName type = getParams().getType();
ObjectDeltaType delta = createDeleteDelta(getParams().getOid(), type);
ObjectDeltaListType deltas = createDeltaList(delta);
try {
ObjectDeltaOperationListType result = port.executeChanges(deltas, options);
List<ObjectDeltaOperationType> operations = result.getDeltaOperation();
ObjectDeltaOperationType operation = operations.get(0);
OperationResultType resultType = operation.getExecutionResult();
STD_OUT.info("Status: {}", resultType.getStatus());
} catch (FaultMessage ex) {
handleError("Couldn't delete object '" + type.getLocalPart() + "' with oid '" + getParams().getOid() + "'", ex);
}
}
Aggregations