Search in sources :

Example 96 with QName

use of javax.xml.namespace.QName in project tdi-studio-se by Talend.

the class DynamicInvoker method invokeMethod.

/**
     * Method invokeMethod
     * 
     * @param wsdlLocation
     * @param operationName
     * @param inputName
     * @param outputName
     * @param portName
     * @param args
     * 
     * @return
     * 
     * @throws Exception
     */
public HashMap invokeMethod(String operationName, String portName, String[] args) throws Exception {
    String serviceNS = null;
    String serviceName = null;
    String operationQName = null;
    // System.out.println("Preparing Axis dynamic invocation");
    Service service = selectService(serviceNS, serviceName);
    Operation operation = null;
    org.apache.axis.client.Service dpf = new org.apache.axis.client.Service(wsdlParser, service.getQName());
    if (needWINAuth) {
        EngineConfiguration defaultConfig = EngineConfigurationFactoryFinder.newFactory().getClientEngineConfig();
        SimpleProvider config = new SimpleProvider(defaultConfig);
        config.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, new CommonsHTTPSender());
        AxisClient axisClient = new AxisClient(config);
        dpf.setEngine(axisClient);
    }
    Vector inputs = new Vector();
    Port port = selectPort(service.getPorts(), portName);
    if (portName == null) {
        portName = port.getName();
    }
    Binding binding = port.getBinding();
    Call call = dpf.createCall(QName.valueOf(portName), QName.valueOf(operationName));
    ((org.apache.axis.client.Call) call).setTimeout(new Integer(timeout * 1000));
    ((org.apache.axis.client.Call) call).setProperty(ElementDeserializer.DESERIALIZE_CURRENT_ELEMENT, Boolean.TRUE);
    if (needAuth) {
        // authentication way1:
        // for calling webservice in deploy.wsdd:
        // <handler type="java:org.apache.axis.handlers.SimpleAuthorizationHandler"/>
        ((org.apache.axis.client.Call) call).setUsername(username);
        ((org.apache.axis.client.Call) call).setPassword(password);
        // authentication way2:
        // for bug:8403, in order to call webservice on "basic HTTP authentication"
        ((org.apache.axis.client.Call) call).setProperty(Stub.USERNAME_PROPERTY, username);
        ((org.apache.axis.client.Call) call).setProperty(Stub.PASSWORD_PROPERTY, password);
    }
    if (needWINAuth) {
        ((org.apache.axis.client.Call) call).setUsername(username);
        ((org.apache.axis.client.Call) call).setPassword(password);
    }
    if (useProxy) {
        AxisProperties.setProperty("http.proxyHost", proxyHost);
        AxisProperties.setProperty("http.proxyPort", proxyPort);
        AxisProperties.setProperty("http.proxyUser", proxyUser);
        AxisProperties.setProperty("http.proxyPassword", proxyPassword);
    }
    // Output types and names
    Vector outNames = new Vector();
    // Input types and names
    Vector inNames = new Vector();
    Vector inTypes = new Vector();
    SymbolTable symbolTable = wsdlParser.getSymbolTable();
    BindingEntry bEntry = symbolTable.getBindingEntry(binding.getQName());
    Parameters parameters = null;
    Iterator i = bEntry.getParameters().keySet().iterator();
    while (i.hasNext()) {
        Operation o = (Operation) i.next();
        if (o.getName().equals(operationName)) {
            operation = o;
            parameters = (Parameters) bEntry.getParameters().get(o);
            break;
        }
    }
    if ((operation == null) || (parameters == null)) {
        throw new RuntimeException(operationName + " was not found.");
    }
    // loop over paramters and set up in/out params
    for (int j = 0; j < parameters.list.size(); ++j) {
        Parameter p = (Parameter) parameters.list.get(j);
        if (p.getMode() == 1) {
            // IN
            inNames.add(p.getQName().getLocalPart());
            inTypes.add(p);
        } else if (p.getMode() == 2) {
            // OUT
            outNames.add(p.getQName().getLocalPart());
        } else if (p.getMode() == 3) {
            // INOUT
            inNames.add(p.getQName().getLocalPart());
            inTypes.add(p);
            outNames.add(p.getQName().getLocalPart());
        }
    }
    // set output type
    if (parameters.returnParam != null) {
        if (!parameters.returnParam.getType().isBaseType()) {
            ((org.apache.axis.client.Call) call).registerTypeMapping(org.w3c.dom.Element.class, parameters.returnParam.getType().getQName(), new ElementSerializerFactory(), new ElementDeserializerFactory());
        }
        // Get the QName for the return Type
        QName returnType = org.apache.axis.wsdl.toJava.Utils.getXSIType(parameters.returnParam);
        QName returnQName = parameters.returnParam.getQName();
        outNames.add(returnQName.getLocalPart());
    }
    if (inNames.size() != args.length - 2)
        throw new RuntimeException("Need " + inNames.size() + " arguments!!!");
    for (int pos = 0; pos < inNames.size(); ++pos) {
        String arg = args[pos + 2];
        Parameter p = (Parameter) inTypes.get(pos);
        inputs.add(getParamData((org.apache.axis.client.Call) call, p, arg));
    }
    // System.out.println("Executing operation " + operationName + " with parameters:");
    for (int j = 0; j < inputs.size(); j++) {
    // System.out.println(inNames.get(j) + "=" + inputs.get(j));
    }
    Object ret = call.invoke(inputs.toArray());
    Map outputs = call.getOutputParams();
    HashMap map = new HashMap();
    String name = null;
    Object value = null;
    if (outNames.size() > 0) {
        name = (String) outNames.get(0);
        value = outputs.get(name);
    }
    if ((value == null) && (ret != null)) {
        map.put(name, ret);
    } else {
        map.put(outNames, outputs);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Port(javax.wsdl.Port) Operation(javax.wsdl.Operation) AxisClient(org.apache.axis.client.AxisClient) EngineConfiguration(org.apache.axis.EngineConfiguration) Iterator(java.util.Iterator) ElementDeserializerFactory(org.apache.axis.encoding.ser.ElementDeserializerFactory) Vector(java.util.Vector) Binding(javax.wsdl.Binding) Call(javax.xml.rpc.Call) CommonsHTTPSender(org.apache.axis.transport.http.CommonsHTTPSender) Parameters(org.apache.axis.wsdl.symbolTable.Parameters) ElementSerializerFactory(org.apache.axis.encoding.ser.ElementSerializerFactory) QName(javax.xml.namespace.QName) Service(javax.wsdl.Service) SymbolTable(org.apache.axis.wsdl.symbolTable.SymbolTable) SimpleProvider(org.apache.axis.configuration.SimpleProvider) Parameter(org.apache.axis.wsdl.symbolTable.Parameter) BindingEntry(org.apache.axis.wsdl.symbolTable.BindingEntry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 97 with QName

use of javax.xml.namespace.QName in project tdi-studio-se by Talend.

the class XRMAuthPolicyInterceptor method handleMessage.

public void handleMessage(SoapMessage message) throws Fault {
    AssertionInfoMap aim = message.get(AssertionInfoMap.class);
    if (null == aim) {
        return;
    }
    QName qname = new QName("http://schemas.microsoft.com/xrm/2011/Contracts/Services", "AuthenticationPolicy", "ms-xrm");
    Collection<AssertionInfo> ais = aim.get(qname);
    if (null == ais || ais.size() == 0) {
        return;
    }
    for (AssertionInfo ai : ais) {
        ai.setAsserted(true);
    }
}
Also used : AssertionInfo(org.apache.cxf.ws.policy.AssertionInfo) QName(javax.xml.namespace.QName) AssertionInfoMap(org.apache.cxf.ws.policy.AssertionInfoMap)

Example 98 with QName

use of javax.xml.namespace.QName in project tdi-studio-se by Talend.

the class NetsuiteManagement_CXF method initializeStub.

public void initializeStub() throws Exception {
    URL wsdl_locationUrl = this.getClass().getResource("/wsdl/netsuite.wsdl");
    QName serviceQname = new QName("urn:platform_2014_2.webservices.netsuite.com", "NetSuiteService");
    NetSuiteService service = new NetSuiteService(wsdl_locationUrl, serviceQname);
    NetSuitePortType port = service.getNetSuitePort();
    BindingProvider provider = (BindingProvider) port;
    Map<String, Object> requestContext = provider.getRequestContext();
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, _url);
    Preferences preferences = new Preferences();
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.FALSE);
    preferences.setWarningAsError(Boolean.FALSE);
    preferences.setIgnoreReadOnlyFields(Boolean.TRUE);
    preferences.setDisableMandatoryCustomFieldValidation(Boolean.TRUE);
    SearchPreferences searchPreferences = new SearchPreferences();
    searchPreferences.setPageSize(this._pageSize);
    searchPreferences.setBodyFieldsOnly(Boolean.valueOf(false));
    RecordRef role = new RecordRef();
    role.setInternalId(this._role);
    Passport passport = new Passport();
    passport.setEmail(this._email);
    passport.setPassword(this._pwd);
    passport.setRole(role);
    passport.setAccount(this._account);
    // Get the webservices domain for your account
    GetDataCenterUrlsRequest dataCenterRequest = new GetDataCenterUrlsRequest();
    dataCenterRequest.setAccount(this._account);
    DataCenterUrls urls = null;
    GetDataCenterUrlsResponse reponse = port.getDataCenterUrls(dataCenterRequest);
    if (reponse != null && reponse.getGetDataCenterUrlsResult() != null) {
        urls = reponse.getGetDataCenterUrlsResult().getDataCenterUrls();
    }
    if (urls == null) {
        throw new Exception("Can't get a correct webservice domain! Please check your configuration or try to run again.");
    }
    String wsDomain = urls.getWebservicesDomain();
    String endpoint = wsDomain.concat(new URL(this._url).getPath());
    requestContext.put(BindingProvider.SESSION_MAINTAIN_PROPERTY, true);
    requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
    List<Header> list = (List<Header>) requestContext.get(Header.HEADER_LIST);
    if (list == null) {
        list = new ArrayList<Header>();
        requestContext.put(Header.HEADER_LIST, list);
    }
    Header searchPreferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "searchPreferences"), searchPreferences, new JAXBDataBinding(searchPreferences.getClass()));
    Header preferences_header = new Header(new QName("urn:messages_2014_2.platform.webservices.netsuite.com", "preferences"), preferences, new JAXBDataBinding(preferences.getClass()));
    list.add(searchPreferences_header);
    list.add(preferences_header);
    LoginRequest request = new LoginRequest();
    request.setPassport(passport);
    port.login(request);
    this._port = port;
    Arrays.asList(new String[] { "", "", "" });
}
Also used : GetDataCenterUrlsResponse(com.netsuite.webservices.platform.messages.GetDataCenterUrlsResponse) QName(javax.xml.namespace.QName) RecordRef(com.netsuite.webservices.platform.core.RecordRef) ListOrRecordRef(com.netsuite.webservices.platform.core.ListOrRecordRef) DataCenterUrls(com.netsuite.webservices.platform.core.DataCenterUrls) BindingProvider(javax.xml.ws.BindingProvider) LoginRequest(com.netsuite.webservices.platform.messages.LoginRequest) URL(java.net.URL) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) SOAPException(javax.xml.soap.SOAPException) ParseException(java.text.ParseException) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) NetSuitePortType(com.netsuite.webservices.platform.NetSuitePortType) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Passport(com.netsuite.webservices.platform.core.Passport) Header(org.apache.cxf.headers.Header) NetSuiteService(com.netsuite.webservices.platform.NetSuiteService) GetDataCenterUrlsRequest(com.netsuite.webservices.platform.messages.GetDataCenterUrlsRequest) List(java.util.List) SearchCustomFieldList(com.netsuite.webservices.platform.core.SearchCustomFieldList) ArrayList(java.util.ArrayList) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) SearchPreferences(com.netsuite.webservices.platform.messages.SearchPreferences) Preferences(com.netsuite.webservices.platform.messages.Preferences)

Example 99 with QName

use of javax.xml.namespace.QName in project jersey by jersey.

the class Elements method createElement.

private static JAXBElement<XhtmlValueType> createElement(final String elementName, String value) {
    try {
        final XhtmlValueType element = new XhtmlValueType();
        element.value = value;
        final JAXBElement<XhtmlValueType> jaxbElement = new JAXBElement<XhtmlValueType>(new QName("http://www.w3.org/1999/xhtml", elementName), XhtmlValueType.class, element);
        return jaxbElement;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : QName(javax.xml.namespace.QName) JAXBElement(javax.xml.bind.JAXBElement)

Example 100 with QName

use of javax.xml.namespace.QName in project intellij-community by JetBrains.

the class CompletionLists method addContextNames.

private static XPathNodeTest.PrincipalType addContextNames(XPathNodeTest element, ContextProvider contextProvider, PrefixedName prefixedName, Set<Lookup> list) {
    final NamespaceContext namespaceContext = contextProvider.getNamespaceContext();
    final XmlElement context = contextProvider.getContextElement();
    final XPathNodeTest.PrincipalType principalType = element.getPrincipalType();
    if (principalType == XPathNodeTest.PrincipalType.ELEMENT) {
        final Set<QName> elementNames = contextProvider.getElements(false);
        if (elementNames != null) {
            for (QName pair : elementNames) {
                if ("*".equals(pair.getLocalPart()))
                    continue;
                if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context, true)) {
                    if (prefixedName.getPrefix() == null && namespaceContext != null) {
                        final String p = namespaceContext.getPrefixForURI(pair.getNamespaceURI(), context);
                        list.add(new NodeLookup(makePrefix(p) + pair.getLocalPart(), XPathNodeTest.PrincipalType.ELEMENT));
                    } else {
                        list.add(new NodeLookup(pair.getLocalPart(), XPathNodeTest.PrincipalType.ELEMENT));
                    }
                }
            }
        }
    } else if (principalType == XPathNodeTest.PrincipalType.ATTRIBUTE) {
        final Set<QName> attributeNames = contextProvider.getAttributes(false);
        if (attributeNames != null) {
            for (QName pair : attributeNames) {
                if ("*".equals(pair.getLocalPart()))
                    continue;
                if (namespaceMatches(prefixedName, pair.getNamespaceURI(), namespaceContext, context, false)) {
                    if (prefixedName.getPrefix() == null && namespaceContext != null) {
                        final String p = namespaceContext.getPrefixForURI(pair.getNamespaceURI(), context);
                        list.add(new NodeLookup(makePrefix(p) + pair.getLocalPart(), XPathNodeTest.PrincipalType.ATTRIBUTE));
                    } else {
                        list.add(new NodeLookup(pair.getLocalPart(), XPathNodeTest.PrincipalType.ATTRIBUTE));
                    }
                }
            }
        }
    }
    return principalType;
}
Also used : NamespaceContext(org.intellij.lang.xpath.context.NamespaceContext) QName(javax.xml.namespace.QName) XmlElement(com.intellij.psi.xml.XmlElement)

Aggregations

QName (javax.xml.namespace.QName)6627 Test (org.junit.Test)1397 URL (java.net.URL)1195 Service (javax.xml.ws.Service)1051 ArrayList (java.util.ArrayList)850 Bus (org.apache.cxf.Bus)486 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)462 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)395 Test (org.testng.annotations.Test)357 HashMap (java.util.HashMap)343 OMElement (org.apache.axiom.om.OMElement)325 Element (org.w3c.dom.Element)295 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)292 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)289 JBossWSTest (org.jboss.wsf.test.JBossWSTest)272 Document (org.w3c.dom.Document)255 List (java.util.List)239 InputStream (java.io.InputStream)218 JAXBElement (javax.xml.bind.JAXBElement)217 IOException (java.io.IOException)209