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:be.fedict.eid.pkira.contracts.EIDPKIRAContractsClient.java

/**
 * Marshals the JAXB contract to a DOM document.
 * //w ww . j  av a  2s .c om
 * @param contractDocument
 *            document to marshal.
 * @return the text in the XML.
 * @throws XmlMarshallingException
 *             when this fails.
 */
public <T extends EIDPKIRAContractType> Document marshalToDocument(T contractDocument, Class<T> clazz)
        throws XmlMarshallingException {
    QName qname = new QName(NAMESPACE, getElementNameForType(clazz));
    JAXBElement<T> jaxbElement = new JAXBElement<T>(qname, clazz, contractDocument);

    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        dbf.setNamespaceAware(true);
        Document document = dbf.newDocumentBuilder().newDocument();

        getMarshaller().marshal(jaxbElement, document);

        return document;
    } catch (JAXBException e) {
        throw new XmlMarshallingException("Cannot marshal XML object.", e);
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.deegree.securityproxy.wfs.responsefilter.capabilities.WfsCapabilitiesModificationManagerCreator.java

private LinkedList<ElementPathStep> createBasePath() {
    LinkedList<ElementPathStep> path = new LinkedList<ElementPathStep>();
    path.add(new ElementPathStep(new QName("http://www.opengis.net/wfs", "WFS_Capabilities")));
    path.add(new ElementPathStep(new QName("http://www.opengis.net/ows", "OperationsMetadata")));
    path.add(new ElementPathStep(new QName("http://www.opengis.net/ows", "Operation")));
    path.add(new ElementPathStep(new QName("http://www.opengis.net/ows", "DCP")));
    path.add(new ElementPathStep(new QName("http://www.opengis.net/ows", "HTTP")));
    return path;//ww  w.j a  va 2 s  . c  o m
}

From source file:org.javelin.sws.ext.bind.internal.model.ClassHierarchyTest.java

@Test
public void handleXmlAccessTypeField() throws Exception {
    // f1, f2, f3, f4, p3, p4 - fields and annotated properties
    System.out.println("\nC2");
    JAXBContext.newInstance(C2.class).createMarshaller()
            .marshal(new JAXBElement<C2>(new QName("", "r"), C2.class, new C2()), System.out);
    JAXBContext ctx = SweJaxbContextFactory.createContext(new Class[] { C2.class }, null);
    Map<Class<?>, TypedPattern<?>> patterns = (Map<Class<?>, TypedPattern<?>>) ReflectionTestUtils.getField(ctx,
            "patterns");
    ComplexTypePattern<C2> pattern = (ComplexTypePattern<C2>) patterns.get(C2.class);
    Map<QName, PropertyMetadata<C2, ?>> elements = (Map<QName, PropertyMetadata<C2, ?>>) ReflectionTestUtils
            .getField(pattern, "elements");
    assertThat(elements.size(), equalTo(6));
    assertTrue(elements.containsKey(new QName("", "f1")));
    assertTrue(elements.containsKey(new QName("", "f2")));
    assertTrue(elements.containsKey(new QName("", "f3")));
    assertTrue(elements.containsKey(new QName("", "f4")));
    assertTrue(elements.containsKey(new QName("", "p3")));
    assertTrue(elements.containsKey(new QName("", "p4")));
}

From source file:com.profesorfalken.payzen.webservices.sdk.handler.soap.HeaderHandler.java

private void addHeaderField(SOAPHeader header, String fieldName, String value) throws SOAPException {
    QName qname = new QName(NAMESPACE, fieldName);
    SOAPElement element = header.addChildElement(qname);
    element.addTextNode(value);/*  ww  w .ja  va 2 s .c  o m*/
}

From source file:org.apache.servicemix.jms.JMSComponentTest.java

public void testProviderInOut() throws Exception {
    // JMS Component
    JmsComponent component = new JmsComponent();
    container.activateComponent(component, "JMSComponent");

    // Add a jms receiver
    JmsServiceComponent jmsReceiver = new JmsServiceComponent();
    jmsTemplate.setDefaultDestinationName("queue/A");
    jmsReceiver.setTemplate(jmsTemplate);
    jmsReceiver.afterPropertiesSet();/*from w w  w.  j  a v  a2  s . c  o  m*/
    ActivationSpec asJmsReceiver = new ActivationSpec("jmsReceiver", jmsReceiver);
    asJmsReceiver.setDestinationService(new QName("test", "receiver"));
    container.activateComponent(asJmsReceiver);

    // Add an echo component
    EchoComponent echo = new EchoComponent();
    ActivationSpec asEcho = new ActivationSpec("receiver", echo);
    asEcho.setService(new QName("test", "receiver"));
    container.activateComponent(asEcho);

    // Deploy SU
    URL url = getClass().getClassLoader().getResource("provider/jms.wsdl");
    File path = new File(new URI(url.toString()));
    path = path.getParentFile();
    component.getServiceUnitManager().deploy("provider", path.getAbsolutePath());
    component.getServiceUnitManager().init("provider", path.getAbsolutePath());
    component.getServiceUnitManager().start("provider");

    // Call it
    InOut inout = client.createInOutExchange();
    inout.setInterfaceName(new QName("http://jms.servicemix.org/Test", "ProviderInterface"));
    inout.getInMessage().setContent(new StringSource("<hello>world</hello>"));
    boolean result = client.sendSync(inout);
    assertTrue(result);
    NormalizedMessage out = inout.getOutMessage();
    assertNotNull(out);
    Source src = out.getContent();
    assertNotNull(src);
    logger.info(new SourceTransformer().toString(src));
}

From source file:edu.internet2.middleware.shibboleth.common.config.attribute.resolver.dataConnector.RDBMSDataConnectorBeanDefinitionParser.java

/**
 * Processes the connection management configuration.
 * //  w  ww.ja va 2  s.  c  o  m
 * @param pluginId ID of the data connector
 * @param pluginConfig configuration element for the data connector
 * @param pluginConfigChildren child config elements for the data connect
 * @param pluginBuilder builder of the data connector
 * @param parserContext current configuration parsing context
 */
protected void processConnectionManagement(String pluginId, Element pluginConfig,
        Map<QName, List<Element>> pluginConfigChildren, BeanDefinitionBuilder pluginBuilder,
        ParserContext parserContext) {
    DataSource datasource;
    List<Element> cmc = pluginConfigChildren
            .get(new QName(DataConnectorNamespaceHandler.NAMESPACE, "ContainerManagedConnection"));
    if (cmc != null && cmc.get(0) != null) {
        datasource = buildContainerManagedConnection(pluginId, cmc.get(0));
    } else {
        datasource = buildApplicationManagedConnection(pluginId,
                pluginConfigChildren
                        .get(new QName(DataConnectorNamespaceHandler.NAMESPACE, "ApplicationManagedConnection"))
                        .get(0));
    }

    pluginBuilder.addPropertyValue("connectionDataSource", datasource);
}

From source file:com.wandrell.example.swss.test.util.test.unit.client.AbstractTestEntityClientHeader.java

/**
 * Tests that the client can handle incorrectly formed SOAP messages.
 *
 * @throws IOException/*from www. ja v a 2  s  .  c  o m*/
 *             if there is any problem loading the entity schema file
 */
@Test
public final void testClient_Header_Invalid() throws IOException {
    final MockWebServiceServer mockServer; // Mocked server
    final RequestMatcher requestMatcher; // Matcher for the request
    final ResponseCreator responseCreator; // Creator for the response
    final ExampleEntity result; // Queried entity

    // Creates the request matcher
    requestMatcher = RequestMatchers.soapHeader(new QName(secHeaderUri, secHeaderLocalPart));

    // Creates the response
    responseCreator = ResponseCreators.withPayload(new ClassPathResource(responsePayloadInvalidPath));

    // Creates the server mock
    mockServer = MockWebServiceServer.createServer(client);
    mockServer.expect(requestMatcher).andRespond(responseCreator);

    // Calls the server mock
    result = client.getEntity("http:somewhere.com", entityId);

    Assert.assertEquals(result.getId(), new Integer(-1));
    Assert.assertEquals(result.getName(), "");

    mockServer.verify();
}

From source file:org.wso2.carbon.apimgt.gateway.handlers.Utils.java

public static void setSOAPFault(MessageContext messageContext, String code, String reason, String detail) {
    SOAPFactory factory = (messageContext.isSOAP11() ? OMAbstractFactory.getSOAP11Factory()
            : OMAbstractFactory.getSOAP12Factory());

    OMDocument soapFaultDocument = factory.createOMDocument();
    SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
    soapFaultDocument.addChild(faultEnvelope);

    SOAPFault fault = faultEnvelope.getBody().getFault();
    if (fault == null) {
        fault = factory.createSOAPFault();
    }//from w  w  w  .  j a  v  a2 s  . c  o m

    SOAPFaultCode faultCode = factory.createSOAPFaultCode();
    if (messageContext.isSOAP11()) {
        faultCode.setText(new QName(fault.getNamespace().getNamespaceURI(), code));
    } else {
        SOAPFaultValue value = factory.createSOAPFaultValue(faultCode);
        value.setText(new QName(fault.getNamespace().getNamespaceURI(), code));
    }
    fault.setCode(faultCode);

    SOAPFaultReason faultReason = factory.createSOAPFaultReason();
    if (messageContext.isSOAP11()) {
        faultReason.setText(reason);
    } else {
        SOAPFaultText text = factory.createSOAPFaultText();
        text.setText(reason);
        text.setLang("en");
        faultReason.addSOAPText(text);
    }
    fault.setReason(faultReason);

    SOAPFaultDetail soapFaultDetail = factory.createSOAPFaultDetail();
    soapFaultDetail.setText(detail);
    fault.setDetail(soapFaultDetail);

    // set the all headers of original SOAP Envelope to the Fault Envelope
    if (messageContext.getEnvelope() != null) {
        SOAPHeader soapHeader = messageContext.getEnvelope().getHeader();
        if (soapHeader != null) {
            for (Iterator iterator = soapHeader.examineAllHeaderBlocks(); iterator.hasNext();) {
                Object o = iterator.next();
                if (o instanceof SOAPHeaderBlock) {
                    SOAPHeaderBlock header = (SOAPHeaderBlock) o;
                    faultEnvelope.getHeader().addChild(header);
                } else if (o instanceof OMElement) {
                    faultEnvelope.getHeader().addChild((OMElement) o);
                }
            }
        }
    }

    try {
        messageContext.setEnvelope(faultEnvelope);
    } catch (AxisFault af) {
        log.error("Error while setting SOAP fault as payload", af);
        return;
    }

    if (messageContext.getFaultTo() != null) {
        messageContext.setTo(messageContext.getFaultTo());
    } else if (messageContext.getReplyTo() != null) {
        messageContext.setTo(messageContext.getReplyTo());
    } else {
        messageContext.setTo(null);
    }

    // set original messageID as relatesTo
    if (messageContext.getMessageID() != null) {
        RelatesTo relatesTo = new RelatesTo(messageContext.getMessageID());
        messageContext.setRelatesTo(new RelatesTo[] { relatesTo });
    }
}

From source file:com._4dconcept.springframework.data.marklogic.repository.query.PartTreeMarklogicQueryTest.java

@Test
public void deepFieldsShouldBeConsidered() {
    Query query = deriveQueryFromMethod("findByAddressCountry", "France");
    assertCriteria(query.getCriteria(), is(new QName("http://spring.data.marklogic/test/contact", "country")),
            is("France"));
}

From source file:in.gov.uidai.auth.aua.httpclient.BfdClient.java

private String generateSignedBfdXML(Bfd bfd) throws JAXBException, Exception {
    StringWriter bfdXML = new StringWriter();

    JAXBElement<Bfd> bfdElement = new JAXBElement<Bfd>(
            new QName("http://www.uidai.gov.in/authentication/uid-bfd-request/1.0", "Bfd"), Bfd.class, bfd);

    JAXBContext.newInstance(Bfd.class).createMarshaller().marshal(bfdElement, bfdXML);
    boolean includeKeyInfo = true;

    if (System.getenv().get("SKIP_DIGITAL_SIGNATURE") != null) {
        return bfdXML.toString();
    } else {/*from  w ww  .  java  2s  . c  o m*/
        return this.digitalSignator.signXML(bfdXML.toString(), includeKeyInfo);
    }
}