use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.
the class EPRWriteNReadTest method verifyEPR.
private static void verifyEPR(WSEndpointReference wsepr) throws Exception {
ByteArrayBuffer bytebuffer = new ByteArrayBuffer();
XMLStreamWriter w = XMLOutputFactory.newInstance().createXMLStreamWriter(bytebuffer);
System.out.println("----------------------------------------------------------------------");
w.writeStartDocument();
wsepr.writeTo("EndpointReference", w);
w.writeEndDocument();
System.out.println(bytebuffer.toString());
// verify the validity of infoset by reading it as EPR back again
EndpointReference epr = W3CEndpointReference.readFrom(new StreamSource(bytebuffer.newInputStream()));
// Verify it good old way
XMLStreamReader xsr = XMLInputFactory.newInstance().createXMLStreamReader(new StreamSource(bytebuffer.newInputStream()));
QName q = new QName("http://schemas.xmlsoap.org/ws/2006/02/addressingidentity", "Identity");
while (xsr.hasNext()) {
xsr.next();
if (xsr.getEventType() == XMLStreamConstants.START_ELEMENT && xsr.getLocalName().equals("Identity")) {
assertEquals(q.getNamespaceURI(), xsr.getNamespaceURI());
}
}
}
use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.
the class EPRWriteNReadTest method test3.
public void test3() throws Exception {
URL fileurl = getResource("hello_literal_identity3.wsdl");
WSDLModel doc = RuntimeWSDLParser.parse(fileurl, new StreamSource(fileurl.toExternalForm()), getResolver(), true, null);
WSDLService service = doc.getService(new QName("urn:test", "Hello2"));
WSDLPort port = service.getFirstPort();
WSEndpointReference wsepr = port.getExtension(WSEndpointReference.class);
verifyEPR(wsepr);
}
use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.
the class EPRinWsdlPortTest method test1.
public void test1() throws Exception {
URL fileurl = getResource("hello_literal_identity.wsdl");
WSDLModel doc = RuntimeWSDLParser.parse(fileurl, new StreamSource(fileurl.toExternalForm()), getResolver(), true, null);
WSDLService service = doc.getService(new QName("urn:test", "Hello"));
WSDLPort port = service.getFirstPort();
WSEndpointReference wsepr = port.getExtension(WSEndpointReference.class);
QName q = new QName("http://schemas.xmlsoap.org/ws/2006/02/addressingidentity", "Identity");
WSEndpointReference.EPRExtension eprExtn = wsepr.getEPRExtension(q);
XMLStreamReader xsr = eprExtn.readAsXMLStreamReader();
if (xsr.getEventType() == XMLStreamConstants.START_DOCUMENT)
xsr.next();
assertEquals(q.getNamespaceURI(), xsr.getNamespaceURI());
assertEquals(q.getLocalPart(), xsr.getLocalName());
}
use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.
the class ProviderImpl method createW3CEndpointReference.
public W3CEndpointReference createW3CEndpointReference(String address, QName interfaceName, QName serviceName, QName portName, List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters, List<Element> elements, Map<QName, String> attributes) {
Container container = ContainerResolver.getInstance().getContainer();
if (address == null) {
if (serviceName == null || portName == null) {
throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS_SERVICE_ENDPOINT());
} else {
// check if it is run in a Java EE Container and if so, get address using serviceName and portName
Module module = container.getSPI(Module.class);
if (module != null) {
List<BoundEndpoint> beList = module.getBoundEndpoints();
for (BoundEndpoint be : beList) {
WSEndpoint wse = be.getEndpoint();
if (wse.getServiceName().equals(serviceName) && wse.getPortName().equals(portName)) {
try {
address = be.getAddress().toString();
} catch (WebServiceException e) {
// May be the container does n't support this
// just ignore the exception
}
break;
}
}
}
// address is still null? may be its not run in a JavaEE Container
if (address == null)
throw new IllegalStateException(ProviderApiMessages.NULL_ADDRESS());
}
}
if ((serviceName == null) && (portName != null)) {
throw new IllegalStateException(ProviderApiMessages.NULL_SERVICE());
}
// Validate Service and Port in WSDL
String wsdlTargetNamespace = null;
if (wsdlDocumentLocation != null) {
try {
EntityResolver er = XmlUtil.createDefaultCatalogResolver();
URL wsdlLoc = new URL(wsdlDocumentLocation);
WSDLModel wsdlDoc = RuntimeWSDLParser.parse(wsdlLoc, new StreamSource(wsdlLoc.toExternalForm()), er, true, container, ServiceFinder.find(WSDLParserExtension.class).toArray());
if (serviceName != null) {
WSDLService wsdlService = wsdlDoc.getService(serviceName);
if (wsdlService == null)
throw new IllegalStateException(ProviderApiMessages.NOTFOUND_SERVICE_IN_WSDL(serviceName, wsdlDocumentLocation));
if (portName != null) {
WSDLPort wsdlPort = wsdlService.get(portName);
if (wsdlPort == null)
throw new IllegalStateException(ProviderApiMessages.NOTFOUND_PORT_IN_WSDL(portName, serviceName, wsdlDocumentLocation));
}
wsdlTargetNamespace = serviceName.getNamespaceURI();
} else {
QName firstService = wsdlDoc.getFirstServiceName();
wsdlTargetNamespace = firstService.getNamespaceURI();
}
} catch (Exception e) {
throw new IllegalStateException(ProviderApiMessages.ERROR_WSDL(wsdlDocumentLocation), e);
}
}
// wcf3.0/3.5 rejected empty metadata element.
if (metadata != null && metadata.size() == 0) {
metadata = null;
}
return new WSEndpointReference(AddressingVersion.fromSpecClass(W3CEndpointReference.class), address, serviceName, portName, interfaceName, metadata, wsdlDocumentLocation, wsdlTargetNamespace, referenceParameters, elements, attributes).toSpec(W3CEndpointReference.class);
}
use of com.sun.xml.ws.api.addressing.WSEndpointReference in project metro-jax-ws by eclipse-ee4j.
the class WSEndpointImpl method getEndpointReference.
@Override
public <T extends EndpointReference> T getEndpointReference(Class<T> clazz, String address, String wsdlAddress, List<Element> metadata, List<Element> referenceParameters) {
QName portType = null;
if (port != null) {
portType = port.getBinding().getPortTypeName();
}
AddressingVersion av = AddressingVersion.fromSpecClass(clazz);
return new WSEndpointReference(av, address, serviceName, portName, portType, metadata, wsdlAddress, referenceParameters, endpointReferenceExtensions.values(), null).toSpec(clazz);
}
Aggregations