Search in sources :

Example 1 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class WSDLGenerator method generateBindingOperation.

protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
    BindingOperationType operation = binding.operation().name(method.getOperationName());
    extension.addBindingOperationExtension(operation, method);
    String targetNamespace = model.getTargetNamespace();
    QName requestMessage = new QName(targetNamespace, method.getOperationName());
    List<ParameterImpl> bodyParams = new ArrayList<>();
    List<ParameterImpl> headerParams = new ArrayList<>();
    splitParameters(bodyParams, headerParams, method.getRequestParameters());
    SOAPBinding soapBinding = method.getBinding();
    operation.soapOperation().soapAction(soapBinding.getSOAPAction());
    // input
    TypedXmlWriter input = operation.input();
    extension.addBindingOperationInputExtension(input, method);
    BodyType body = input._element(Body.class);
    boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
    if (soapBinding.getUse() == Use.LITERAL) {
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().next();
                if (isRpc) {
                    StringBuilder parts = new StringBuilder();
                    int i = 0;
                    for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                        if (i++ > 0)
                            parts.append(' ');
                        parts.append(parameter.getPartName());
                    }
                    body.parts(parts.toString());
                } else {
                    body.parts(param.getPartName());
                }
            } else {
                body.parts("");
            }
            generateSOAPHeaders(input, headerParams, requestMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    } else {
        // TODO localize this
        throw new WebServiceException("encoded use is not supported");
    }
    if (method.getMEP() != MEP.ONE_WAY) {
        // output
        bodyParams.clear();
        headerParams.clear();
        splitParameters(bodyParams, headerParams, method.getResponseParameters());
        TypedXmlWriter output = operation.output();
        extension.addBindingOperationOutputExtension(output, method);
        body = output._element(Body.class);
        body.use(LITERAL);
        if (headerParams.size() > 0) {
            StringBuilder parts = new StringBuilder();
            if (bodyParams.size() > 0) {
                ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
                if (param != null) {
                    if (isRpc) {
                        int i = 0;
                        for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
                            if (i++ > 0) {
                                parts.append(" ");
                            }
                            parts.append(parameter.getPartName());
                        }
                    } else {
                        parts = new StringBuilder(param.getPartName());
                    }
                }
            }
            body.parts(parts.toString());
            QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
            generateSOAPHeaders(output, headerParams, responseMessage);
        }
        if (isRpc) {
            body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
        }
    }
    for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
        Fault fault = operation.fault().name(exception.getMessageName());
        extension.addBindingOperationFaultExtension(fault, method, exception);
        SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
        soapFault.use(LITERAL);
    }
}
Also used : BindingOperationType(com.sun.xml.ws.wsdl.writer.document.BindingOperationType) WebServiceException(jakarta.xml.ws.WebServiceException) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CheckedExceptionImpl(com.sun.xml.ws.model.CheckedExceptionImpl) SOAPBinding(com.sun.xml.ws.api.model.soap.SOAPBinding) WrapperParameter(com.sun.xml.ws.model.WrapperParameter) Fault(com.sun.xml.ws.wsdl.writer.document.Fault) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) BodyType(com.sun.xml.ws.wsdl.writer.document.soap.BodyType) TypedXmlWriter(com.sun.xml.txw2.TypedXmlWriter) ParameterImpl(com.sun.xml.ws.model.ParameterImpl) SOAPFault(com.sun.xml.ws.wsdl.writer.document.soap.SOAPFault) Body(com.sun.xml.ws.wsdl.writer.document.soap.Body)

Example 2 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class RuntimeWSDLParser method parse.

/**
 * Parses the WSDL and gives WSDLModel. If wsdl parameter is null, then wsdlLoc is used to get the WSDL. If the WSDL
 * document could not be obtained then {@link MetadataResolverFactory} is tried to get the WSDL document, if not found
 * then as last option, if the wsdlLoc has no '?wsdl' as query parameter then it is tried by appending '?wsdl'.
 *
 * @param wsdlLoc
 *      Either this or {@code wsdl} parameter must be given.
 *      Null location means the system won't be able to resolve relative references in the WSDL,
 */
public static WSDLModel parse(@Nullable URL wsdlLoc, @NotNull Source wsdlSource, @NotNull EntityResolver resolver, boolean isClientSide, Container container, Class serviceClass, @NotNull PolicyResolver policyResolver, boolean isUseStreamFromEntityResolverWrapper, WSDLParserExtension... extensions) throws IOException, XMLStreamException, SAXException {
    assert resolver != null;
    RuntimeWSDLParser wsdlParser = new RuntimeWSDLParser(wsdlSource.getSystemId(), new EntityResolverWrapper(resolver, isUseStreamFromEntityResolverWrapper), isClientSide, container, policyResolver, extensions);
    Parser parser;
    try {
        parser = wsdlParser.resolveWSDL(wsdlLoc, wsdlSource, serviceClass);
        if (!hasWSDLDefinitions(parser.parser)) {
            throw new XMLStreamException(ClientMessages.RUNTIME_WSDLPARSER_INVALID_WSDL(parser.systemId, WSDLConstants.QNAME_DEFINITIONS, parser.parser.getName(), parser.parser.getLocation()));
        }
    } catch (XMLStreamException e) {
        // Try MEX if there is WSDLLoc available
        if (wsdlLoc == null)
            throw e;
        return tryWithMex(wsdlParser, wsdlLoc, resolver, isClientSide, container, e, serviceClass, policyResolver, extensions);
    } catch (IOException e) {
        // Try MEX if there is WSDLLoc available
        if (wsdlLoc == null)
            throw e;
        return tryWithMex(wsdlParser, wsdlLoc, resolver, isClientSide, container, e, serviceClass, policyResolver, extensions);
    }
    wsdlParser.extensionFacade.start(wsdlParser.context);
    wsdlParser.parseWSDL(parser, false);
    wsdlParser.wsdlDoc.freeze();
    wsdlParser.extensionFacade.finished(wsdlParser.context);
    wsdlParser.extensionFacade.postFinished(wsdlParser.context);
    if (wsdlParser.wsdlDoc.getServices().isEmpty())
        throw new WebServiceException(ClientMessages.WSDL_CONTAINS_NO_SERVICE(wsdlLoc));
    return wsdlParser.wsdlDoc;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) IOException(java.io.IOException) Parser(com.sun.xml.ws.api.wsdl.parser.XMLEntityResolver.Parser)

Example 3 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class ManagedServiceAssertionTest method testEndpointDisposeDelayInvalid.

public void testEndpointDisposeDelayInvalid() throws AssertionCreationException {
    final HashMap<QName, String> attributes = new HashMap<QName, String>();
    attributes.put(ID_ATTRIBUTE_QNAME, "id1");
    attributes.put(ENDPOINT_DISPOSE_DELAY_ATTRIBUTE_QNAME, "not an integer");
    final AssertionData data = AssertionData.createAssertionData(ManagedServiceAssertion.MANAGED_SERVICE_QNAME, null, attributes, false, false);
    final ManagedServiceAssertion instance = new ManagedServiceAssertion(data, null);
    try {
        final long result = instance.getEndpointDisposeDelay(2000l);
        fail("Expected a WebserviceException, instead got this value: \"" + result + '"');
    } catch (WebServiceException e) {
    // Expected this exception
    }
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) AssertionData(com.sun.xml.ws.policy.sourcemodel.AssertionData)

Example 4 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class W3CAddressingWSDLParserExtension method bindingOperationElements.

@Override
public boolean bindingOperationElements(EditableWSDLBoundOperation operation, XMLStreamReader reader) {
    EditableWSDLBoundOperation edit = operation;
    QName anon = reader.getName();
    if (anon.equals(AddressingVersion.W3C.wsdlAnonymousTag)) {
        try {
            String value = reader.getElementText();
            if (value == null || value.trim().equals("")) {
                throw new WebServiceException("Null values not permitted in wsaw:Anonymous.");
            // TODO: throw exception only if wsdl:required=true
            // TODO: is this the right exception ?
            } else if (value.equals("optional")) {
                edit.setAnonymous(WSDLBoundOperation.ANONYMOUS.optional);
            } else if (value.equals("required")) {
                edit.setAnonymous(WSDLBoundOperation.ANONYMOUS.required);
            } else if (value.equals("prohibited")) {
                edit.setAnonymous(WSDLBoundOperation.ANONYMOUS.prohibited);
            } else {
                throw new WebServiceException("wsaw:Anonymous value \"" + value + "\" not understood.");
            // TODO: throw exception only if wsdl:required=true
            // TODO: is this the right exception ?
            }
        } catch (XMLStreamException e) {
            // TODO: is this the correct behavior ?
            throw new WebServiceException(e);
        }
        // consumed the element
        return true;
    }
    return false;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException) XMLStreamException(javax.xml.stream.XMLStreamException) QName(javax.xml.namespace.QName)

Example 5 with WebServiceException

use of jakarta.xml.ws.WebServiceException in project metro-jax-ws by eclipse-ee4j.

the class W3CAddressingWSDLParserExtension method buildAction.

protected static final String buildAction(String name, EditableWSDLOperation o, boolean isFault) {
    String tns = o.getName().getNamespaceURI();
    String delim = SLASH_DELIMITER;
    // TODO: is this the correct way to find the separator ?
    if (!tns.startsWith("http"))
        delim = COLON_DELIMITER;
    if (tns.endsWith(delim))
        tns = tns.substring(0, tns.length() - 1);
    if (o.getPortTypeName() == null)
        throw new WebServiceException("\"" + o.getName() + "\" operation's owning portType name is null.");
    return tns + delim + o.getPortTypeName().getLocalPart() + delim + (isFault ? o.getName().getLocalPart() + delim + "Fault" + delim : "") + name;
}
Also used : WebServiceException(jakarta.xml.ws.WebServiceException)

Aggregations

WebServiceException (jakarta.xml.ws.WebServiceException)386 QName (javax.xml.namespace.QName)49 SOAPFaultException (jakarta.xml.ws.soap.SOAPFaultException)36 SOAPException (jakarta.xml.soap.SOAPException)33 JAXBException (jakarta.xml.bind.JAXBException)30 Node (org.w3c.dom.Node)28 JAXBContext (jakarta.xml.bind.JAXBContext)27 IOException (java.io.IOException)26 SOAPMessage (jakarta.xml.soap.SOAPMessage)25 XMLStreamException (javax.xml.stream.XMLStreamException)25 Source (javax.xml.transform.Source)23 ProtocolException (jakarta.xml.ws.ProtocolException)20 Dispatch (jakarta.xml.ws.Dispatch)19 MalformedURLException (java.net.MalformedURLException)19 MessageContext (jakarta.xml.ws.handler.MessageContext)17 Map (java.util.Map)17 URL (java.net.URL)16 StreamSource (javax.xml.transform.stream.StreamSource)16 HandlerTracker (fromwsdl.handler.common.HandlerTracker)14 HandlerTracker (handler.handler_processing.common.HandlerTracker)14