Search in sources :

Example 71 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class JaxWsServiceConfiguration method getOperationName.

@Override
public QName getOperationName(InterfaceInfo intf, Method method) {
    method = getDeclaredMethod(method);
    WebMethod wm = method.getAnnotation(WebMethod.class);
    if (wm != null) {
        String name = wm.operationName();
        if (name.length() == 0) {
            name = method.getName();
        }
        return new QName(intf.getName().getNamespaceURI(), name);
    }
    return new QName(intf.getName().getNamespaceURI(), method.getName());
}
Also used : WebMethod(javax.jws.WebMethod) QName(javax.xml.namespace.QName)

Example 72 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class JaxWsServiceConfiguration method getResponseWrapperName.

@Override
public QName getResponseWrapperName(OperationInfo op, Method method) {
    Method m = getDeclaredMethod(method);
    ResponseWrapper rw = m.getAnnotation(ResponseWrapper.class);
    String nm = null;
    String lp = null;
    if (rw != null) {
        nm = rw.targetNamespace();
        lp = rw.localName();
    }
    WebMethod meth = m.getAnnotation(WebMethod.class);
    if (meth != null && StringUtils.isEmpty(lp)) {
        lp = meth.operationName();
        if (!StringUtils.isEmpty(lp)) {
            lp += "Response";
        }
    }
    if (StringUtils.isEmpty(nm)) {
        nm = op.getName().getNamespaceURI();
    }
    if (!StringUtils.isEmpty(nm) && !StringUtils.isEmpty(lp)) {
        return new QName(nm, lp);
    }
    return null;
}
Also used : WebMethod(javax.jws.WebMethod) QName(javax.xml.namespace.QName) ResponseWrapper(javax.xml.ws.ResponseWrapper) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod)

Example 73 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class JaxWsServiceFactoryBean method buildWSAActions.

private void buildWSAActions(OperationInfo operation, Method method) {
    // nothing
    if (method == null) {
        return;
    }
    Action action = method.getAnnotation(Action.class);
    Addressing addressing = method.getDeclaringClass().getAnnotation(Addressing.class);
    if (action == null && addressing == null) {
        return;
    }
    WebMethod wm = method.getAnnotation(WebMethod.class);
    String inputAction = "";
    if (action != null) {
        inputAction = action.input();
    }
    if (wm != null && StringUtils.isEmpty(inputAction)) {
        inputAction = wm.action();
    }
    if (StringUtils.isEmpty(inputAction)) {
        inputAction = computeAction(operation, "Request");
    }
    if (action == null && addressing != null) {
        operation.getInput().addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, inputAction);
        operation.getInput().addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, inputAction);
        if (operation.getOutput() != null) {
            operation.getOutput().addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, "Response"));
            operation.getOutput().addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, computeAction(operation, "Response"));
        }
    } else {
        MessageInfo input = operation.getInput();
        input.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, inputAction);
        if (!StringUtils.isEmpty(action.input())) {
            input.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, inputAction);
        }
        MessageInfo output = operation.getOutput();
        if (output != null && !StringUtils.isEmpty(action.output())) {
            output.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, action.output());
            output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, action.output());
        } else if (output != null) {
            output.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, "Response"));
        }
        FaultAction[] faultActions = action.fault();
        if (faultActions != null && faultActions.length > 0 && operation.getFaults() != null) {
            for (FaultAction faultAction : faultActions) {
                FaultInfo faultInfo = getFaultInfo(operation, faultAction.className());
                if (faultInfo != null && !StringUtils.isEmpty(faultAction.value())) {
                    faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, faultAction.value());
                    faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, faultAction.value());
                }
                if (operation.isUnwrappedCapable()) {
                    faultInfo = getFaultInfo(operation.getUnwrappedOperation(), faultAction.className());
                    if (faultInfo != null && !StringUtils.isEmpty(faultAction.value())) {
                        faultInfo.addExtensionAttribute(JAXWSAConstants.WSAW_ACTION_QNAME, faultAction.value());
                        faultInfo.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, faultAction.value());
                    }
                }
            }
        }
    }
    for (FaultInfo fi : operation.getFaults()) {
        if (fi.getExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME) == null) {
            String f = "/Fault/" + fi.getName().getLocalPart();
            fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, f));
            if (operation.isUnwrappedCapable()) {
                fi = operation.getUnwrappedOperation().getFault(fi.getName());
                fi.addExtensionAttribute(JAXWSAConstants.WSAM_ACTION_QNAME, computeAction(operation, f));
            }
        }
    }
}
Also used : WebMethod(javax.jws.WebMethod) FaultAction(javax.xml.ws.FaultAction) Action(javax.xml.ws.Action) FaultAction(javax.xml.ws.FaultAction) FaultInfo(org.apache.cxf.service.model.FaultInfo) Addressing(javax.xml.ws.soap.Addressing) MessageInfo(org.apache.cxf.service.model.MessageInfo)

Example 74 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class CustomerService method getCustomers.

@WebMethod
@WebResult(name = "customers")
public Customers getCustomers(@WebParam(name = "GetCustomers") GetCustomers req) {
    Customers cbean = new Customers();
    cbean.setCustomer(customers.values());
    if (context == null || context.getMessageContext() == null) {
        throw new WebServiceException("WebServiceContext is null!");
    }
    return cbean;
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Customers(org.apache.cxf.customer.Customers) WebMethod(javax.jws.WebMethod) WebResult(javax.jws.WebResult)

Example 75 with WebMethod

use of javax.jws.WebMethod in project cxf by apache.

the class CodeGenTest method testAsyncMethodFromCommandLine.

@Test
public void testAsyncMethodFromCommandLine() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
    env.put(ToolConstants.CFG_ASYNCMETHODS, new String[0]);
    processor.setContext(env);
    processor.execute();
    assertNotNull(output);
    File org = new File(output, "org");
    assertTrue(org.exists());
    File apache = new File(org, "apache");
    assertTrue(apache.exists());
    File cxf = new File(apache, "cxf");
    assertTrue(cxf.exists());
    File w2j = new File(cxf, "w2j");
    assertTrue(w2j.exists());
    File async = new File(w2j, "hello_world_soap_http");
    assertTrue(async.exists());
    File[] files = async.listFiles();
    assertEquals(9, files.length);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap_http.Greeter");
    Method method1 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class, javax.xml.ws.AsyncHandler.class });
    WebMethod webMethodAnno1 = AnnotationUtil.getPrivMethodAnnotation(method1, WebMethod.class);
    assertEquals(method1.getName() + "()" + " Annotation : WebMethod.operationName ", "greetMeSometime", webMethodAnno1.operationName());
    java.lang.reflect.Method method2 = clz.getMethod("greetMeSometimeAsync", new Class[] { java.lang.String.class });
    WebMethod webMethodAnno2 = AnnotationUtil.getPrivMethodAnnotation(method2, WebMethod.class);
    assertEquals(method2.getName() + "()" + " Annotation : WebMethod.operationName ", "greetMeSometime", webMethodAnno2.operationName());
}
Also used : WebMethod(javax.jws.WebMethod) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) File(java.io.File) Method(java.lang.reflect.Method) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Aggregations

WebMethod (javax.jws.WebMethod)107 Method (java.lang.reflect.Method)18 Path (javax.ws.rs.Path)17 IOException (java.io.IOException)16 WebResult (javax.jws.WebResult)13 MessageContext (javax.xml.ws.handler.MessageContext)12 WebServiceException (javax.xml.ws.WebServiceException)11 Test (org.junit.Test)10 DataHandler (javax.activation.DataHandler)9 GET (javax.ws.rs.GET)9 Action (javax.xml.ws.Action)9 ArrayList (java.util.ArrayList)8 Oneway (javax.jws.Oneway)8 POST (javax.ws.rs.POST)8 File (java.io.File)7 InputStream (java.io.InputStream)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 QName (javax.xml.namespace.QName)6 RequestWrapper (javax.xml.ws.RequestWrapper)6 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)6