Java Code Examples for javax.xml.ws.wsaddressing.W3CEndpointReference#writeTo()

The following examples show how to use javax.xml.ws.wsaddressing.W3CEndpointReference#writeTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProviderImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testCreateW3CEpr() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org", "ServiceName");
    QName portName = new QName("http://cxf.apache.org", "PortName");
    ProviderImpl impl = new ProviderImpl();
    W3CEndpointReference w3Epr = impl.createW3CEndpointReference("http://myaddress", serviceName,
                                                                  portName, null, "wsdlLoc",
                                                                  null);

    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult result = new StreamResult(sw);
    w3Epr.writeTo(result);
    String expected = "<wsdl:definitions";
    assertTrue("Embeded wsdl element is not generated", sw.toString().indexOf(expected) > -1);
    assertTrue("wsdlLocation attribute has the wrong value",
               sw.toString().contains(":wsdlLocation=\"http://cxf.apache.org wsdlLoc\""));
}
 
Example 2
Source File: ProviderImplTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testCreateW3CEprMetadataMetadataOnly() throws Exception {
    ProviderImpl impl = new ProviderImpl();
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Element element = builder.newDocument().createElement("customMetadata");
    List<Element> metadata = new ArrayList<>();
    metadata.add(element);
    W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
                     "http://myaddress", null, null,
                     metadata, null, null);

    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult result = new StreamResult(sw);
    w3Epr.writeTo(result);
    assertTrue("Address is expected", sw.toString().contains("Address"));
    assertTrue("Metadata element expected", sw.toString().contains("Metadata"));
    assertTrue("Custom Metadata element expected", sw.toString().contains("customMetadata"));
    assertFalse("Interface element unexpected", sw.toString().contains("Interface"));
    assertFalse("ServiceName unexpected", sw.toString().contains("ServiceName"));
}
 
Example 3
Source File: WSNHelper.java    From cxf with Apache License 2.0 5 votes vote down vote up
public String getWSAAddress(W3CEndpointReference ref) {
    Element element = DOMUtils.getEmptyDocument().createElement("elem");
    ref.writeTo(new DOMResult(element));
    NodeList nl = element.getElementsByTagNameNS("http://www.w3.org/2005/08/addressing", "Address");
    if (nl != null && nl.getLength() > 0) {
        Element e = (Element) nl.item(0);
        return DOMUtils.getContent(e).trim();
    }
    return null;
}
 
Example 4
Source File: ProviderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testCreateW3CEprNoMetadata() throws Exception {
    ProviderImpl impl = new ProviderImpl();
    W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
                     "http://myaddress", null, null, null, null, null, null, null, null);

    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult result = new StreamResult(sw);
    w3Epr.writeTo(result);
    assertTrue("Address is expected", sw.toString().contains("Address"));
    assertFalse("empty Metadata element should be dropped", sw.toString().contains("Metadata"));
}
 
Example 5
Source File: ProviderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testCreateW3CEprNoMetadataEmptyCustomMetadata() throws Exception {
    ProviderImpl impl = new ProviderImpl();
    W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
        "http://myaddress", null, null, new ArrayList<>(), null, null);

    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult result = new StreamResult(sw);
    w3Epr.writeTo(result);
    assertTrue("Address is expected", sw.toString().contains("Address"));
    assertFalse("empty Metadata element should be dropped", sw.toString().contains("Metadata"));
}
 
Example 6
Source File: ProviderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testCreateW3CEprMetadataInterfaceNameOnly() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org", "IntfName");
    ProviderImpl impl = new ProviderImpl();
    W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
                     "http://myaddress", serviceName, null, null, null, null, null, null, null);

    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult result = new StreamResult(sw);
    w3Epr.writeTo(result);
    assertTrue("Address is expected", sw.toString().contains("Address"));
    assertTrue("Metadata element expected", sw.toString().contains("Metadata"));
    assertTrue("Interface element expected", sw.toString().contains("Interface"));
    assertFalse("ServiceName is unexpected", sw.toString().contains("ServiceName"));
}
 
Example 7
Source File: ProviderImplTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@org.junit.Test
public void testCreateW3CEprMetadataServiceNameOnly() throws Exception {
    QName serviceName = new QName("http://cxf.apache.org", "ServiceName");
    ProviderImpl impl = new ProviderImpl();
    W3CEndpointReference w3Epr = impl.createW3CEndpointReference(
                     "http://myaddress", null, serviceName, null, null, null, null, null, null);

    java.io.StringWriter sw = new java.io.StringWriter();
    StreamResult result = new StreamResult(sw);
    w3Epr.writeTo(result);
    assertTrue("Address is expected", sw.toString().contains("Address"));
    assertTrue("Metadata element expected", sw.toString().contains("Metadata"));
    assertFalse("Interface element unexpected", sw.toString().contains("Interface"));
    assertTrue("ServiceName is expected", sw.toString().contains("ServiceName"));
}