Search in sources :

Example 86 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class ProviderImpl method createEndpoint.

@Override
public Endpoint createEndpoint(String bindingId, Object implementor) {
    Endpoint ep = null;
    if (EndpointUtils.isValidImplementor(implementor)) {
        Bus bus = BusFactory.getThreadDefaultBus();
        ep = createEndpointImpl(bus, bindingId, implementor);
        return ep;
    }
    throw new WebServiceException(new Message("INVALID_IMPLEMENTOR_EXC", LOG).toString());
}
Also used : Bus(org.apache.cxf.Bus) Endpoint(javax.xml.ws.Endpoint) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message)

Example 87 with WebServiceException

use of javax.xml.ws.WebServiceException 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);
    }
}
Also used : Bus(org.apache.cxf.Bus) W3CDOMStreamWriter(org.apache.cxf.staxutils.W3CDOMStreamWriter) WebServiceException(javax.xml.ws.WebServiceException) Message(org.apache.cxf.common.i18n.Message) PrivilegedActionException(java.security.PrivilegedActionException) Element(org.w3c.dom.Element) JAXBException(javax.xml.bind.JAXBException) Definition(javax.wsdl.Definition) XMLStreamException(javax.xml.stream.XMLStreamException) PrivilegedActionException(java.security.PrivilegedActionException) JAXBException(javax.xml.bind.JAXBException) WebServiceException(javax.xml.ws.WebServiceException) W3CEndpointReference(javax.xml.ws.wsaddressing.W3CEndpointReference) WSDLManager(org.apache.cxf.wsdl.WSDLManager) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 88 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class JaxWsImplementorInfo method initialize.

private void initialize() {
    Class<?> cls = implementorClass;
    while (cls != null) {
        WebService annotation = cls.getAnnotation(WebService.class);
        if (annotation != null) {
            wsAnnotations.add(annotation);
            if (cls.isInterface()) {
                cls = null;
            }
        } else {
            // check if there are annotations has the same name with WebServices
            if (ifAnnotationLoadedByOtherClassLoader(cls, WebService.class)) {
                LOG.log(Level.WARNING, "WEBSERVICE_ANNOTATIONS_IS_LOADED_BY_OTHER_CLASSLOADER", WebService.class.getName());
            }
        }
        if (cls != null) {
            cls = cls.getSuperclass();
        }
    }
    String sei = getImplementorClassName();
    boolean seiFromWsAnnotation = true;
    if (StringUtils.isEmpty(sei)) {
        seiFromWsAnnotation = false;
        sei = getWSInterfaceName(implementorClass);
    }
    if (!StringUtils.isEmpty(sei)) {
        try {
            seiClass = ClassLoaderUtils.loadClass(sei, implementorClass);
        } catch (ClassNotFoundException ex) {
            throw new WebServiceException(BUNDLE.getString("SEI_LOAD_FAILURE_MSG"), ex);
        }
        WebService seiAnnotation = seiClass.getAnnotation(WebService.class);
        if (null == seiAnnotation) {
            throw new WebServiceException(BUNDLE.getString("SEI_WITHOUT_WEBSERVICE_ANNOTATION_EXC"));
        }
        if (seiFromWsAnnotation && (!StringUtils.isEmpty(seiAnnotation.portName()) || !StringUtils.isEmpty(seiAnnotation.serviceName()) || !StringUtils.isEmpty(seiAnnotation.endpointInterface()))) {
            String expString = BUNDLE.getString("ILLEGAL_ATTRIBUTE_IN_SEI_ANNOTATION_EXC");
            throw new WebServiceException(expString);
        }
        wsAnnotations.add(seiAnnotation);
        for (int x = implementorClass.getInterfaces().length - 1; x >= 0; x--) {
            if (seiClass.equals(implementorClass.getInterfaces()[x])) {
                Type type = implementorClass.getGenericInterfaces()[x];
                if (type instanceof ParameterizedType) {
                    seiType = (ParameterizedType) type;
                }
            }
        }
    }
    wsProviderAnnotation = getWebServiceProviderAnnotation(implementorClass);
}
Also used : ParameterizedType(java.lang.reflect.ParameterizedType) BindingType(javax.xml.ws.BindingType) ParameterizedType(java.lang.reflect.ParameterizedType) Type(java.lang.reflect.Type) WebServiceException(javax.xml.ws.WebServiceException) WebService(javax.jws.WebService)

Example 89 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class ServiceDelegateAccessor method get.

/**
 * Get the delegate reference from the Service private field. This method
 * uses Field.setAccessible() which, in the presence of a SecurityManager,
 * requires the suppressAccessChecks permission
 *
 * @param service the taraget service
 * @return the implementation delegate
 * @throws WebServiceException if access to the field fails for any reason
 */
public static ServiceImpl get(Service service) {
    ServiceImpl delegate = null;
    try {
        Field delegateField = Service.class.getDeclaredField(DELEGATE_FIELD_NAME);
        ReflectionUtil.setAccessible(delegateField);
        delegate = (ServiceImpl) delegateField.get(service);
    } catch (Exception e) {
        try {
            Field delegateField = Service.class.getDeclaredField(DELEGATE_FIELD_NAME2);
            ReflectionUtil.setAccessible(delegateField);
            delegate = (ServiceImpl) delegateField.get(service);
        } catch (Exception e2) {
            WebServiceException wse = new WebServiceException("Failed to access Field named " + DELEGATE_FIELD_NAME + " of Service instance " + service, e);
            LOG.log(Level.SEVERE, e.getMessage(), e);
            throw wse;
        }
    }
    return delegate;
}
Also used : Field(java.lang.reflect.Field) WebServiceException(javax.xml.ws.WebServiceException) ServiceImpl(org.apache.cxf.jaxws.ServiceImpl) Service(javax.xml.ws.Service) WebServiceException(javax.xml.ws.WebServiceException)

Example 90 with WebServiceException

use of javax.xml.ws.WebServiceException in project cxf by apache.

the class DispatchImpl method mapException.

private RuntimeException mapException(Exception 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);
        return exception;
    } else if (getBinding() instanceof SOAPBinding) {
        SOAPFault soapFault = null;
        try {
            soapFault = JaxWsClientProxy.createSoapFault((SOAPBinding) getBinding(), ex);
        } catch (SOAPException e) {
        // ignore
        }
        if (soapFault == null) {
            return new WebServiceException(ex);
        }
        SOAPFaultException exception = new SOAPFaultException(soapFault);
        exception.initCause(ex);
        return exception;
    }
    return new WebServiceException(ex);
}
Also used : HTTPException(javax.xml.ws.http.HTTPException) WebServiceException(javax.xml.ws.WebServiceException) SOAPException(javax.xml.soap.SOAPException) SOAPBinding(javax.xml.ws.soap.SOAPBinding) SOAPFault(javax.xml.soap.SOAPFault) Fault(org.apache.cxf.interceptor.Fault) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) IOException(java.io.IOException) HTTPBinding(javax.xml.ws.http.HTTPBinding)

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