Example usage for javax.xml.namespace QName valueOf

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

Introduction

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

Prototype

public static QName valueOf(String qNameAsString) 

Source Link

Document

<p><code>QName</code> derived from parsing the formatted <code>String</code>.</p> <p>If the <code>String</code> is <code>null</code> or does not conform to #toString() QName.toString() formatting, an <code>IllegalArgumentException</code> is thrown.</p> <p><em>The <code>String</code> <strong>MUST</strong> be in the form returned by #toString() QName.toString() .</em></p> <p>The commonly accepted way of representing a <code>QName</code> as a <code>String</code> was <a href="http://jclark.com/xml/xmlns.htm">defined</a> by James Clark.

Usage

From source file:com.centeractive.ws.builder.core.WsdlParser.java

public SoapBuilder getBuilder(String bindingName, SoapContext context) {
    return getBuilder(QName.valueOf(bindingName), context);
}

From source file:org.apache.servicemix.jbi.cluster.engine.AbstractClusterEndpointTest.java

protected ProxyEndpoint createProxy(NMR nmr, ClusterEngine cluster) throws Exception {
    ProxyEndpoint proxy = new ProxyEndpoint(QName.valueOf("{urn:test}receiver"));
    nmr.getEndpointRegistry().register(proxy,
            ServiceHelper.createMap(Endpoint.NAME, PROXY_ENDPOINT_NAME, Endpoint.SERVICE_NAME,
                    "{urn:test}proxy", Endpoint.ENDPOINT_NAME, "endpoint",
                    AbstractComponentContext.INTERNAL_ENDPOINT, "true"));
    SimpleClusterRegistration reg = new SimpleClusterRegistration();
    reg.setEndpoint(proxy);// w w w. j a va 2s  .  c om
    reg.init();
    cluster.register(reg, null);
    return proxy;
}

From source file:org.cleverbus.core.common.ws.HeaderAndPayloadValidatingInterceptor.java

/**
 * Sets request root element names which will be ignored from trace header checking.
 *
 * @param ignoreRequests the array of element names, e.g.
 *                       {@code {http://cleverbus.org/ws/SubscriberService-v1}getCounterDataRequest }
 *///from   w w w  .j  ava2 s  . c o  m
public void setIgnoreRequests(Collection<String> ignoreRequests) {
    this.ignoreRequests = new HashSet<QName>();
    for (String ignoreRequest : ignoreRequests) {
        this.ignoreRequests.add(QName.valueOf(ignoreRequest));
    }
}

From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.auth.OpenStackAuthenticationProviderTest.java

@Test
public void retrieveUserTest_systemFiware() throws AuthenticationConnectionException {
    String adminToken = "fa63ea912a2a579c2542dbb90951d500";

    OpenStackAuthenticationProvider openStackAuthenticationProvider = new OpenStackAuthenticationProvider();
    openStackAuthenticationProvider.setAdminPass("admin");
    openStackAuthenticationProvider.setAdminTenant("00000000000000000000000000000001");
    openStackAuthenticationProvider.setAdminUser("admin");
    openStackAuthenticationProvider.setKeystoneURL("http://keystone.test");
    openStackAuthenticationProvider.setThresholdString("1");
    openStackAuthenticationProvider.setCloudSystem("FIWARE");
    openStackAuthenticationToken = mock(OpenStackAuthenticationToken.class);
    openStackAuthenticationProvider.oSAuthToken = openStackAuthenticationToken;
    Client client = mock(Client.class);
    openStackAuthenticationProvider.setClient(client);
    WebTarget webResource = mock(WebTarget.class);
    Invocation.Builder builder = mock(Invocation.Builder.class);
    WebTarget webResource2 = mock(WebTarget.class);
    Invocation.Builder builder2 = mock(Invocation.Builder.class);
    Response clientResponse = mock(Response.class);
    Response response401 = mock(Response.class);
    AuthenticateResponse authenticateResponse = mock(AuthenticateResponse.class);

    // when//  w w w  .j av a2s . co m
    when(openStackAuthenticationToken.getCredentials()).thenReturn(new String[] { adminToken, "string2" });
    when(client.target("http://keystone.test")).thenReturn(webResource).thenReturn(webResource2);
    when(webResource.path(any(String.class))).thenReturn(webResource);
    when(webResource.request()).thenReturn(builder);
    when(builder.header(anyString(), anyString())).thenReturn(builder);
    when(builder.header(eq("X-Auth-Token"), anyString())).thenReturn(builder);
    when(builder.get()).thenReturn(response401);
    when(response401.getStatus()).thenReturn(401);

    when(webResource2.path(any(String.class))).thenReturn(webResource2);
    when(webResource2.request()).thenReturn(builder2);
    when(builder2.header(anyString(), anyString())).thenReturn(builder2);
    when(builder2.header(eq("X-Auth-Token"), anyString())).thenReturn(builder2);
    when(builder2.get(AuthenticateResponse.class)).thenReturn(authenticateResponse);

    Token validToken = mock(Token.class);
    TenantForAuthenticateResponse tenantForAuthenticateResponse = mock(TenantForAuthenticateResponse.class);
    UserForAuthenticateResponse userForAuthenticateResponse = mock(UserForAuthenticateResponse.class);
    when(authenticateResponse.getToken()).thenReturn(validToken);
    when(validToken.getTenant()).thenReturn(tenantForAuthenticateResponse);
    when(tenantForAuthenticateResponse.getId()).thenReturn("user tenantId");
    when(authenticateResponse.getUser()).thenReturn(userForAuthenticateResponse);
    when(userForAuthenticateResponse.getRoles()).thenReturn(null);
    Map<QName, String> collection = new HashMap<QName, String>();
    collection.put(QName.valueOf("username"), "value");
    when(userForAuthenticateResponse.getOtherAttributes()).thenReturn(collection);

    UsernamePasswordAuthenticationToken authentication = mock(UsernamePasswordAuthenticationToken.class);
    when(authentication.getCredentials()).thenReturn("user tenantId");

    UserDetails user = openStackAuthenticationProvider.retrieveUser("pepe", authentication);

    assertNotNull(user);
    verify(openStackAuthenticationToken, times(2)).getCredentials();
    verify(authentication, times(2)).getCredentials();

}

From source file:edu.jhu.hlt.concrete.ingesters.webposts.WebPostIngester.java

@Override
public Communication fromCharacterBasedFile(final Path path) throws IngestException {
    if (!Files.exists(path))
        throw new IngestException("No file at: " + path.toString());

    AnalyticUUIDGeneratorFactory f = new AnalyticUUIDGeneratorFactory();
    AnalyticUUIDGenerator g = f.create();
    Communication c = new Communication();
    c.setUuid(g.next());//from   w w  w  .ja v a 2  s.c om
    c.setType(this.getKind());
    c.setMetadata(TooledMetadataConverter.convert(this));

    try {
        ExistingNonDirectoryFile ef = new ExistingNonDirectoryFile(path);
        c.setId(ef.getName().split("\\.")[0]);
    } catch (NoSuchFileException | NotFileException e) {
        // might throw if path is a directory.
        throw new IngestException(path.toString() + " is not a file, or is a directory.");
    }

    String content;
    try (InputStream is = Files.newInputStream(path);
            BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 8);) {
        content = IOUtils.toString(bin, StandardCharsets.UTF_8);
        c.setText(content);
    } catch (IOException e) {
        throw new IngestException(e);
    }

    try (InputStream is = Files.newInputStream(path);
            BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 8);
            BufferedReader reader = new BufferedReader(new InputStreamReader(bin, StandardCharsets.UTF_8));) {
        XMLEventReader rdr = null;
        try {
            rdr = inF.createXMLEventReader(reader);

            // Below method moves the reader
            // to the headline end element.
            Section headline = this.handleBeginning(rdr, content, c);
            headline.setUuid(g.next());
            c.addToSectionList(headline);
            TextSpan sts = headline.getTextSpan();
            LOGGER.debug("headline text: {}", c.getText().substring(sts.getStart(), sts.getEnding()));

            int sectNumber = 1;
            int subSect = 0;

            int currOff = -1;
            // Big amounts of characters.
            while (rdr.hasNext()) {
                XMLEvent nextEvent = rdr.nextEvent();
                currOff = nextEvent.getLocation().getCharacterOffset();

                // First: see if document is going to end.
                // If yes: exit.
                if (nextEvent.isEndDocument())
                    break;

                // region
                // enables ingestion of quotes inside a usenet webpost.
                // by Tongfei Chen
                if (nextEvent.isStartElement()
                        && nextEvent.asStartElement().getName().equals(QName.valueOf("QUOTE"))) {
                    Attribute attrQuote = nextEvent.asStartElement()
                            .getAttributeByName(QName.valueOf("PREVIOUSPOST"));
                    String quote = StringEscapeUtils.escapeXml(attrQuote.getValue());
                    int location = attrQuote.getLocation().getCharacterOffset()
                            + "<QUOTE PREVIOUSPOST=\"".length();
                    Section quoteSection = new Section(g.next(), "quote")
                            .setTextSpan(new TextSpan(location, location + quote.length()));
                    c.addToSectionList(quoteSection);
                }
                // endregion

                // Check if start element.
                if (nextEvent.isCharacters()) {
                    Characters chars = nextEvent.asCharacters();
                    if (!chars.isWhiteSpace()) {
                        String fpContent = chars.getData();
                        LOGGER.debug("Character offset: {}", currOff);
                        LOGGER.debug("Character based data: {}", fpContent);

                        SimpleImmutableEntry<Integer, Integer> pads = trimSpacing(fpContent);
                        final int tsb = currOff + pads.getKey();

                        final int tse = currOff + fpContent.replace("\"", "&quot;").replace("<", "&lt;")
                                .replace(">", "&gt;").length() - (pads.getValue());
                        // MAINTAIN CORRECT TEXT SPAN
                        // CANNOT USE StringEscapeUtils.escapeXml because it will escape "'", which
                        // is not escaped in the data
                        // @tongfei

                        LOGGER.debug("Section text: {}", content.substring(tsb, tse));
                        TextSpan ts = new TextSpan(tsb, tse);
                        String sk;
                        if (subSect == 0)
                            sk = "poster";
                        else if (subSect == 1)
                            sk = "postdate";
                        else
                            sk = "post";

                        Section s = new Section();
                        s.setKind(sk);
                        s.setTextSpan(ts);
                        s.setUuid(g.next());
                        List<Integer> intList = new ArrayList<>();
                        intList.add(sectNumber);
                        intList.add(subSect);
                        s.setNumberList(intList);
                        c.addToSectionList(s);

                        subSect++;
                    }
                } else if (nextEvent.isEndElement()) {
                    EndElement ee = nextEvent.asEndElement();
                    currOff = ee.getLocation().getCharacterOffset();
                    QName name = ee.getName();
                    String localName = name.getLocalPart();
                    LOGGER.debug("Hit end element: {}", localName);
                    if (localName.equalsIgnoreCase(POST_LOCAL_NAME)) {
                        LOGGER.debug("Switching to new post.");
                        sectNumber++;
                        subSect = 0;
                    } else if (localName.equalsIgnoreCase(TEXT_LOCAL_NAME)) {
                        // done with document.
                        break;
                    }
                }
            }

            return c;

        } catch (XMLStreamException | ConcreteException | StringIndexOutOfBoundsException
                | ClassCastException x) {
            throw new IngestException(x);
        } finally {
            if (rdr != null)
                try {
                    rdr.close();
                } catch (XMLStreamException e) {
                    // not likely.
                    LOGGER.info("Error closing XMLReader.", e);
                }
        }
    } catch (IOException e) {
        throw new IngestException(e);
    }
}

From source file:org.eclipse.winery.bpmn2bpel.parser.Bpmn4JsonParser.java

protected ManagementTask createManagementTaskFromJson(JsonNode managementTaskNode) {

    if (!hasRequiredFields(managementTaskNode,
            Arrays.asList(JsonKeys.NODE_TEMPLATE, JsonKeys.NODE_OPERATION))) {
        log.warn("Ignoring mangement node: One of the fields '" + JsonKeys.NODE_TEMPLATE + "' or '"
                + JsonKeys.NODE_OPERATION + "' is missing");
        return null;
    }/*from   w  ww.jav  a 2  s.c o m*/
    String nodeTemplate = managementTaskNode.get(JsonKeys.NODE_TEMPLATE).asText();
    String nodeInterfaceName = managementTaskNode.get(JsonKeys.NODE_INTERFACE_NAME).asText();
    String nodeOperation = managementTaskNode.get(JsonKeys.NODE_OPERATION).asText();

    log.debug("Creating management task with id '" + managementTaskNode.get(JsonKeys.ID) + "', name '"
            + managementTaskNode.get(JsonKeys.NAME) + "', node template '" + nodeTemplate
            + "', node operation '" + "', node operation '" + nodeOperation + "'");

    ManagementTask task = new ManagementTask();
    task.setNodeTemplateId(QName.valueOf(nodeTemplate));
    task.setNodeOperation(nodeOperation);
    task.setInterfaceName(nodeInterfaceName);

    return task;

}

From source file:com.snaplogic.snaps.firstdata.Transaction.java

@Override
public void configure(final PropertyValues propertyValues) throws ConfigurationException {
    resourceType = propertyValues.get(RESOURCE_PROP);
    String wsdlUrl = propertyValues.get(PROP_WSDL_URL);
    String serviceName = propertyValues.get(PROP_SERVICE);
    String portName = propertyValues.get(PROP_ENDPOINT);
    String operation = propertyValues.get(PROP_OPERATION);
    String defaultValueForSubstitution = propertyValues.get(PROP_DEFAULT_VALUE);

    QName serviceQName = QName.valueOf(serviceName);
    QName portQName = QName.valueOf(portName);
    QName operationQName = QName.valueOf(operation);
    HttpContextProvider httpContextProvider = new SoapHttpContextProvider();
    clientBuilder = invocationService.createClientBuilderFor(wsdlUrl, serviceQName, portQName, operationQName,
            httpContextProvider);/*  ww  w  .  j  av  a 2  s .  com*/
    configureDispatch(clientBuilder.getDispatchClient(), clientBuilder.getSoapAction());
    editorProperty = propertyValues.getEditorProperty(soapEditorContentProvider,
            ((SOAPExecuteTemplateEvaluatorImpl) templateEvaluator).withDefaultValue(
                    useDefaultValueChecked ? defaultValueForSubstitution : XmlUtilsImpl.NO_DATA),
            soapUtils.initializeSuggestionProvider(wsdlUrl, serviceQName, portQName, operationQName,
                    clientBuilder, httpContextProvider));
    Bus bus = BusFactory.getDefaultBus(true);
    bus.getInInterceptors().add(new ResponseInterceptor());
}

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

private void createDispatch(MessageObject mo) throws Exception {
    String wsdlUrl = replacer.replaceValues(connector.getDispatcherWsdlUrl(), mo);
    String username = replacer.replaceValues(connector.getDispatcherUsername(), mo);
    String password = replacer.replaceValues(connector.getDispatcherPassword(), mo);
    String serviceName = replacer.replaceValues(connector.getDispatcherService(), mo);
    String portName = replacer.replaceValues(connector.getDispatcherPort(), mo);

    /*/*w  w w.ja  v a 2  s.c o m*/
     * The dispatch needs to be created if it hasn't been created yet
     * (null). It needs to be recreated if any of the above variables are
     * different than what were used to create the current dispatch object.
     * This could happen if variables are being used for these properties.
     */
    if (dispatch == null || !StringUtils.equals(wsdlUrl, currentWsdlUrl)
            || !StringUtils.equals(username, currentUsername) || !StringUtils.equals(password, currentPassword)
            || !StringUtils.equals(serviceName, currentServiceName)
            || !StringUtils.equals(portName, currentPortName)) {
        currentWsdlUrl = wsdlUrl;
        currentUsername = username;
        currentPassword = password;
        currentServiceName = serviceName;
        currentPortName = portName;

        URL endpointUrl = getWsdlUrl(wsdlUrl, username, password);
        QName serviceQName = QName.valueOf(serviceName);
        QName portQName = QName.valueOf(portName);

        // create the service and dispatch
        logger.debug("Creating web service: url=" + endpointUrl.toString() + ", service=" + serviceQName
                + ", port=" + portQName);
        Service service = Service.create(endpointUrl, serviceQName);

        dispatch = service.createDispatch(portQName, SOAPMessage.class, Service.Mode.MESSAGE);
    }
}

From source file:com.telefonica.euro_iaas.sdc.puppetwrapper.auth.OpenStackAuthenticationProviderTest.java

@Test
public void retrieveUserTest_systemFasttrack() throws AuthenticationConnectionException {
    String adminToken = "fa63ea912a2a579c2542dbb90951d500";

    OpenStackAuthenticationProvider openStackAuthenticationProvider = new OpenStackAuthenticationProvider();
    openStackAuthenticationProvider.setAdminPass("admin");
    openStackAuthenticationProvider.setAdminTenant("00000000000000000000000000000001");
    openStackAuthenticationProvider.setAdminUser("admin");
    openStackAuthenticationProvider.setKeystoneURL("http://keystone.test");
    openStackAuthenticationProvider.setThresholdString("1");
    openStackAuthenticationProvider.setCloudSystem("FASTTRACK");
    openStackAuthenticationToken = mock(OpenStackAuthenticationToken.class);
    openStackAuthenticationProvider.oSAuthToken = openStackAuthenticationToken;
    Client client = mock(Client.class);
    openStackAuthenticationProvider.setClient(client);
    WebTarget webResource = mock(WebTarget.class);
    Invocation.Builder builder = mock(Invocation.Builder.class);
    WebTarget webResource2 = mock(WebTarget.class);
    Invocation.Builder builder2 = mock(Invocation.Builder.class);
    Response clientResponse = mock(Response.class);
    Response response401 = mock(Response.class);
    AuthenticateResponse authenticateResponse = mock(AuthenticateResponse.class);

    // when//ww w.  j  a va 2  s.  c om
    when(openStackAuthenticationToken.getCredentials()).thenReturn(new String[] { adminToken, "string2" });
    when(client.target("http://keystone.test")).thenReturn(webResource).thenReturn(webResource2);
    when(webResource.path(any(String.class))).thenReturn(webResource);
    when(webResource.request()).thenReturn(builder);
    when(builder.header(anyString(), anyString())).thenReturn(builder);
    when(builder.header(eq("X-Auth-Token"), anyString())).thenReturn(builder);
    when(builder.get()).thenReturn(response401);
    when(response401.getStatus()).thenReturn(401);

    when(webResource2.path(any(String.class))).thenReturn(webResource2);
    when(webResource2.request()).thenReturn(builder2);
    when(builder2.header(anyString(), anyString())).thenReturn(builder2);
    when(builder2.header(eq("X-Auth-Token"), anyString())).thenReturn(builder2);
    when(builder2.get(AuthenticateResponse.class)).thenReturn(authenticateResponse);

    Token validToken = mock(Token.class);
    TenantForAuthenticateResponse tenantForAuthenticateResponse = mock(TenantForAuthenticateResponse.class);
    UserForAuthenticateResponse userForAuthenticateResponse = mock(UserForAuthenticateResponse.class);
    when(authenticateResponse.getToken()).thenReturn(validToken);
    when(validToken.getTenant()).thenReturn(tenantForAuthenticateResponse);
    when(tenantForAuthenticateResponse.getId()).thenReturn("user tenantId");
    when(authenticateResponse.getUser()).thenReturn(userForAuthenticateResponse);
    when(userForAuthenticateResponse.getRoles()).thenReturn(null);
    Map<QName, String> collection = new HashMap<QName, String>();
    collection.put(QName.valueOf("username"), "value");
    when(userForAuthenticateResponse.getOtherAttributes()).thenReturn(collection);

    UsernamePasswordAuthenticationToken authentication = mock(UsernamePasswordAuthenticationToken.class);
    when(authentication.getCredentials()).thenReturn("user tenantId");

    UserDetails user = openStackAuthenticationProvider.retrieveUser("pepe", authentication);

    assertTrue(user == null);
    verify(authentication, times(2)).getCredentials();

}

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

private void createDispatch(WebServiceDispatcherProperties webServiceDispatcherProperties,
        DispatchContainer dispatchContainer) throws Exception {
    String wsdlUrl = webServiceDispatcherProperties.getWsdlUrl();
    String username = webServiceDispatcherProperties.getUsername();
    String password = webServiceDispatcherProperties.getPassword();
    String serviceName = webServiceDispatcherProperties.getService();
    String portName = webServiceDispatcherProperties.getPort();

    /*//from  www  .  j a  v a  2 s.  co m
     * The dispatch needs to be created if it hasn't been created yet (null). It needs to be
     * recreated if any of the above variables are different than what were used to create the
     * current dispatch object. This could happen if variables are being used for these
     * properties.
     */
    if (dispatchContainer.getDispatch() == null
            || !StringUtils.equals(wsdlUrl, dispatchContainer.getCurrentWsdlUrl())
            || !StringUtils.equals(username, dispatchContainer.getCurrentUsername())
            || !StringUtils.equals(password, dispatchContainer.getCurrentPassword())
            || !StringUtils.equals(serviceName, dispatchContainer.getCurrentServiceName())
            || !StringUtils.equals(portName, dispatchContainer.getCurrentPortName())) {
        dispatchContainer.setCurrentWsdlUrl(wsdlUrl);
        dispatchContainer.setCurrentUsername(username);
        dispatchContainer.setCurrentPassword(password);
        dispatchContainer.setCurrentServiceName(serviceName);
        dispatchContainer.setCurrentPortName(portName);

        URL endpointUrl = getWsdlUrl(dispatchContainer);
        QName serviceQName = QName.valueOf(serviceName);
        QName portQName = QName.valueOf(portName);

        // create the service and dispatch
        logger.debug("Creating web service: url=" + endpointUrl.toString() + ", service=" + serviceQName
                + ", port=" + portQName);
        Service service = Service.create(endpointUrl, serviceQName);

        Dispatch<SOAPMessage> dispatch = service.createDispatch(portQName, SOAPMessage.class,
                Service.Mode.MESSAGE);

        if (timeout > 0) {
            dispatch.getRequestContext().put("com.sun.xml.internal.ws.connect.timeout", timeout);
            dispatch.getRequestContext().put("com.sun.xml.internal.ws.request.timeout", timeout);
            dispatch.getRequestContext().put("com.sun.xml.ws.connect.timeout", timeout);
            dispatch.getRequestContext().put("com.sun.xml.ws.request.timeout", timeout);
        }

        Map<String, List<String>> requestHeaders = (Map<String, List<String>>) dispatch.getRequestContext()
                .get(MessageContext.HTTP_REQUEST_HEADERS);
        if (requestHeaders == null) {
            requestHeaders = new HashMap<String, List<String>>();
        }
        dispatchContainer.setDefaultRequestHeaders(requestHeaders);

        dispatchContainer.setDispatch(dispatch);
    }
}