Search in sources :

Example 11 with Holder

use of javax.xml.ws.Holder in project camel by apache.

the class MultiPartCxfServerTest method testSendRequestWithInAndInOutParts.

@Test
public void testSendRequestWithInAndInOutParts() throws Exception {
    Exchange exchange = producerTemplate.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            BeanInvocation beanInvocation = new BeanInvocation();
            beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("saveCustomer", SaveCustomer.class, Product.class, Holder.class));
            Customer customer = new Customer();
            customer.setName("TestCustomer");
            customer.setRevenue(50000);
            SaveCustomer saveCustomer = new SaveCustomer();
            saveCustomer.setCustomer(customer);
            Product product = new Product();
            product.setName("Multiuse Product");
            product.setDescription("Useful for lots of things.");
            Holder<Company> holder = new Holder<Company>();
            Object[] args = new Object[] { saveCustomer, product, holder };
            beanInvocation.setArgs(args);
            exchange.getIn().setBody(beanInvocation);
        }
    });
    if (exchange.getException() != null) {
        throw exchange.getException();
    }
    @SuppressWarnings("unchecked") List<Object> headers = (List<Object>) exchange.getOut().getHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST);
    assertTrue(headers.size() == 1);
    Object companyHeaderObj = headers.get(0);
    assertTrue(companyHeaderObj instanceof Company);
    assertTrue(((Company) companyHeaderObj).getName().equals("MultipartSoft"));
}
Also used : Company(com.example.customerservice.multipart.Company) Processor(org.apache.camel.Processor) Customer(com.example.customerservice.multipart.Customer) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Holder(javax.xml.ws.Holder) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) Product(com.example.customerservice.multipart.Product) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Exchange(org.apache.camel.Exchange) List(java.util.List) Test(org.junit.Test)

Example 12 with Holder

use of javax.xml.ws.Holder in project camel by apache.

the class MultiPartCxfServerTest method testSendRequestWithReusedInAndInOutParts.

/**
     * This test validates the end-to-end behavior of the service interface mapping when a parameter type
     * is defined with a different QName in two different Web method. It also tests the case where a 
     * QName and type are directly reused across methods.
     */
@Test
public void testSendRequestWithReusedInAndInOutParts() throws Exception {
    Exchange exchange = producerTemplate.send("direct:start", new Processor() {

        public void process(Exchange exchange) throws Exception {
            BeanInvocation beanInvocation = new BeanInvocation();
            beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("saveCustomerToo", SaveCustomer.class, Product.class, Holder.class));
            Customer customer = new Customer();
            customer.setName("TestCustomerToo");
            customer.setRevenue(50000);
            SaveCustomer saveCustomer = new SaveCustomer();
            saveCustomer.setCustomer(customer);
            Product product = new Product();
            product.setName("Multiuse Product");
            product.setDescription("Useful for lots of things.");
            Holder<Company> holder = new Holder<Company>();
            Object[] args = new Object[] { saveCustomer, product, holder };
            beanInvocation.setArgs(args);
            exchange.getIn().setBody(beanInvocation);
        }
    });
    if (exchange.getException() != null) {
        throw exchange.getException();
    }
    @SuppressWarnings("unchecked") List<Object> headers = (List<Object>) exchange.getOut().getHeader(SoapJaxbDataFormat.SOAP_UNMARSHALLED_HEADER_LIST);
    assertTrue(headers.size() == 1);
    Object companyHeaderObj = headers.get(0);
    assertTrue(companyHeaderObj instanceof Company);
    assertTrue(((Company) companyHeaderObj).getName().equals("MultipartSoft"));
}
Also used : Company(com.example.customerservice.multipart.Company) Processor(org.apache.camel.Processor) Customer(com.example.customerservice.multipart.Customer) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Holder(javax.xml.ws.Holder) BeanInvocation(org.apache.camel.component.bean.BeanInvocation) Product(com.example.customerservice.multipart.Product) SaveCustomer(com.example.customerservice.multipart.SaveCustomer) Exchange(org.apache.camel.Exchange) List(java.util.List) Test(org.junit.Test)

Example 13 with Holder

use of javax.xml.ws.Holder in project bazel by bazelbuild.

the class JavaSource2CFGDOT method getMethodTreeAndCompilationUnit.

/**
     * @return The AST of a specific method in a specific class as well as the
     *         {@link CompilationUnitTree} in a specific file (or null they do
     *         not exist).
     */
public static Entry</*@Nullable*/
MethodTree, /*@Nullable*/
CompilationUnitTree> getMethodTreeAndCompilationUnit(String file, final String method, String clas) {
    final Holder<MethodTree> m = new Holder<>();
    final Holder<CompilationUnitTree> c = new Holder<>();
    BasicTypeProcessor typeProcessor = new BasicTypeProcessor() {

        @Override
        protected TreePathScanner<?, ?> createTreePathScanner(CompilationUnitTree root) {
            c.value = root;
            return new TreePathScanner<Void, Void>() {

                @Override
                public Void visitMethod(MethodTree node, Void p) {
                    ExecutableElement el = TreeUtils.elementFromDeclaration(node);
                    if (el.getSimpleName().contentEquals(method)) {
                        m.value = node;
                        // compilation).
                        throw new RuntimeException();
                    }
                    return null;
                }
            };
        }
    };
    Context context = new Context();
    JavaCompiler javac = new JavaCompiler(context);
    javac.attrParseOnly = true;
    JavacFileManager fileManager = (JavacFileManager) context.get(JavaFileManager.class);
    JavaFileObject l = fileManager.getJavaFileObjectsFromStrings(List.of(file)).iterator().next();
    PrintStream err = System.err;
    try {
        // redirect syserr to nothing (and prevent the compiler from issuing
        // warnings about our exception.
        System.setErr(new PrintStream(new OutputStream() {

            @Override
            public void write(int b) throws IOException {
            }
        }));
        javac.compile(List.of(l), List.of(clas), List.of(typeProcessor));
    } catch (Throwable e) {
    // ok
    } finally {
        System.setErr(err);
    }
    return new Entry<MethodTree, CompilationUnitTree>() {

        @Override
        public CompilationUnitTree setValue(CompilationUnitTree value) {
            return null;
        }

        @Override
        public CompilationUnitTree getValue() {
            return c.value;
        }

        @Override
        public MethodTree getKey() {
            return m.value;
        }
    };
}
Also used : Context(com.sun.tools.javac.util.Context) PrintStream(java.io.PrintStream) CompilationUnitTree(com.sun.source.tree.CompilationUnitTree) MethodTree(com.sun.source.tree.MethodTree) JavaFileManager(javax.tools.JavaFileManager) Holder(javax.xml.ws.Holder) ExecutableElement(javax.lang.model.element.ExecutableElement) OutputStream(java.io.OutputStream) TreePathScanner(com.sun.source.util.TreePathScanner) JavaCompiler(com.sun.tools.javac.main.JavaCompiler) JavacFileManager(com.sun.tools.javac.file.JavacFileManager) JavaFileObject(javax.tools.JavaFileObject) Entry(java.util.Map.Entry) BasicTypeProcessor(org.checkerframework.javacutil.BasicTypeProcessor)

Example 14 with Holder

use of javax.xml.ws.Holder in project midpoint by Evolveum.

the class ModelWebServiceRaw method invokeAllowingFaults.

public DOMSource invokeAllowingFaults(DOMSource request) throws FaultMessage {
    Node rootNode = request.getNode();
    Element rootElement;
    if (rootNode instanceof Document) {
        rootElement = ((Document) rootNode).getDocumentElement();
    } else if (rootNode instanceof Element) {
        rootElement = (Element) rootNode;
    } else {
        throw ws.createIllegalArgumentFault("Unexpected DOM node type: " + rootNode);
    }
    Object requestObject;
    try {
        requestObject = prismContext.parserFor(rootElement).parseRealValue();
    } catch (SchemaException e) {
        throw ws.createIllegalArgumentFault("Couldn't parse SOAP request body because of schema exception: " + e.getMessage());
    }
    Node response;
    Holder<OperationResultType> operationResultTypeHolder = new Holder<>();
    try {
        PrismSerializer<Element> serializer = prismContext.domSerializer().options(SerializationOptions.createSerializeReferenceNames());
        if (requestObject instanceof GetObjectType) {
            GetObjectType g = (GetObjectType) requestObject;
            Holder<ObjectType> objectTypeHolder = new Holder<>();
            ws.getObject(g.getObjectType(), g.getOid(), g.getOptions(), objectTypeHolder, operationResultTypeHolder);
            GetObjectResponseType gr = new GetObjectResponseType();
            gr.setObject(objectTypeHolder.value);
            gr.setResult(operationResultTypeHolder.value);
            response = serializer.serializeAnyData(gr, ModelPort.GET_OBJECT_RESPONSE);
        } else if (requestObject instanceof SearchObjectsType) {
            SearchObjectsType s = (SearchObjectsType) requestObject;
            Holder<ObjectListType> objectListTypeHolder = new Holder<>();
            ws.searchObjects(s.getObjectType(), s.getQuery(), s.getOptions(), objectListTypeHolder, operationResultTypeHolder);
            SearchObjectsResponseType sr = new SearchObjectsResponseType();
            sr.setObjectList(objectListTypeHolder.value);
            sr.setResult(operationResultTypeHolder.value);
            response = serializer.serializeAnyData(sr, ModelPort.SEARCH_OBJECTS_RESPONSE);
        } else if (requestObject instanceof ExecuteChangesType) {
            ExecuteChangesType e = (ExecuteChangesType) requestObject;
            ObjectDeltaOperationListType objectDeltaOperationListType = ws.executeChanges(e.getDeltaList(), e.getOptions());
            ExecuteChangesResponseType er = new ExecuteChangesResponseType();
            er.setDeltaOperationList(objectDeltaOperationListType);
            response = serializer.serializeAnyData(er, ModelPort.EXECUTE_CHANGES_RESPONSE);
        } else if (requestObject instanceof FindShadowOwnerType) {
            FindShadowOwnerType f = (FindShadowOwnerType) requestObject;
            Holder<UserType> userTypeHolder = new Holder<>();
            ws.findShadowOwner(f.getShadowOid(), userTypeHolder, operationResultTypeHolder);
            FindShadowOwnerResponseType fsr = new FindShadowOwnerResponseType();
            fsr.setUser(userTypeHolder.value);
            fsr.setResult(operationResultTypeHolder.value);
            response = serializer.serializeAnyData(fsr, ModelPort.FIND_SHADOW_OWNER_RESPONSE);
        } else if (requestObject instanceof TestResourceType) {
            TestResourceType tr = (TestResourceType) requestObject;
            OperationResultType operationResultType = ws.testResource(tr.getResourceOid());
            TestResourceResponseType trr = new TestResourceResponseType();
            trr.setResult(operationResultType);
            response = serializer.serializeAnyData(trr, ModelPort.TEST_RESOURCE_RESPONSE);
        } else if (requestObject instanceof ExecuteScriptsType) {
            ExecuteScriptsType es = (ExecuteScriptsType) requestObject;
            ExecuteScriptsResponseType esr = ws.executeScripts(es);
            response = serializer.serializeAnyData(esr, ModelPort.EXECUTE_SCRIPTS_RESPONSE);
        } else if (requestObject instanceof ImportFromResourceType) {
            ImportFromResourceType ifr = (ImportFromResourceType) requestObject;
            TaskType taskType = ws.importFromResource(ifr.getResourceOid(), ifr.getObjectClass());
            ImportFromResourceResponseType ifrr = new ImportFromResourceResponseType();
            ifrr.setTask(taskType);
            response = serializer.serializeAnyData(ifrr, ModelPort.IMPORT_FROM_RESOURCE_RESPONSE);
        } else if (requestObject instanceof NotifyChangeType) {
            NotifyChangeType nc = (NotifyChangeType) requestObject;
            TaskType taskType = ws.notifyChange(nc.getChangeDescription());
            NotifyChangeResponseType ncr = new NotifyChangeResponseType();
            ncr.setTask(taskType);
            response = serializer.serializeAnyData(ncr, ModelPort.NOTIFY_CHANGE_RESPONSE);
        } else {
            throw ws.createIllegalArgumentFault("Unsupported request type: " + requestObject);
        }
    } catch (SchemaException e) {
        throwFault(e, operationResultTypeHolder.value);
        // not reached
        return null;
    }
    return new DOMSource(response);
}
Also used : ExecuteChangesResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesResponseType) DOMSource(javax.xml.transform.dom.DOMSource) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) ExecuteChangesType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteChangesType) FindShadowOwnerResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.FindShadowOwnerResponseType) Document(org.w3c.dom.Document) FindShadowOwnerType(com.evolveum.midpoint.xml.ns._public.model.model_3.FindShadowOwnerType) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) GetObjectType(com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) GetObjectType(com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectType) ImportFromResourceType(com.evolveum.midpoint.xml.ns._public.model.model_3.ImportFromResourceType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) NotifyChangeType(com.evolveum.midpoint.xml.ns._public.model.model_3.NotifyChangeType) GetObjectResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.GetObjectResponseType) Holder(javax.xml.ws.Holder) NotifyChangeResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.NotifyChangeResponseType) TestResourceType(com.evolveum.midpoint.xml.ns._public.model.model_3.TestResourceType) SearchObjectsType(com.evolveum.midpoint.xml.ns._public.model.model_3.SearchObjectsType) ImportFromResourceResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ImportFromResourceResponseType) ExecuteScriptsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsResponseType) ExecuteScriptsType(com.evolveum.midpoint.xml.ns._public.model.model_3.ExecuteScriptsType) SearchObjectsResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.SearchObjectsResponseType) TestResourceResponseType(com.evolveum.midpoint.xml.ns._public.model.model_3.TestResourceResponseType) ObjectDeltaOperationListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectDeltaOperationListType)

Example 15 with Holder

use of javax.xml.ws.Holder in project midpoint by Evolveum.

the class ExportAction method executeSearch.

private void executeSearch(ModelPortType port, Writer writer) throws FaultMessage, IOException, JAXBException, SAXException {
    SelectorQualifiedGetOptionsType options = createOptions();
    QName type = ObjectType.getType(getParams().getType());
    if (type == null) {
        type = ObjectType.OBJECT.getType();
    }
    int count = 0;
    int currentSize = 1;
    Holder<ObjectListType> list = new Holder<>();
    Holder<OperationResultType> result = new Holder<>();
    while (currentSize > 0) {
        QueryType query = createQuery(count);
        port.searchObjects(type, query, options, list, result);
        OperationResultType res = result.value;
        if (!OperationResultStatusType.SUCCESS.equals(res.getStatus()) && !getParams().isIgnore()) {
            printInfoMessage("Search returned {}, reason: ", res.getStatus(), res.getMessage());
            if (getParams().isVerbose()) {
                printInfoMessage("Operation result:\n{}", ToolsUtils.serializeObject(res));
            }
            break;
        }
        ObjectListType objList = list.value;
        if (getParams().isVerbose()) {
            printInfoMessage("Search returned {}, status: {}/{}", res.getStatus(), count, objList.getCount());
        }
        List<com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType> objects = objList.getObject();
        currentSize = objects.size();
        for (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType object : objects) {
            ToolsUtils.serializeObject(object, writer);
            writer.write('\n');
        }
        count += currentSize;
    }
}
Also used : QName(javax.xml.namespace.QName) Holder(javax.xml.ws.Holder) ObjectListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType) ObjectType(com.evolveum.midpoint.cli.ninja.util.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) QueryType(com.evolveum.prism.xml.ns._public.query_3.QueryType) SelectorQualifiedGetOptionsType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)

Aggregations

Holder (javax.xml.ws.Holder)129 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)77 Test (org.testng.annotations.Test)53 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)48 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)33 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)24 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)23 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)23 Test (org.junit.Test)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)19 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)18 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)16 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 IpPort (io.servicecomb.foundation.common.net.IpPort)14 ClientException (io.servicecomb.serviceregistry.client.ClientException)14