Search in sources :

Example 91 with WebServiceException

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);
    }
}
Also used : W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.message.Message) Element(org.w3c.dom.Element) W3CEndpointReferenceBuilder(javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder) HTTPBinding(javax.xml.ws.http.HTTPBinding)

Example 92 with WebServiceException

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();
        }
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) ServerImpl(org.apache.cxf.endpoint.ServerImpl) WebServiceException(javax.xml.ws.WebServiceException) Definition(javax.wsdl.Definition) WSDLGetUtils(org.apache.cxf.frontend.WSDLGetUtils) ClassLoaderHolder(org.apache.cxf.common.classloader.ClassLoaderUtils.ClassLoaderHolder) WebServiceException(javax.xml.ws.WebServiceException)

Example 93 with WebServiceException

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);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) HTTPException(javax.xml.ws.http.HTTPException) Message(org.apache.cxf.common.i18n.Message) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SoapFault(org.apache.cxf.binding.soap.SoapFault) Endpoint(org.apache.cxf.endpoint.Endpoint) MethodDispatcher(org.apache.cxf.service.invoker.MethodDispatcher) HTTPBinding(javax.xml.ws.http.HTTPBinding) WebServiceException(javax.xml.ws.WebServiceException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) BindingProvider(javax.xml.ws.BindingProvider) Method(java.lang.reflect.Method) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HTTPException(javax.xml.ws.http.HTTPException) SOAPException(javax.xml.soap.SOAPException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) WebServiceException(javax.xml.ws.WebServiceException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Scope(javax.xml.ws.handler.MessageContext.Scope) SOAPFault(javax.xml.soap.SOAPFault) Map(java.util.Map)

Example 94 with WebServiceException

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);
    }
}
Also used : EndpointInfo(org.apache.cxf.service.model.EndpointInfo) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) JaxWsClientEndpointImpl(org.apache.cxf.jaxws.support.JaxWsClientEndpointImpl) EndpointException(org.apache.cxf.endpoint.EndpointException) Service(org.apache.cxf.service.Service) WebService(javax.jws.WebService) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) BusException(org.apache.cxf.BusException)

Example 95 with WebServiceException

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;
}
Also used : AbstractServiceFactoryBean(org.apache.cxf.service.factory.AbstractServiceFactoryBean) Bus(org.apache.cxf.Bus) WebServiceException(javax.xml.ws.WebServiceException) Handler(javax.xml.ws.handler.Handler) ClientImpl(org.apache.cxf.endpoint.ClientImpl) ServiceConstructionException(org.apache.cxf.service.factory.ServiceConstructionException) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) Feature(org.apache.cxf.feature.Feature) WebServiceFeature(javax.xml.ws.WebServiceFeature) JaxWsEndpointImpl(org.apache.cxf.jaxws.support.JaxWsEndpointImpl) DataBinding(org.apache.cxf.databinding.DataBinding) SourceDataBinding(org.apache.cxf.databinding.source.SourceDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) JAXBDataBinding(org.apache.cxf.jaxb.JAXBDataBinding) PortInfoImpl(org.apache.cxf.jaxws.handler.PortInfoImpl) Client(org.apache.cxf.endpoint.Client)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)120 Test (org.junit.Test)50 URL (java.net.URL)37 BindingProvider (javax.xml.ws.BindingProvider)25 Service (javax.xml.ws.Service)22 QName (javax.xml.namespace.QName)14 IOException (java.io.IOException)10 Message (org.apache.cxf.common.i18n.Message)9 JAXBException (javax.xml.bind.JAXBException)8 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 Bus (org.apache.cxf.Bus)7 Packet (com.sun.xml.ws.api.message.Packet)6 AuthStatus (javax.security.auth.message.AuthStatus)6 SOAPException (javax.xml.soap.SOAPException)6 SOAPMessage (javax.xml.soap.SOAPMessage)6 ArrayList (java.util.ArrayList)5 WebService (javax.jws.WebService)5 Subject (javax.security.auth.Subject)5 HttpSession (javax.servlet.http.HttpSession)5 Handler (javax.xml.ws.handler.Handler)5