use of javax.xml.ws.WebServiceException in project cxf by apache.
the class EndpointImpl method getEndpointReference.
public EndpointReference getEndpointReference(Element... referenceParameters) {
if (!isPublished()) {
throw new WebServiceException(new org.apache.cxf.common.i18n.Message("ENDPOINT_NOT_PUBLISHED", LOG).toString());
}
if (getBinding() instanceof HTTPBinding) {
throw new UnsupportedOperationException(new org.apache.cxf.common.i18n.Message("GET_ENDPOINTREFERENCE_UNSUPPORTED_BINDING", LOG).toString());
}
W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
builder.address(address);
builder.serviceName(serviceName);
builder.endpointName(endpointName);
if (referenceParameters != null) {
for (Element referenceParameter : referenceParameters) {
builder.referenceParameter(referenceParameter);
}
}
builder.wsdlDocumentLocation(wsdlLocation);
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try {
Thread.currentThread().setContextClassLoader(EndpointReferenceBuilder.class.getClassLoader());
return builder.build();
} finally {
Thread.currentThread().setContextClassLoader(cl);
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class EndpointImpl method doPublish.
/**
* Performs the publication action by setting up a {@link Server}
* instance based on this endpoint's configuration.
*
* @param addr the optional endpoint address.
*
* @throws IllegalStateException if the endpoint cannot be published/republished
* @throws SecurityException if permission checking is enabled and policy forbids publishing
* @throws WebServiceException if there is an error publishing the endpoint
*
* @see #checkPublishPermission()
* @see #checkPublishable()
* @see #getServer(String)
*/
protected void doPublish(String addr) {
checkPublishPermission();
checkPublishable();
ServerImpl serv = null;
ClassLoaderHolder loader = null;
try {
if (bus != null) {
ClassLoader newLoader = bus.getExtension(ClassLoader.class);
if (newLoader != null) {
loader = ClassLoaderUtils.setThreadContextClassloader(newLoader);
}
}
serv = getServer(addr);
if (addr != null) {
EndpointInfo endpointInfo = serv.getEndpoint().getEndpointInfo();
if (endpointInfo.getAddress() == null || !endpointInfo.getAddress().contains(addr)) {
endpointInfo.setAddress(addr);
}
if (publishedEndpointUrl != null) {
endpointInfo.setProperty(WSDLGetUtils.PUBLISHED_ENDPOINT_URL, publishedEndpointUrl);
}
if (publishedEndpointUrl != null && wsdlLocation != null) {
// early update the publishedEndpointUrl so that endpoints in the same app sharing the same wsdl
// do not require all of them to be queried for wsdl before the wsdl is finally fully updated
Definition def = endpointInfo.getService().getProperty(WSDLServiceBuilder.WSDL_DEFINITION, Definition.class);
if (def == null) {
def = bus.getExtension(WSDLManager.class).getDefinition(wsdlLocation);
}
new WSDLGetUtils().updateWSDLPublishedEndpointAddress(def, endpointInfo);
}
if (null != properties) {
for (Entry<String, Object> entry : properties.entrySet()) {
endpointInfo.setProperty(entry.getKey(), entry.getValue());
}
}
this.address = endpointInfo.getAddress();
}
serv.start();
publishable = false;
} catch (Exception ex) {
try {
stop();
} catch (Exception e) {
// Nothing we can do.
}
throw new WebServiceException(ex);
} finally {
if (loader != null) {
loader.reset();
}
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class JaxWsClientProxy method invoke.
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (client == null) {
throw new IllegalStateException("The client has been closed.");
}
Endpoint endpoint = getClient().getEndpoint();
String address = endpoint.getEndpointInfo().getAddress();
MethodDispatcher dispatcher = (MethodDispatcher) endpoint.getService().get(MethodDispatcher.class.getName());
Object[] params = args;
if (null == params) {
params = new Object[0];
}
try {
if (method.getDeclaringClass().equals(BindingProvider.class) || method.getDeclaringClass().equals(Object.class) || method.getDeclaringClass().equals(Closeable.class) || method.getDeclaringClass().equals(AutoCloseable.class)) {
return method.invoke(this, params);
} else if (method.getDeclaringClass().isInstance(client)) {
return method.invoke(client, params);
}
} catch (InvocationTargetException e) {
throw e.getCause();
}
BindingOperationInfo oi = dispatcher.getBindingOperation(method, endpoint);
if (oi == null) {
Message msg = new Message("NO_BINDING_OPERATION_INFO", LOG, method.getName());
throw new WebServiceException(msg.toString());
}
client.getRequestContext().put(Method.class.getName(), method);
boolean isAsync = isAsync(method);
Object result = null;
try {
if (isAsync) {
result = invokeAsync(method, oi, params);
} else {
result = invokeSync(method, oi, params);
}
} catch (WebServiceException wex) {
throw wex;
} catch (Exception ex) {
for (Class<?> excls : method.getExceptionTypes()) {
if (excls.isInstance(ex)) {
throw ex;
}
}
if (ex instanceof Fault && ex.getCause() instanceof IOException) {
throw new WebServiceException(ex.getMessage(), ex.getCause());
}
if (getBinding() instanceof HTTPBinding) {
HTTPException exception = new HTTPException(HttpURLConnection.HTTP_INTERNAL_ERROR);
exception.initCause(ex);
throw exception;
} else if (getBinding() instanceof SOAPBinding) {
SOAPFault soapFault = createSoapFault((SOAPBinding) getBinding(), ex);
if (soapFault == null) {
throw new WebServiceException(ex);
}
SOAPFaultException exception = new SOAPFaultException(soapFault);
if (ex instanceof Fault && ex.getCause() != null) {
exception.initCause(ex.getCause());
} else {
exception.initCause(ex);
}
throw exception;
} else {
throw new WebServiceException(ex);
}
} finally {
if (addressChanged(address)) {
setupEndpointAddressContext(getClient().getEndpoint());
}
}
Map<String, Object> respContext = client.getResponseContext();
Map<String, Scope> scopes = CastUtils.cast((Map<?, ?>) respContext.get(WrappedMessageContext.SCOPES));
if (scopes != null) {
for (Map.Entry<String, Scope> scope : scopes.entrySet()) {
if (scope.getValue() == Scope.HANDLER) {
respContext.remove(scope.getKey());
}
}
}
return adjustObject(result);
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class ServiceImpl method getJaxwsEndpoint.
private JaxWsClientEndpointImpl getJaxwsEndpoint(QName portName, AbstractServiceFactoryBean sf, WebServiceFeature... features) {
Service service = sf.getService();
EndpointInfo ei = null;
if (portName == null) {
ei = service.getServiceInfos().get(0).getEndpoints().iterator().next();
} else {
ei = service.getEndpointInfo(portName);
if (ei == null) {
PortInfoImpl portInfo = getPortInfo(portName);
if (null != portInfo) {
try {
ei = createEndpointInfo(sf, portName, portInfo);
} catch (BusException e) {
throw new WebServiceException(e);
}
}
}
}
if (ei == null) {
Message msg = new Message("INVALID_PORT", BUNDLE, portName);
throw new WebServiceException(msg.toString());
}
// When the dispatch is created from EPR, the EPR's address will be set in portInfo
PortInfoImpl portInfo = getPortInfo(portName);
if (portInfo != null && portInfo.getAddress() != null && !portInfo.getAddress().equals(ei.getAddress())) {
ei.setAddress(portInfo.getAddress());
}
try {
return new JaxWsClientEndpointImpl(bus, service, ei, this, getAllFeatures(features));
} catch (EndpointException e) {
throw new WebServiceException(e);
}
}
use of javax.xml.ws.WebServiceException in project cxf by apache.
the class ServiceImpl method createDispatch.
public <T> Dispatch<T> createDispatch(QName portName, Class<T> type, JAXBContext context, Mode mode, WebServiceFeature... features) {
// using this instead of JaxWsClientFactoryBean so that handlers are configured
JaxWsProxyFactoryBean clientFac = new JaxWsProxyFactoryBean();
// Initialize Features.
configureObject(portName.toString() + ".jaxws-client.proxyFactory", clientFac);
AbstractServiceFactoryBean sf = null;
try {
DataBinding db;
if (context != null) {
db = new JAXBDataBinding(context);
} else {
db = new SourceDataBinding(type);
}
sf = createDispatchService(db);
} catch (ServiceConstructionException e) {
throw new WebServiceException(e);
}
JaxWsEndpointImpl endpoint = getJaxwsEndpoint(portName, sf, features);
// if the client factory has properties specified, then set those into the endpoint
if (clientFac.getProperties() != null) {
endpoint.putAll(clientFac.getProperties());
}
// add all the client factory features onto the endpoint feature list
endpoint.getFeatures().addAll(clientFac.getFeatures());
// if the client factory has a bus specified (other than the thread default),
// then use that for the client. Otherwise use the bus from this service.
Bus clientBus = getBus();
if (clientFac.getBus() != BusFactory.getThreadDefaultBus(false) && clientFac.getBus() != null) {
clientBus = clientFac.getBus();
}
@SuppressWarnings("rawtypes") List<Handler> hc = clientFac.getHandlers();
// CXF-3956
hc.addAll(handlerResolver.getHandlerChain(portInfos.get(portName)));
endpoint.getJaxwsBinding().setHandlerChain(hc);
// create the client object, then initialize the endpoint features against it
Client client = new ClientImpl(clientBus, endpoint, clientFac.getConduitSelector());
for (Feature af : endpoint.getFeatures()) {
af.initialize(client, clientBus);
}
// CXF-2822
initIntercepors(client, clientFac);
if (executor != null) {
client.getEndpoint().setExecutor(executor);
}
// then try to get it from the wsdl
if (!StringUtils.isEmpty(clientFac.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(clientFac.getAddress());
} else {
// Set the the EPR's address in EndpointInfo
PortInfoImpl portInfo = portInfos.get(portName);
if (portInfo != null && !StringUtils.isEmpty(portInfo.getAddress())) {
client.getEndpoint().getEndpointInfo().setAddress(portInfo.getAddress());
}
}
Dispatch<T> disp = new DispatchImpl<T>(client, mode, context, type);
configureObject(disp);
return disp;
}
Aggregations