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(String localPart) 

Source Link

Document

QName constructor specifying the local part.

If the local part is null an IllegalArgumentException is thrown.

Usage

From source file:org.apache.axis2.transport.http.CommonsHTTPTransportSenderTest.java

static SOAPEnvelope getEnvelope() throws IOException, MessagingException {
    SOAPFactory soapFac = OMAbstractFactory.getSOAP11Factory();
    OMFactory omFac = OMAbstractFactory.getOMFactory();
    SOAPEnvelope enp = soapFac.createSOAPEnvelope();
    SOAPBody sopaBody = soapFac.createSOAPBody();

    OMElement content = omFac.createOMElement(new QName("message"));
    OMElement data1 = omFac.createOMElement(new QName("part"));
    data1.setText("sample data");

    content.addChild(data1);//from   www .  j  a va  2s. c  o m
    sopaBody.addChild(content);
    enp.addChild(sopaBody);
    return enp;
}

From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPProxyConfigurator.java

private static String getProxyHost(OMElement proxyConfiguration) throws AxisFault {
    OMElement proxyHostElement = proxyConfiguration
            .getFirstChildWithName(new QName(HTTPTransportConstants.PROXY_HOST_ELEMENT));
    if (proxyHostElement == null) {
        log.error(HTTPTransportConstants.PROXY_HOST_ELEMENT_NOT_FOUND);
        throw new AxisFault(HTTPTransportConstants.PROXY_HOST_ELEMENT_NOT_FOUND);
    }/*from w  w w.  j av a2  s.c  om*/
    String proxyHost = proxyHostElement.getText();
    if (proxyHost == null) {
        log.error(HTTPTransportConstants.PROXY_HOST_ELEMENT_WITH_EMPTY_VALUE);
        throw new AxisFault(HTTPTransportConstants.PROXY_HOST_ELEMENT_WITH_EMPTY_VALUE);
    }
    return proxyHost;
}

From source file:com.msopentech.odatajclient.testservice.utils.XMLUtilities.java

/**
 * {@inheritDoc }//from w w  w  .  j a  va  2s.com
 */
@Override
protected Set<String> retrieveAllLinkNames(final InputStream is) throws Exception {
    final Set<String> links = new HashSet<String>();

    final XMLEventReader reader = getEventReader(is);

    try {

        int startDepth = 0;

        while (true) {
            final Map.Entry<Integer, XmlElement> linkInfo = getAtomElement(reader, null, LINK, null, startDepth,
                    2, 2, true);

            startDepth = linkInfo.getKey();

            links.add(linkInfo.getValue().getStart().getAttributeByName(new QName("title")).getValue());
        }
    } catch (Exception ignore) {
        // ignore
    } finally {
        reader.close();
        IOUtils.closeQuietly(is);
    }

    return links;
}

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

public void testConsumerDefault() throws Exception {
    JmsComponent component = new JmsComponent();
    JmsConsumerEndpoint endpoint = new JmsConsumerEndpoint();
    endpoint.setService(new QName("jms"));
    endpoint.setEndpoint("endpoint");
    endpoint.setTargetService(new QName("receiver"));
    endpoint.setListenerType("default");
    endpoint.setConnectionFactory(connectionFactory);
    endpoint.setDestinationName("destination");
    component.setEndpoints(new JmsConsumerEndpoint[] { endpoint });
    container.activateComponent(component, "servicemix-jms");

    container.start();//w w  w  .ja  va2s. c  o  m

    jmsTemplate.convertAndSend("destination", "<hello>world</hello>");
    receiver.getMessageList().assertMessagesReceived(1);
    Thread.sleep(500);
}

From source file:backend.Weather.java

private SOAPMessage createSOAPRequest() throws Exception {
    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();
    String serverURI = "http://ws.cdyne.com/";
    SOAPEnvelope envelope = soapPart.getEnvelope();

    SOAPBody soapBody = envelope.getBody();
    SOAPElement soapBodyElem = soapBody.addChildElement("GetCityWeatherByZIP");
    QName attributeName = new QName("xmlns");
    soapBodyElem.addAttribute(attributeName, "http://ws.cdyne.com/WeatherWS/");
    SOAPElement soapBodyElem1 = soapBodyElem.addChildElement("ZIP");
    soapBodyElem1.addTextNode("02215");
    soapMessage.saveChanges();/*  w  ww.  j a  va  2s.  co  m*/
    return soapMessage;

}

From source file:com.telefonica.euro_iaas.sdc.rest.auth.OpenStackAuthenticationProvider.java

/**
 * Authentication fiware./*from   w  w w.j  a  va 2 s .c o  m*/
 * 
 * @param token
 *            the token
 * @param tenantId
 *            the tenantId
 * @return the open stack user
 */
@SuppressWarnings("deprecation")
private PaasManagerUser authenticationFiware(String token, String tenantId) {

    String keystoneURL = systemPropertiesProvider.getProperty(SystemPropertiesProvider.KEYSTONE_URL);

    String adminUser = systemPropertiesProvider.getProperty(SystemPropertiesProvider.KEYSTONE_USER);

    String adminPass = systemPropertiesProvider.getProperty(SystemPropertiesProvider.KEYSTONE_PASS);

    String adminTenant = systemPropertiesProvider.getProperty(SystemPropertiesProvider.KEYSTONE_TENANT);

    String thresholdString = systemPropertiesProvider
            .getProperty(SystemPropertiesProvider.VALIDATION_TIME_THRESHOLD);

    DefaultHttpClient httpClient = new DefaultHttpClient();

    if (oSAuthToken == null) {
        ArrayList<Object> params = new ArrayList();

        Long threshold = Long.parseLong(thresholdString);

        params.add(keystoneURL);
        params.add(adminTenant);
        params.add(adminUser);
        params.add(adminPass);
        params.add(httpClient);
        params.add(threshold);

        oSAuthToken = new OpenStackAuthenticationToken(params);
    }

    String[] credential = oSAuthToken.getCredentials();

    log.debug("Keystone URL : " + keystoneURL);
    log.debug("adminToken : " + credential[0]);

    Client client = Client.create();
    WebResource webResource = client.resource(keystoneURL);
    try {

        // Validate user's token
        AuthenticateResponse responseAuth = webResource.path("tokens").path(token)
                .header("Accept", "application/xml").header("X-Auth-Token", credential[0])
                .get(AuthenticateResponse.class);

        if (!tenantId.equals(responseAuth.getToken().getTenant().getId())) {
            throw new AuthenticationServiceException("Token " + responseAuth.getToken().getTenant().getId()
                    + " not valid for the tenantId provided:" + tenantId);
        }

        Set<GrantedAuthority> authsSet = new HashSet<GrantedAuthority>();

        if (responseAuth.getUser().getRoles() != null) {
            for (Role role : responseAuth.getUser().getRoles().getRole()) {
                authsSet.add(new GrantedAuthorityImpl(role.getName()));
            }
        }

        PaasManagerUser user = new PaasManagerUser(
                responseAuth.getUser().getOtherAttributes().get(new QName("username")), token, authsSet);

        user.setTenantId(tenantId);
        user.setTenantName(responseAuth.getToken().getTenant().getName());
        user.setToken(token);
        return user;

    } catch (UniformInterfaceException e) {
        // this.OSAuthToken.close();
        // this.OSAuthToken = null;

        log.error("response status:" + e.getResponse().getStatus());

        if ((e.getResponse().getStatus() == CODE_401) || (e.getResponse().getStatus() == CODE_403)
                || (e.getResponse().getStatus() == CODE_404)) {
            throw new BadCredentialsException("Token not valid", e);
        }

        throw new AuthenticationServiceException("Token not valid", e);
    } catch (Exception e) {
        // this.OSAuthToken.close();
        // this.OSAuthToken = null;

        throw new AuthenticationServiceException("unknown problem", e);
    }
}

From source file:org.wso2.carbon.connector.EWSIntegrationTest.java

@Test(enabled = true, groups = { "wso2.esb" }, description = "EWS test case", dependsOnMethods = {
        "testCreateItem" })
public void testFindItemAndSendItem() throws Exception {
    DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
    //Send find Item Request
    String createItemProxyUrl = getProxyServiceURL("findItemOperation");
    RestResponse<OMElement> esbSoapResponse = sendXmlRestRequest(createItemProxyUrl, "POST",
            esbRequestHeadersMap, "FindItem.xml");
    OMElement omElement = esbSoapResponse.getBody();
    String findItemStatus = omElement.getFirstElement().getFirstElement()
            .getAttributeValue(new QName("ResponseClass"));
    //Check for success
    Assert.assertEquals(findItemStatus, "Success");
    //Extract Message unique Id and changeKey
    itemId = (String) xPathEvaluate(omElement, "string(//t:ItemId/@Id)", namespaceMap);
    changeKey = (String) xPathEvaluate(omElement, "string(//t:ItemId/@ChangeKey)", namespaceMap);
    Assert.assertNotNull(itemId);/*from   w  w  w . j a  v a  2  s . c  o m*/
    Assert.assertNotNull(changeKey);
    //Send SendItem Request
    String sendItemOperation = getProxyServiceURL("sendItem");
    HttpPost httpPost = new HttpPost(sendItemOperation);
    String payload = "<SendItem><SaveItemToFolder>true</SaveItemToFolder><ItemId><Id>" + itemId
            + "</Id><ChangeKey>" + changeKey + "</ChangeKey></ItemId></SendItem>";
    httpPost.setEntity(new StringEntity(payload, ContentType.TEXT_XML.withCharset(Charset.forName("UTF-8"))));
    HttpResponse response = defaultHttpClient.execute(httpPost);
    OMElement createAttachmentResponse = AXIOMUtil
            .stringToOM(IOUtils.toString(response.getEntity().getContent()));
    String GetAttachmentStatus = createAttachmentResponse.getFirstElement().getFirstElement()
            .getAttributeValue(new QName("ResponseClass"));
    Assert.assertEquals(GetAttachmentStatus, "Success");
}

From source file:com.vangent.hieos.services.xds.registry.transactions.RegistryPatientIdentityFeed.java

/**
 * Processs Patient ID Feeds for HL7 v3 messages
 *
 * @param request/*w w  w .  j  ava2  s.  c om*/
 * @param messageType
 * @return
 */
public OMElement run(OMElement request, MessageType messageType) {
    OMElement result = null;
    Exception ex = null;
    EventActionCode eventActionCode = EventActionCode.CREATE;
    try {
        _adtConn = this.adtGetDatabaseConnection(); // Get ADT connection.
        switch (messageType) {
        case PatientRegistryRecordAdded:
            eventActionCode = EventActionCode.CREATE;
            this.processPatientRegistryRecordAdded(request);
            break;
        case PatientRegistryRecordUpdated:
            eventActionCode = EventActionCode.UPDATE;
            this.processPatientRegistryRecordUpdated(request);
            break;
        case PatientRegistryDuplicatesResolved:
            eventActionCode = EventActionCode.UPDATE;
            // FIXME: Need to fixup how ATNA is handled; ATNA delete not generated for
            // subsumed patient id.
            this.processPatientRegistyDuplicatesResolved(request);
            break;
        case PatientRegistryRecordUnmerged:
            eventActionCode = EventActionCode.UPDATE;
            this.processPatientRegistryRecordUnmerged(request);
            break;
        }
        //this.logResponse(result, !this.errorDetected /* success */);
    } catch (PatientIdentityFeedException feedException) {
        ex = feedException;
    } catch (XdsInternalException internalException) {
        ex = internalException;
    } catch (Exception e) {
        ex = e;
        this.logException(e.getMessage()); // Some lower level exception.
    } finally {
        if (_adtConn != null) {
            _adtConn.closeConnection();
        }
    }

    // Generate the response.
    result = this.generateACK(request, (ex != null) ? ex.getMessage() : null);
    this.logResponse(result, !this.errorDetected /* success */);

    // ATNA log (Start)
    OMElement idNode = this.getFirstChildWithName(request, "id");
    String messageId = (idNode != null) ? idNode.getAttributeValue(new QName("root")) : "UNKNOWN";
    this.auditPatientIdentityFeed(ATNAAuditEvent.IHETransaction.ITI44, this._patientId,
            (messageId != null) ? messageId : "UNKNOWN", eventActionCode,
            this.errorDetected ? ATNAAuditEvent.OutcomeIndicator.MINOR_FAILURE
                    : ATNAAuditEvent.OutcomeIndicator.SUCCESS,
            null /* sourceIdentity */, null /* sourceIP */);
    // ATNA log (Stop)
    return result;
}

From source file:io.hummer.util.ws.WebServiceClient.java

private void setRelevantAttributes(EndpointReference epr) {
    try {/*from w  ww .j  av a2 s .  com*/
        this.eprParamsAndProps.addAll(epr.getAllReferenceParameters());
        this.eprParamsAndProps.addAll(epr.getAllReferenceProperties());
        if (this.eprParamsAndProps.size() > 0) {
            if (logger.isDebugEnabled())
                logger.trace("Reference Params/Props: " + this.eprParamsAndProps);
        }

        this.endpointURL = epr.getAddress();
        String binding = SOAPBinding.SOAP11HTTP_BINDING;
        try {
            this.serviceName = epr.getServiceName().getServiceName();
            this.portName = new QName(epr.getPortName());
            service = Service.create(this.serviceName);
            service.addPort(portName, binding, this.endpointURL);
        } catch (Exception e) {
            if (endpointURL.contains("wsdl") || endpointURL.contains("WSDL")) {
                // assume that the given URL is a WSDL URL
                String wsdlURL = endpointURL;
                javax.wsdl.Service wsdlService = getSingleWSDLService(wsdlURL);
                this.serviceName = wsdlService.getQName();
                javax.wsdl.Port port = getDefaultWSDLPort(wsdlService);
                if (port instanceof SOAP12Binding)
                    binding = SOAPBinding.SOAP12HTTP_BINDING;
                this.portName = new QName(serviceName.getNamespaceURI(), port.getName());
                this.endpointURL = getAddressFromWSDLPort(port);
                service = Service.create(new URL(wsdlURL), this.serviceName);
            }
        }
    } catch (WSDLException e) {
        throw new RuntimeException("Unable to create Web service client from WSDL.", e);
    } catch (ConnectException e) {
        throw new RuntimeException("Unable to create Web service client.", e);
    } catch (Exception e) {
        // swallow
        logger.info("Error initializing Web service client.", e);
    }
}

From source file:org.apache.axis2.transport.http.impl.httpclient4.HTTPProxyConfigurator.java

private static Integer getProxyPort(OMElement proxyConfiguration) throws AxisFault {
    OMElement proxyPortElement = proxyConfiguration
            .getFirstChildWithName(new QName(HTTPTransportConstants.PROXY_PORT_ELEMENT));
    if (proxyPortElement == null) {
        log.error(HTTPTransportConstants.PROXY_PORT_ELEMENT_NOT_FOUND);
        throw new AxisFault(HTTPTransportConstants.PROXY_PORT_ELEMENT_NOT_FOUND);
    }//  w w w . j a v  a2  s.  com
    String proxyPort = proxyPortElement.getText();
    if (proxyPort == null) {
        log.error(HTTPTransportConstants.PROXY_PORT_ELEMENT_WITH_EMPTY_VALUE);
        throw new AxisFault(HTTPTransportConstants.PROXY_PORT_ELEMENT_WITH_EMPTY_VALUE);
    }
    return Integer.parseInt(proxyPort);
}