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:com.temenos.useragent.generic.mediatype.AtomPayloadHandler.java

@Override
public void setPayload(String payload) {
    if (payload == null) {
        throw new IllegalArgumentException("Payload is null");
    }/*from  w w  w  .j a  va  2 s  . c  om*/
    Document<Element> payloadDoc = null;
    try {
        payloadDoc = new Abdera().getParser().parse(IOUtils.toInputStream(payload));
    } catch (Exception e) {
        throw new IllegalArgumentException("Unexpected payload for media type '" + AtomUtil.MEDIA_TYPE + "'.",
                e);
    }
    QName rootElementQName = payloadDoc.getRoot().getQName();
    if (new QName(AtomUtil.NS_ATOM, "feed").equals(rootElementQName)) {
        feed = (Feed) payloadDoc.getRoot();
        isCollection = true;
    } else if (new QName(AtomUtil.NS_ATOM, "entry").equals(rootElementQName)) {
        entityTransformer.setEntry((Entry) payloadDoc.getRoot());
        isCollection = false;
    } else {
        throw new IllegalArgumentException("Unexpected payload for media type '" + AtomUtil.MEDIA_TYPE
                + "'. Payload [" + payloadDoc.getRoot().toString() + "]");
    }
}

From source file:fi.mystes.synapse.mediator.ReadFileMediator.java

/**
 * Invokes the mediator passing the current message for mediation. Each
 * mediator performs its mediation action, and returns true if mediation
 * should continue, or false if further mediation should be aborted.
 *
 * @param context/*from  w  w w.jav  a 2s . c om*/
 *            Current message context for mediation
 * @return true if further mediation should continue, otherwise false
 */
@Override
public boolean mediate(MessageContext context) {
    SynapseLog synLog = getLog(context);

    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Starting ReadFileMediator");
    }

    SOAPBody body = context.getEnvelope().getBody();

    try {

        InputStream inputStream = initProcessableFile(context);

        if (contentType != null) {

            OMElement fileElement = null;
            try {
                if (contentType.equalsIgnoreCase("text/plain")) {
                    fileElement = OMAbstractFactory.getOMFactory()
                            .createOMElement(new QName("http://ws.apache.org/commons/ns/payload", "text"));

                    StringWriter writer = new StringWriter();
                    IOUtils.copy(inputStream, writer, "UTF-8");
                    String content = writer.toString();
                    context.getEnvelope().getBody().getFirstElement().detach();
                    fileElement.setText(content);

                } else if (contentType.equalsIgnoreCase("xml")) {
                    fileElement = new StAXOMBuilder(inputStream).getDocumentElement();
                }

            } catch (Exception e) {
                synLog.error("Error while parsing file : " + fileName);
                context.setProperty("READ_FILE_RESPONSE", "Error while parsing file : " + fileName);
            }
            appendFileContentIntoGivenElement(context, body, fileElement);

        } else {
            if (synLog.isTraceOrDebugEnabled()) {
                synLog.traceOrDebug("Content Type of file " + fileName + "unknown or not declared.");
            }
            context.setProperty("READ_FILE_RESPONSE",
                    "Content Type of file " + fileName + " unknown or not declared.");
        }
    } catch (Exception e) {
        if (synLog.isTraceOrDebugEnabled()) {
            synLog.traceOrDebug("Error trying to read file " + fileName + ". " + e.getMessage());
        }
        context.setProperty("READ_FILE_RESPONSE",
                "Error trying to read file " + fileName + ". " + e.getMessage());
    }

    if (synLog.isTraceOrDebugEnabled()) {
        synLog.traceOrDebug("Ending ReadFileMediator");
    }
    context.setProperty("READ_FILE_RESPONSE", "OK");
    return true;
}

From source file:org.cleverbus.modules.in.hello.AsyncHelloRoute.java

/**
 * Route for asynchronous <strong>asyncHello</strong> input operation.
 * <p/>/*from   w  ww .j a v  a 2s. c  om*/
 * Prerequisite: none
 * <p/>
 * Output: {@link AsyncHelloResponse}
 */
private void createRouteForAsyncHelloRouteIn() {
    Namespaces ns = new Namespaces("h", SyncHelloRoute.HELLO_SERVICE_NS);

    // note: mandatory parameters are set already in XSD, this validation is extra
    XPathValidator validator = new XPathValidator("/h:asyncHelloRequest", ns, "h:name");

    // note: only shows using but without any influence in this case
    Expression nameExpr = xpath("/h:asyncHelloRequest/h:name").namespaces(ns).stringResult();

    AsynchRouteBuilder.newInstance(ServiceEnum.HELLO, OPERATION_NAME,
            getInWsUri(new QName(SyncHelloRoute.HELLO_SERVICE_NS, "asyncHelloRequest")),
            new AsynchResponseProcessor() {
                @Override
                protected Object setCallbackResponse(CallbackResponse callbackResponse) {
                    AsyncHelloResponse res = new AsyncHelloResponse();
                    res.setConfirmAsyncHello(callbackResponse);
                    return res;
                }
            }, jaxb(AsyncHelloResponse.class))

            .withValidator(validator).withObjectIdExpr(nameExpr).build(this);
}

From source file:net.shibboleth.idp.cas.flow.BuildSamlValidationFailureMessageAction.java

@Nonnull
@Override/*ww w.  j  a  va 2  s .co m*/
protected Response buildSamlResponse(final @Nonnull RequestContext springRequestContext,
        final @Nonnull ProfileRequestContext<SAMLObject, SAMLObject> profileRequestContext) {

    final String code = (String) springRequestContext.getFlashScope().get("code");
    final String detailCode = (String) springRequestContext.getFlashScope().get("detailCode");

    final Response response = newSAMLObject(Response.class, Response.DEFAULT_ELEMENT_NAME);
    final Status status = newSAMLObject(Status.class, Status.DEFAULT_ELEMENT_NAME);
    final StatusCode statusCode = newSAMLObject(StatusCode.class, StatusCode.DEFAULT_ELEMENT_NAME);
    statusCode.setValue(new QName(NAMESPACE, code));
    status.setStatusCode(statusCode);
    final StatusMessage message = newSAMLObject(StatusMessage.class, StatusMessage.DEFAULT_ELEMENT_NAME);
    message.setMessage(detailCode);
    status.setStatusMessage(message);
    response.setStatus(status);

    return response;
}

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

public void testNonSoap() throws Exception {
    EchoComponent echo = new EchoComponent();
    echo.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService"));
    echo.setEndpoint("service");
    container.activateComponent(echo, "echo");

    HttpComponent http = new HttpComponent();

    HttpConsumerEndpoint ep0 = new HttpConsumerEndpoint();
    ep0.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService"));
    ep0.setEndpoint("consumer");
    ep0.setTargetService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService"));
    ep0.setTargetEndpoint("service");
    ep0.setLocationURI("http://localhost:8192/person/");

    HttpProviderEndpoint ep1 = new HttpProviderEndpoint();
    ep1.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService2"));
    ep1.setEndpoint("provider");
    ep1.setLocationURI("http://localhost:8192/person/");

    http.setEndpoints(new HttpEndpointType[] { ep0, ep1 });
    container.activateComponent(http, "http");
    container.start();//  ww  w.j  ava 2  s.  com

    ServiceMixClient client = new DefaultServiceMixClient(container);
    InOut me = client.createInOutExchange();
    me.setService(new QName("http://servicemix.apache.org/samples/wsdl-first", "PersonService2"));
    me.setOperation(new QName("http://servicemix.apache.org/samples/wsdl-first", "GetPerson"));
    me.getInMessage().setContent(
            new StringSource("<jbi:message xmlns:jbi=\"http://java.sun.com/xml/ns/jbi/wsdl-11-wrapper\""
                    + "             xmlns:msg=\"http://servicemix.apache.org/samples/wsdl-first/types\" "
                    + "             name=\"Hello\" " + "             type=\"msg:HelloRequest\" "
                    + "             version=\"1.0\">" + "  <jbi:part>"
                    + "    <msg:GetPerson><msg:personId>id</msg:personId></msg:GetPerson>" + "  </jbi:part>"
                    + "</jbi:message>"));
    client.sendSync(me);
    System.err.println(new SourceTransformer().contentToString(me.getOutMessage()));
    client.done(me);
}

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

/**
 * Parses the certificates from the credential configuration.
 * //from w  ww.  ja v a2  s .c  om
 * @param configChildren children of the credential element
 * @param builder credential 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 x509 credential 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;
        }

        boolean isEntityCert = false;
        Attr entityCertAttr = certElem.getAttributeNodeNS(null, "entityCertificate");
        if (entityCertAttr != null) {
            isEntityCert = XMLHelper.getAttributeValueAsBoolean(entityCertAttr);
        }
        if (isEntityCert) {
            log.debug("Element config flag found indicating entity certificate");
        }

        try {
            decodedCerts = X509Util.decodeCertificate(encodedCert);
            certs.addAll(decodedCerts);
            if (isEntityCert) {
                if (decodedCerts.size() == 1) {
                    builder.addPropertyValue("entityCertificate", decodedCerts.iterator().next());
                } else {
                    throw new FatalBeanException(
                            "Config element indicated an entityCertificate, but multiple certs where decoded");
                }
            }
        } catch (CertificateException e) {
            throw new FatalBeanException("Unable to create X509 credential, unable to parse certificates", e);
        }
    }

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

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

@Test
public void singleFieldShouldBeConsidered() {
    Query query = deriveQueryFromMethod("findByLastname", "foo");

    assertCriteria(query.getCriteria(), is(new QName("http://spring.data.marklogic/test/contact", "lastname")),
            is("foo"));
}

From source file:com.evolveum.midpoint.model.impl.rest.MidpointAbstractProvider.java

@Override
public void writeTo(T object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType,
        MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
        throws IOException, WebApplicationException {

    // TODO implement in the standard serializer; also change root name
    QName fakeQName = new QName(PrismConstants.NS_PREFIX + "debug", "debugPrintObject");
    String xml;//from   ww w .j  a va2  s  .c om

    PrismSerializer<String> serializer = getSerializer();

    try {
        if (object instanceof PrismObject) {
            xml = serializer.serialize((PrismObject<?>) object);
        } else if (object instanceof OperationResult) {
            OperationResultType operationResultType = ((OperationResult) object).createOperationResultType();
            xml = serializer.serializeAnyData(operationResultType, fakeQName);
        } else {
            xml = serializer.serializeAnyData(object, fakeQName);
        }
        entityStream.write(xml.getBytes("utf-8"));
    } catch (SchemaException | RuntimeException e) {
        LoggingUtils.logException(LOGGER, "Couldn't marshal element to string: {}", e, object);
    }
}

From source file:com.ea.core.bridge.ws.soap.client.SoapClient.java

private QName getQName(Endpoint endpoint, String methodName) {
    BindingInfo bindingInfo = endpoint.getEndpointInfo().getBinding();
    QName opName = new QName(endpoint.getService().getName().getNamespaceURI(), methodName);

    if (bindingInfo.getOperation(opName) == null) {
        for (BindingOperationInfo operationInfo : bindingInfo.getOperations()) {
            if (methodName.equals(operationInfo.getName().getLocalPart())) {
                opName = operationInfo.getName();
                break;
            }//from   ww w  . j  a  va2  s .co m
        }
    }
    return opName;
}

From source file:org.apache.cxf.fediz.service.idp.STSKrbAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    // We only handle KerberosServiceRequestTokens
    if (!(authentication instanceof KerberosServiceRequestToken)) {
        return null;
    }//  w ww .  j av a2 s  . c om

    Bus cxfBus = getBus();
    IdpSTSClient sts = new IdpSTSClient(cxfBus);
    sts.setAddressingNamespace("http://www.w3.org/2005/08/addressing");
    if (tokenType != null && tokenType.length() > 0) {
        sts.setTokenType(tokenType);
    } else {
        sts.setTokenType(WSConstants.WSS_SAML2_TOKEN_TYPE);
    }
    sts.setKeyType(HTTP_DOCS_OASIS_OPEN_ORG_WS_SX_WS_TRUST_200512_BEARER);
    sts.setWsdlLocation(wsdlLocation);
    sts.setServiceQName(new QName(namespace, wsdlService));
    sts.setEndpointQName(new QName(namespace, wsdlEndpoint));

    sts.getProperties().putAll(properties);
    if (use200502Namespace) {
        sts.setNamespace(HTTP_SCHEMAS_XMLSOAP_ORG_WS_2005_02_TRUST);
    }

    if (lifetime != null) {
        sts.setEnableLifetime(true);
        sts.setTtl(lifetime.intValue());
    }

    return handleKerberos((KerberosServiceRequestToken) authentication, sts);
}