Search in sources :

Example 1 with WebResult

use of javax.jws.WebResult in project camel by apache.

the class ServiceInterfaceStrategy method getOutInfo.

private TypeInfo getOutInfo(Method method) {
    ResponseWrapper respWrap = method.getAnnotation(ResponseWrapper.class);
    if (respWrap != null && respWrap.className() != null) {
        return new TypeInfo(respWrap.className(), new QName(respWrap.targetNamespace(), respWrap.localName()));
    }
    Class<?> returnType = method.getReturnType();
    if (Void.TYPE.equals(returnType)) {
        return new TypeInfo(null, null);
    } else {
        Class<?> type = method.getReturnType();
        WebResult webResult = method.getAnnotation(WebResult.class);
        if (webResult != null) {
            return new TypeInfo(type.getName(), new QName(webResult.targetNamespace(), webResult.name()));
        } else {
            throw new IllegalArgumentException("Result type of method " + method.getName() + " is not annotated with WebParam. This is not yet supported");
        }
    }
}
Also used : QName(javax.xml.namespace.QName) ResponseWrapper(javax.xml.ws.ResponseWrapper) WebResult(javax.jws.WebResult)

Example 2 with WebResult

use of javax.jws.WebResult in project quickstarts by jboss-switchyard.

the class ReverseService method reverse.

@POST
@Path("/")
@WebMethod(action = "urn:switchyard-quickstart:camel-soap-proxy:1.0")
@WebResult(name = "text")
public String reverse(@WebParam(name = "text") String text) throws Exception {
    if (text.equals("fault")) {
        SOAPFactory factory = SOAPFactory.newInstance();
        SOAPFault sf = factory.createFault("myfaultstring", new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, "Server"));
        sf.setFaultActor("myFaultActor");
        Detail d = sf.addDetail();
        QName entryName = new QName("urn:switchyard-quickstart:camel-soap-proxy:1.0", "order", "PO");
        DetailEntry entry = d.addDetailEntry(entryName);
        QName name = new QName("urn:switchyard-quickstart:camel-soap-proxy:1.0", "symbol");
        SOAPElement symbol = entry.addChildElement(name);
        symbol.addTextNode("SUNW");
        throw new SOAPFaultException(sf);
    }
    return new StringBuilder(text).reverse().toString();
}
Also used : QName(javax.xml.namespace.QName) DetailEntry(javax.xml.soap.DetailEntry) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPFactory(javax.xml.soap.SOAPFactory) Detail(javax.xml.soap.Detail) Path(javax.ws.rs.Path) WebMethod(javax.jws.WebMethod) POST(javax.ws.rs.POST) WebResult(javax.jws.WebResult)

Example 3 with WebResult

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

the class JaxWsServiceConfiguration method getOutPartName.

@Override
public QName getOutPartName(OperationInfo op, Method method, int paramNumber) {
    method = getDeclaredMethod(method);
    if (paramNumber >= 0) {
        return getPartName(op, method, paramNumber, op.getOutput(), "return", false);
    }
    WebResult webResult = getWebResult(method);
    String tns = op.getOutput().getName().getNamespaceURI();
    String local = null;
    if (webResult != null) {
        if (Boolean.TRUE.equals(isRPC(method)) || isDocumentBare(method)) {
            local = webResult.partName();
        }
        if (local == null || local.length() == 0) {
            local = webResult.name();
        }
    }
    if (local == null || local.length() == 0) {
        if (Boolean.TRUE.equals(isRPC(method)) || !Boolean.FALSE.equals(isWrapped(method))) {
            local = "return";
        } else {
            local = getOperationName(op.getInterface(), method).getLocalPart() + "Response";
        }
    }
    return new QName(tns, local);
}
Also used : QName(javax.xml.namespace.QName) WebResult(javax.jws.WebResult)

Example 4 with WebResult

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

the class CodeGenTest method testHelloWorldSoap12.

@Test
public void testHelloWorldSoap12() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_soap12.wsdl"));
    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 helloworldsoaphttp = new File(w2j, "hello_world_soap12_http");
    assertTrue(helloworldsoaphttp.exists());
    File types = new File(helloworldsoaphttp, "types");
    assertTrue(types.exists());
    File[] files = helloworldsoaphttp.listFiles();
    assertEquals(5, files.length);
    files = types.listFiles();
    assertEquals(7, files.length);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_soap12_http.Greeter");
    assertTrue("class " + clz.getName() + " modifier is not public", Modifier.isPublic(clz.getModifiers()));
    assertTrue("class " + clz.getName() + " modifier is interface", Modifier.isInterface(clz.getModifiers()));
    WebService webServiceAnn = AnnotationUtil.getPrivClassAnnotation(clz, WebService.class);
    assertEquals("Greeter", webServiceAnn.name());
    Method method = clz.getMethod("sayHi", new Class[] {});
    WebMethod webMethodAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class);
    if (webMethodAnno.operationName() != null && !"".equals(webMethodAnno.operationName())) {
        assertEquals(method.getName() + "()" + " Annotation : WebMethod.operationName ", "sayHi", webMethodAnno.operationName());
    }
    RequestWrapper requestWrapperAnn = AnnotationUtil.getPrivMethodAnnotation(method, RequestWrapper.class);
    assertEquals("org.apache.cxf.w2j.hello_world_soap12_http.types.SayHi", requestWrapperAnn.className());
    ResponseWrapper resposneWrapperAnn = AnnotationUtil.getPrivMethodAnnotation(method, ResponseWrapper.class);
    assertEquals("sayHiResponse", resposneWrapperAnn.localName());
    WebResult webResultAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebResult.class);
    assertEquals("responseType", webResultAnno.name());
    method = clz.getMethod("pingMe", new Class[] {});
    webMethodAnno = AnnotationUtil.getPrivMethodAnnotation(method, WebMethod.class);
    if (webMethodAnno.operationName() != null && !"".equals(webMethodAnno.operationName())) {
        assertEquals(method.getName() + "()" + " Annotation : WebMethod.operationName ", "pingMe", webMethodAnno.operationName());
    }
    Class<?>[] exceptionCls = method.getExceptionTypes();
    assertEquals(1, exceptionCls.length);
    assertEquals("org.apache.cxf.w2j.hello_world_soap12_http.PingMeFault", exceptionCls[0].getName());
}
Also used : WebMethod(javax.jws.WebMethod) WebService(javax.jws.WebService) RequestWrapper(javax.xml.ws.RequestWrapper) ResponseWrapper(javax.xml.ws.ResponseWrapper) ObjectStreamClass(java.io.ObjectStreamClass) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) WebResult(javax.jws.WebResult) File(java.io.File) AbstractCodeGenTest(org.apache.cxf.tools.wsdlto.AbstractCodeGenTest) Test(org.junit.Test)

Example 5 with WebResult

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

the class CustomerService method getCustomers.

@WebMethod
@WebResult(name = "customers")
public Customers getCustomers() {
    Customers cbean = new Customers();
    cbean.setCustomer(customers.values());
    return cbean;
}
Also used : Customers(org.apache.cxf.customer.Customers) WebMethod(javax.jws.WebMethod) WebResult(javax.jws.WebResult)

Aggregations

WebResult (javax.jws.WebResult)20 WebMethod (javax.jws.WebMethod)14 Method (java.lang.reflect.Method)4 WebParam (javax.jws.WebParam)4 QName (javax.xml.namespace.QName)4 ResponseWrapper (javax.xml.ws.ResponseWrapper)4 AbstractCodeGenTest (org.apache.cxf.tools.wsdlto.AbstractCodeGenTest)4 Test (org.junit.Test)4 File (java.io.File)3 ObjectStreamClass (java.io.ObjectStreamClass)3 Calendar (java.util.Calendar)2 WebService (javax.jws.WebService)2 RequestWrapper (javax.xml.ws.RequestWrapper)2 Customers (org.apache.cxf.customer.Customers)2 Project (com.artezio.arttime.datamodel.Project)1 BigInteger (java.math.BigInteger)1 Oneway (javax.jws.Oneway)1 SOAPBinding (javax.jws.soap.SOAPBinding)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1