public EndpointReference getEndpointReference(Element... referenceParameters) {
WrappedMessageContext ctx = (WrappedMessageContext)getMessageContext();
org.apache.cxf.message.Message msg = ctx.getWrappedMessage();
Endpoint ep = msg.getExchange().get(Endpoint.class);
W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
builder.address(ep.getEndpointInfo().getAddress());
builder.serviceName(ep.getService().getName());
builder.endpointName(ep.getEndpointInfo().getName());
URI wsdlDescription = ep.getEndpointInfo().getProperty("URI", URI.class);
if (wsdlDescription == null) {
String address = ep.getEndpointInfo().getAddress();
try {
wsdlDescription = new URI(address + "?wsdl");
} catch (URISyntaxException e) {
// do nothing
}
ep.getEndpointInfo().setProperty("URI", wsdlDescription);
}
builder.wsdlDocumentLocation(wsdlDescription.toString());
/*
if (ep.getEndpointInfo().getService().getDescription() != null) {
builder.wsdlDocumentLocation(ep.getEndpointInfo().getService()
.getDescription().getBaseURI());
}
*/
if (referenceParameters != null) {
for (Element referenceParameter : referenceParameters) {
builder.referenceParameter(referenceParameter);
}
}
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(EndpointReferenceBuilder.class.getClassLoader());
return builder.build();
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}