use of javax.xml.ws.wsaddressing.W3CEndpointReference in project cxf by apache.
the class MultiplexHttpAddressClientServerTest method testWithGetPortExtensionHttp.
@Test
public void testWithGetPortExtensionHttp() throws Exception {
NumberFactoryService service = new NumberFactoryService();
NumberFactory factory = service.getNumberFactoryPort();
updateAddressPort(factory, PORT);
NumberService numService = new NumberService();
ServiceImpl serviceImpl = ServiceDelegateAccessor.get(numService);
W3CEndpointReference numberTwoRef = factory.create("20");
assertNotNull("reference", numberTwoRef);
Number num = serviceImpl.getPort(numberTwoRef, Number.class);
assertTrue("20 is even", num.isEven().isEven());
W3CEndpointReference numberTwentyThreeRef = factory.create("23");
num = serviceImpl.getPort(numberTwentyThreeRef, Number.class);
assertTrue("23 is not even", !num.isEven().isEven());
}
use of javax.xml.ws.wsaddressing.W3CEndpointReference in project cxf by apache.
the class CallbackClientServerTest method testCallback.
@Test
public void testCallback() throws Exception {
Object implementor = new CallbackImpl();
String address = "http://localhost:" + CB_PORT + "/CallbackContext/NestedCallbackPort";
Endpoint.publish(address, implementor);
URL wsdlURL = getClass().getResource("/wsdl/nested_callback.wsdl");
SOAPService ss = new SOAPService(wsdlURL, SERVICE_NAME);
ServerPortType port = ss.getPort(PORT_NAME, ServerPortType.class);
updateAddressPort(port, PORT);
EndpointReferenceType ref = null;
try {
ref = EndpointReferenceUtils.getEndpointReference(wsdlURL, SERVICE_NAME_CALLBACK, PORT_NAME_CALLBACK.getLocalPart());
EndpointReferenceUtils.setInterfaceName(ref, PORT_TYPE_CALLBACK);
EndpointReferenceUtils.setAddress(ref, address);
} catch (Exception e) {
e.printStackTrace();
}
NestedCallback callbackObject = new NestedCallback();
Source source = EndpointReferenceUtils.convertToXML(ref);
W3CEndpointReference w3cEpr = new W3CEndpointReference(source);
callbackObject.setCallback(w3cEpr);
String resp = port.registerCallback(callbackObject);
assertEquals("registerCallback called", resp);
}
use of javax.xml.ws.wsaddressing.W3CEndpointReference in project cxf by apache.
the class ServerImpl method registerCallback.
public String registerCallback(NestedCallback callbackObject) {
try {
W3CEndpointReference w3cEpr = callbackObject.getCallback();
EndpointReferenceType callback = ProviderImpl.convertToInternal(w3cEpr);
WSDLManager manager = new WSDLManagerImpl();
QName interfaceName = EndpointReferenceUtils.getInterfaceName(callback, bus);
String wsdlLocation = EndpointReferenceUtils.getWSDLLocation(callback);
QName serviceName = EndpointReferenceUtils.getServiceName(callback, bus);
String address = EndpointReferenceUtils.getAddress(callback);
String portString = EndpointReferenceUtils.getPortName(callback);
QName portName = new QName(serviceName.getNamespaceURI(), portString);
StringBuilder seiName = new StringBuilder();
seiName.append(JAXBUtils.namespaceURIToPackage(interfaceName.getNamespaceURI()));
seiName.append(".");
seiName.append(JAXBUtils.nameToIdentifier(interfaceName.getLocalPart(), JAXBUtils.IdentifierType.INTERFACE));
Class<?> sei = null;
try {
sei = Class.forName(seiName.toString(), true, manager.getClass().getClassLoader());
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
}
URL wsdlURL = new URL(wsdlLocation);
Service service = Service.create(wsdlURL, serviceName);
CallbackPortType port = (CallbackPortType) service.getPort(portName, sei);
((BindingProvider) port).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
port.serverSayHi("Sean");
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
return "registerCallback called";
}
use of javax.xml.ws.wsaddressing.W3CEndpointReference in project cxf by apache.
the class ProviderImpl method convertToInternal.
/**
* Convert from EndpointReference to CXF internal 2005/08 EndpointReferenceType
*
* @param external the javax.xml.ws.EndpointReference
* @return CXF internal 2005/08 EndpointReferenceType
*/
public static EndpointReferenceType convertToInternal(EndpointReference external) {
if (external instanceof W3CEndpointReference) {
Unmarshaller um = null;
try {
DocumentFragment frag = DOMUtils.getEmptyDocument().createDocumentFragment();
DOMResult result = new DOMResult(frag);
external.writeTo(result);
W3CDOMStreamReader reader = new W3CDOMStreamReader(frag);
// CXF internal 2005/08 EndpointReferenceType should be
// compatible with W3CEndpointReference
// jaxContext = ContextUtils.getJAXBContext();
JAXBContext context = JAXBContext.newInstance(new Class[] { org.apache.cxf.ws.addressing.ObjectFactory.class });
um = context.createUnmarshaller();
return um.unmarshal(reader, EndpointReferenceType.class).getValue();
} catch (JAXBException e) {
throw new IllegalArgumentException("Could not unmarshal EndpointReference", e);
} finally {
JAXBUtils.closeUnmarshaller(um);
}
}
return null;
}
use of javax.xml.ws.wsaddressing.W3CEndpointReference in project cxf by apache.
the class ProviderImpl method createW3CEndpointReference.
// CHECKSTYLE:OFF - spec requires a bunch of params
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) {
// CHECKSTYLE:ON
if (serviceName != null && portName != null && wsdlDocumentLocation != null && interfaceName == null) {
Bus bus = BusFactory.getThreadDefaultBus();
WSDLManager wsdlManager = bus.getExtension(WSDLManager.class);
try {
Definition def = wsdlManager.getDefinition(wsdlDocumentLocation);
interfaceName = def.getService(serviceName).getPort(portName.getLocalPart()).getBinding().getPortType().getQName();
} catch (Exception e) {
// do nothing
}
}
if (serviceName == null && portName == null && address == null) {
throw new IllegalStateException("Address in an EPR cannot be null, " + " when serviceName or portName is null");
}
try {
final W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.setPrefix(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.NS_WSA);
writer.writeStartElement(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_ERF_NAME, JAXWSAConstants.NS_WSA);
writer.writeNamespace(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.NS_WSA);
writer.writeStartElement(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_ADDRESS_NAME, JAXWSAConstants.NS_WSA);
address = address == null ? "" : address;
writer.writeCharacters(address);
writer.writeEndElement();
if (referenceParameters != null) {
writer.writeStartElement(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_REFERENCEPARAMETERS_NAME, JAXWSAConstants.NS_WSA);
for (Element ele : referenceParameters) {
StaxUtils.writeElement(ele, writer, true);
}
writer.writeEndElement();
}
if (wsdlDocumentLocation != null || interfaceName != null || serviceName != null || (metadata != null && !metadata.isEmpty())) {
writer.writeStartElement(JAXWSAConstants.WSA_PREFIX, JAXWSAConstants.WSA_METADATA_NAME, JAXWSAConstants.NS_WSA);
writer.writeNamespace(JAXWSAConstants.WSAW_PREFIX, JAXWSAConstants.NS_WSAW);
writer.writeNamespace(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.NS_WSAM);
if (wsdlDocumentLocation != null) {
boolean includeLocationOnly = false;
org.apache.cxf.message.Message message = PhaseInterceptorChain.getCurrentMessage();
if (message != null) {
includeLocationOnly = MessageUtils.getContextualBoolean(message, "org.apache.cxf.wsa.metadata.wsdlLocationOnly", false);
}
String attrubuteValue = serviceName != null && !includeLocationOnly ? serviceName.getNamespaceURI() + " " + wsdlDocumentLocation : wsdlDocumentLocation;
writer.writeNamespace(JAXWSAConstants.WSDLI_PFX, JAXWSAConstants.NS_WSDLI);
writer.writeAttribute(JAXWSAConstants.WSDLI_PFX, JAXWSAConstants.NS_WSDLI, JAXWSAConstants.WSDLI_WSDLLOCATION, attrubuteValue);
}
if (interfaceName != null) {
writer.writeStartElement(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.WSAM_INTERFACE_NAME, JAXWSAConstants.NS_WSAM);
String portTypePrefix = interfaceName.getPrefix();
if (portTypePrefix == null || portTypePrefix.equals("")) {
portTypePrefix = "ns1";
}
writer.writeNamespace(portTypePrefix, interfaceName.getNamespaceURI());
writer.writeCharacters(portTypePrefix + ":" + interfaceName.getLocalPart());
writer.writeEndElement();
}
String serviceNamePrefix = null;
if (serviceName != null) {
serviceNamePrefix = (serviceName.getPrefix() == null || serviceName.getPrefix().length() == 0) ? "ns2" : serviceName.getPrefix();
writer.writeStartElement(JAXWSAConstants.WSAM_PREFIX, JAXWSAConstants.WSAM_SERVICENAME_NAME, JAXWSAConstants.NS_WSAM);
if (portName != null) {
writer.writeAttribute(JAXWSAConstants.WSAM_ENDPOINT_NAME, portName.getLocalPart());
}
writer.writeNamespace(serviceNamePrefix, serviceName.getNamespaceURI());
writer.writeCharacters(serviceNamePrefix + ":" + serviceName.getLocalPart());
writer.writeEndElement();
}
if (wsdlDocumentLocation != null) {
writer.writeStartElement(WSDLConstants.WSDL_PREFIX, WSDLConstants.QNAME_DEFINITIONS.getLocalPart(), WSDLConstants.NS_WSDL11);
writer.writeNamespace(WSDLConstants.WSDL_PREFIX, WSDLConstants.NS_WSDL11);
writer.writeStartElement(WSDLConstants.WSDL_PREFIX, WSDLConstants.QNAME_IMPORT.getLocalPart(), WSDLConstants.QNAME_IMPORT.getNamespaceURI());
if (serviceName != null) {
writer.writeAttribute(WSDLConstants.ATTR_NAMESPACE, serviceName.getNamespaceURI());
}
writer.writeAttribute(WSDLConstants.ATTR_LOCATION, wsdlDocumentLocation);
writer.writeEndElement();
writer.writeEndElement();
}
if (metadata != null) {
for (Element e : metadata) {
StaxUtils.writeElement(e, writer, true);
}
}
writer.writeEndElement();
}
if (elements != null) {
for (Element e : elements) {
StaxUtils.writeElement(e, writer, true);
}
}
writer.writeEndElement();
writer.flush();
try {
return AccessController.doPrivileged(new PrivilegedExceptionAction<W3CEndpointReference>() {
public W3CEndpointReference run() throws Exception {
Unmarshaller unmarshaller = getJAXBContext().createUnmarshaller();
try {
return (W3CEndpointReference) unmarshaller.unmarshal(writer.getDocument());
} finally {
JAXBUtils.closeUnmarshaller(unmarshaller);
}
}
});
} catch (PrivilegedActionException pae) {
Exception e = pae.getException();
if (e instanceof JAXBException) {
throw (JAXBException) e;
}
throw new SecurityException(e);
}
} catch (Exception e) {
throw new WebServiceException(new Message("ERROR_UNMARSHAL_ENDPOINTREFERENCE", LOG).toString(), e);
}
}
Aggregations