Example usage for javax.xml.namespace QName QName

List of usage examples for javax.xml.namespace QName QName

Introduction

In this page you can find the example usage for javax.xml.namespace QName QName.

Prototype

public QName(final String namespaceURI, final String localPart) 

Source Link

Document

QName constructor specifying the Namespace URI and local part.

If the Namespace URI is null, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .

Usage

From source file:edu.internet2.middleware.shibboleth.common.config.security.AbstractPKIXValidationInformationBeanDefinitionParser.java

/**
 * Parses the certificates from the validation info configuration.
 * //from   w  w w .  j av a  2s  .co  m
 * @param configChildren children of the validation set element
 * @param builder validation set build
 */
protected void parseCertificates(Map<QName, List<Element>> configChildren, BeanDefinitionBuilder builder) {
    List<Element> certElems = configChildren.get(new QName(SecurityNamespaceHandler.NAMESPACE, "Certificate"));
    if (certElems == null || certElems.isEmpty()) {
        return;
    }

    log.debug("Parsing PKIX validation info certificates");
    ArrayList<X509Certificate> certs = new ArrayList<X509Certificate>();
    byte[] encodedCert;
    Collection<X509Certificate> decodedCerts;
    for (Element certElem : certElems) {
        encodedCert = getEncodedCertificate(DatatypeHelper.safeTrimOrNullString(certElem.getTextContent()));
        if (encodedCert == null) {
            continue;
        }

        try {
            decodedCerts = X509Util.decodeCertificate(encodedCert);
            certs.addAll(decodedCerts);
        } catch (CertificateException e) {
            throw new FatalBeanException("Unable to create PKIX validation info, unable to parse certificates",
                    e);
        }
    }

    builder.addPropertyValue("certificates", certs);
}

From source file:be.fedict.eid.pkira.contracts.EIDPKIRAContractsClient.java

/**
 * Marshals the document to XML./*from  w ww.  j  a va 2s . c o m*/
 * 
 * @param contractDocument
 *            document to marshal.
 * @return the text in the XML.
 * @throws XmlMarshallingException
 *             when this fails.
 */
public <T extends EIDPKIRAContractType> void marshal(T contractDocument, Class<T> clazz, Writer writer)
        throws XmlMarshallingException {
    QName qname = new QName(NAMESPACE, getElementNameForType(clazz));
    JAXBElement<T> jaxbElement = new JAXBElement<T>(qname, clazz, contractDocument);

    try {
        getMarshaller().marshal(jaxbElement, writer);
    } catch (JAXBException e) {
        throw new XmlMarshallingException("Cannot marshal XML object.", e);
    }
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.filtering.AttributeFilterPolicyBeanDefinitionParser.java

/** {@inheritDoc} */
protected void doParse(Element config, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(config, parserContext, builder);

    String policyId = DatatypeHelper.safeTrimOrNullString(config.getAttributeNS(null, "id"));
    log.info("Parsing configuration for attribute filter policy {}", policyId);
    builder.addPropertyValue("policyId", policyId);
    List<Element> children;
    Map<QName, List<Element>> childrenMap = XMLHelper.getChildElements(config);

    children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "PolicyRequirementRule"));
    if (children != null && children.size() > 0) {
        builder.addPropertyValue("policyRequirement",
                SpringConfigurationUtils.parseInnerCustomElement(children.get(0), parserContext));
    } else {//from   w w  w.j  a  va 2s  .c  o m
        children = childrenMap
                .get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "PolicyRequirementRuleReference"));
        String reference = getAbsoluteReference(config, "PolicyRequirementRule",
                children.get(0).getTextContent());
        builder.addPropertyReference("policyRequirement", reference);
    }

    ManagedList attributeRules = new ManagedList();
    children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRule"));
    if (children != null && children.size() > 0) {
        attributeRules.addAll(SpringConfigurationUtils.parseInnerCustomElements(children, parserContext));
    }

    children = childrenMap.get(new QName(AttributeFilterNamespaceHandler.NAMESPACE, "AttributeRuleReference"));
    if (children != null && children.size() > 0) {
        String reference;
        for (Element child : children) {
            reference = getAbsoluteReference(config, "AttributeRule", child.getTextContent());
            attributeRules.add(new RuntimeBeanReference(reference));
        }
    }

    builder.addPropertyValue("attributeRules", attributeRules);
}

From source file:com.vangent.hieos.services.xds.bridge.utils.JUnitHelper.java

/**
 * Method description/*w w w . j a  va  2 s.c  o  m*/
 *
 *
 *
 *
 * @param file
 * @param count
 * @param documentIds
 * @return
 *
 * @throws Exception
 */
public static OMElement createOMRequest(String file, int count, String[] documentIds) throws Exception {

    ObjectFactory factory = new ObjectFactory();
    SubmitDocumentRequest sdr = factory.createSubmitDocumentRequest();

    IdType pid = factory.createIdType();

    pid.setRoot("1.3.6.1.4.1.21367.2005.3.7.6fa11e467880478");
    sdr.setPatientId(pid);

    ClassLoader classLoader = JUnitHelper.class.getClassLoader();

    DocumentsType documents = factory.createDocumentsType();

    for (int i = 0; i < count; ++i) {

        DocumentType document = factory.createDocumentType();

        if ((documentIds != null) && (documentIds.length > i)) {
            document.setId(documentIds[i]);
        }

        CodeType type = factory.createCodeType();

        type.setCode("51855-5");
        type.setCodeSystem("2.16.840.1.113883.6.1");

        document.setType(type);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        InputStream is = classLoader.getResourceAsStream(file);

        assertNotNull(is);

        IOUtils.copy(is, bos);

        document.setContent(bos.toByteArray());

        documents.getDocument().add(document);
    }

    sdr.setDocuments(documents);

    QName qname = new QName(URIConstants.XDSBRIDGE_URI, "SubmitDocumentRequest");
    JAXBContext jc = JAXBContext.newInstance(SubmitDocumentRequest.class);
    Marshaller marshaller = jc.createMarshaller();

    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    JAXBElement element = new JAXBElement(qname, sdr.getClass(), sdr);

    StringWriter sw = new StringWriter();

    marshaller.marshal(element, sw);

    String xml = sw.toString();

    logger.debug(xml);

    OMElement result = AXIOMUtil.stringToOM(OMAbstractFactory.getOMFactory(), xml);

    List<OMElement> list = XPathHelper.selectNodes(result, "./ns:Documents/ns:Document/ns:Content",
            URIConstants.XDSBRIDGE_URI);

    for (OMElement contentNode : list) {

        OMText binaryNode = (OMText) contentNode.getFirstOMChild();

        if (binaryNode != null) {
            binaryNode.setOptimize(true);
        }
    }

    return result;
}

From source file:dk.nsi.haiba.epimibaimporter.ws.EpimibaWebserviceClient.java

private WebServiceSoap createWebserviceClient() throws Exception {
    URL wsdlLocation = new URL(wsdlURL);
    QName serviceName = new QName("http://www.ssi.dk/", "WebService");
    WebService ws = new WebService(wsdlLocation, serviceName);
    WebServiceSoap wsClient = ws.getWebServiceSoap();
    return wsClient;
}

From source file:org.apache.servicemix.http.HttpSpringTest.java

public void testSsl() throws Exception {
    DefaultServiceMixClient client = new DefaultServiceMixClient(jbi);
    InOut me = client.createInOutExchange();
    me.setService(new QName("http://test/ssl", "MyProviderService"));
    me.getInMessage().setContent(new StringSource("<echo xmlns='http://test'><echoin0>world</echoin0></echo>"));
    client.sendSync(me);//from w w  w .  j a v a  2 s  .  c  o m
    if (me.getStatus() == ExchangeStatus.ERROR) {
        if (me.getFault() != null) {
            fail("Received fault: " + new SourceTransformer().toString(me.getFault().getContent()));
        } else if (me.getError() != null) {
            throw me.getError();
        } else {
            fail("Received ERROR status");
        }
    } else {
        logger.info(new SourceTransformer().toString(me.getOutMessage().getContent()));
    }
}

From source file:mitm.common.ws.AbstractWSProxyFactory.java

private T internalCreateProxy() {
    QName SERVICE_NAME = new QName(nsURI, localPart);
    Service service = Service.create(wsdlURL, SERVICE_NAME);

    T proxy = service.getPort(persistentClass);

    /*/*  w w  w .ja v a2s .  co  m*/
     * Make request context multithread safe. See http://markmail.org/message/lgldei2zt4trlyr6
     */
    ((BindingProvider) proxy).getRequestContext().put("thread.local.request.context", Boolean.TRUE);

    Client client = ClientProxy.getClient(proxy);

    HTTPConduit http = (HTTPConduit) client.getConduit();

    HTTPClientPolicy httpClientPolicy = new HTTPClientPolicy();

    httpClientPolicy.setConnectionTimeout(connectTimeOut);
    httpClientPolicy.setReceiveTimeout(receiveTimeOut);

    http.setClient(httpClientPolicy);

    Endpoint endpoint = client.getEndpoint();

    Map<String, Object> outProps = new HashMap<String, Object>();

    outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
    outProps.put(WSHandlerConstants.PASSWORD_TYPE, passwordMode.getMode());

    WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
    endpoint.getOutInterceptors().add(wssOut);

    return proxy;
}

From source file:net.bpelunit.framework.control.deploy.ode.ODERequestEntityFactory.java

private void prepareDeploySOAP(File file) throws IOException, SOAPException {
    MessageFactory mFactory = MessageFactory.newInstance();
    SOAPMessage message = mFactory.createMessage();
    SOAPBody body = message.getSOAPBody();

    SOAPElement xmlDeploy = body.addChildElement(ODE_ELEMENT_DEPLOY);
    SOAPElement xmlZipFilename = xmlDeploy.addChildElement(ODE_ELEMENT_ZIPNAME);
    xmlZipFilename.setTextContent(FilenameUtils.getName(file.toString()).split("\\.")[0]);

    SOAPElement xmlZipContent = xmlDeploy.addChildElement(ODE_ELEMENT_PACKAGE);
    SOAPElement xmlBase64ZipFile = xmlZipContent.addChildElement(ODE_ELEMENT_ZIP, "dep", NS_DEPLOY_SERVICE);

    xmlBase64ZipFile.addAttribute(new QName(NS_XML_MIME, CONTENT_TYPE_STRING), ZIP_CONTENT_TYPE);

    StringBuilder content = new StringBuilder();
    byte[] arr = FileUtils.readFileToByteArray(file);
    byte[] encoded = Base64.encodeBase64Chunked(arr);
    for (int i = 0; i < encoded.length; i++) {
        content.append((char) encoded[i]);
    }// ww  w. j a  v a  2 s.c  om

    xmlBase64ZipFile.setTextContent(content.toString());

    ByteArrayOutputStream b = new ByteArrayOutputStream();
    message.writeTo(b);
    fContent = b.toString();
}

From source file:com.evolveum.midpoint.web.component.input.QNameEditorPanel.java

public QNameEditorPanel(String id, IModel<ItemPathType> model, String localPartTooltipKey,
        String namespaceTooltipKey, boolean markLocalPartAsRequired, boolean markNamespaceAsRequired) {
    super(id, model);
    this.itemPathModel = model;

    localpartModel = new IModel<String>() {
        @Override//from   w w  w . ja v  a  2s .  c  o m
        public String getObject() {
            QName qName = itemPathToQName();
            return qName != null ? qName.getLocalPart() : null;
        }

        @Override
        public void setObject(String object) {
            if (object == null) {
                itemPathModel.setObject(null);
            } else {
                itemPathModel.setObject(
                        new ItemPathType(new ItemPath(new QName(namespaceModel.getObject(), object))));
            }
        }

        @Override
        public void detach() {
        }
    };
    namespaceModel = new IModel<String>() {
        @Override
        public String getObject() {
            QName qName = itemPathToQName();
            return qName != null ? qName.getNamespaceURI() : null;
        }

        @Override
        public void setObject(String object) {
            if (StringUtils.isBlank(localpartModel.getObject())) {
                itemPathModel.setObject(null);
            } else {
                itemPathModel.setObject(
                        new ItemPathType(new ItemPath(new QName(object, localpartModel.getObject()))));
            }
        }

        @Override
        public void detach() {
        }
    };

    initLayout(localPartTooltipKey, namespaceTooltipKey, markLocalPartAsRequired, markNamespaceAsRequired);
}

From source file:com.mirth.connect.connectors.ws.WebServiceConnectorService.java

public Object invoke(String method, Object object, String sessionsId) throws Exception {
    if (method.equals("cacheWsdlFromUrl")) {
        Map<String, String> params = (Map<String, String>) object;
        String wsdlUrl = params.get("wsdlUrl");
        URI wsdlUri = new URI(wsdlUrl);
        String username = params.get("username");
        String password = params.get("password");
        wsdlInterfaceCache.put(wsdlUrl, getWsdlInterface(wsdlUri, username, password));
    } else if (method.equals("isWsdlCached")) {
        String id = (String) object;
        return (wsdlInterfaceCache.get(id) != null);
    } else if (method.equals("getOperations")) {
        String id = (String) object;
        WsdlInterface wsdlInterface = wsdlInterfaceCache.get(id);
        return getOperations(wsdlInterface);
    } else if (method.equals("getService")) {
        String id = (String) object;
        WsdlInterface wsdlInterface = wsdlInterfaceCache.get(id);

        if (MapUtils.isNotEmpty(wsdlInterface.getWsdlContext().getDefinition().getServices())) {
            Service service = (Service) wsdlInterface.getWsdlContext().getDefinition().getServices().values()
                    .iterator().next();/*from   w ww.j av a  2s .  com*/
            return service.getQName().toString();
        }
    } else if (method.equals("getPort")) {
        String id = (String) object;
        WsdlInterface wsdlInterface = wsdlInterfaceCache.get(id);

        if (MapUtils.isNotEmpty(wsdlInterface.getWsdlContext().getDefinition().getServices())) {
            Service service = (Service) wsdlInterface.getWsdlContext().getDefinition().getServices().values()
                    .iterator().next();
            Port port = (Port) service.getPorts().values().iterator().next();
            QName qName = new QName(service.getQName().getNamespaceURI(), port.getName());
            return qName.toString();
        }
    } else if (method.equals("generateEnvelope")) {
        Map<String, String> params = (Map<String, String>) object;
        String id = params.get("id");
        String operationName = params.get("operation");
        WsdlInterface wsdlInterface = wsdlInterfaceCache.get(id);
        return buildEnvelope(wsdlInterface, operationName);
    } else if (method.equals("getSoapAction")) {
        Map<String, String> params = (Map<String, String>) object;
        String id = params.get("id");
        String operationName = params.get("operation");
        WsdlInterface wsdlInterface = wsdlInterfaceCache.get(id);
        return wsdlInterface.getOperationByName(operationName).getAction();
    }

    return null;
}