Search in sources :

Example 56 with WebMethod

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

the class CodeGenTest method testAsyncMethod.

@Test
public void testAsyncMethod() throws Exception {
    env.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world_async.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 async = new File(w2j, "hello_world_async_soap_http");
    assertTrue(async.exists());
    File[] files = async.listFiles();
    assertEquals(4, files.length);
    Class<?> clz = classLoader.loadClass("org.apache.cxf.w2j.hello_world_async_soap_http.GreeterAsync");
    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)

Example 57 with WebMethod

use of javax.jws.WebMethod 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 58 with WebMethod

use of javax.jws.WebMethod in project jaffa-framework by jaffa-projects.

the class WebServiceInvoker method unmarshalResponse.

/**
 * Unmarshals the response into a corresponding Java object.
 * @param response the SOAPMessage returned by a WebService.
 * @return the corresponding Java object.
 * @throws SOAPException if any SOAP error occurs.
 * @throws SOAPFaultException if any SOAPFault occurs.
 * @throws JAXBException if any XML (un)marshalling error occurs.
 */
protected Object unmarshalResponse(SOAPMessage response) throws SOAPException, SOAPFaultException, JAXBException {
    if (log.isDebugEnabled()) {
        log.debug("Unmarshalling response: " + response);
        try {
            StringWriter sw = new StringWriter();
            TransformerFactory.newInstance().newTransformer().transform(new DOMSource(response.getSOAPPart()), new StreamResult(sw));
            log.debug("Contents of response: " + sw.toString());
        } catch (Exception e) {
        // do nothing
        }
    }
    // Determine the response type
    Class responseClass = null;
    boolean isCollection = false;
    for (Method m : getWebServiceClass().getMethods()) {
        if (m.getName().equals(getOperationName()) && m.getAnnotation(WebMethod.class) != null) {
            responseClass = m.getReturnType();
            if (Collection.class.isAssignableFrom(responseClass)) {
                if (ParameterizedType.class.isAssignableFrom(m.getGenericReturnType().getClass())) {
                    isCollection = true;
                    ParameterizedType genericType = (ParameterizedType) m.getGenericReturnType();
                    responseClass = ((Class) (genericType.getActualTypeArguments()[0]));
                }
            }
            break;
        }
    }
    if (responseClass == null) {
        String s = "Unable to locate the WebMethod '" + getOperationName() + "' on the class " + getWebServiceClass();
        log.error(s);
        throw new IllegalArgumentException(s);
    }
    if (response.getSOAPBody().hasFault()) {
        SOAPFault fault = response.getSOAPBody().getFault();
        log.error("SOAPFault occurred while invoking WebService " + getWebServiceClass() + " with faultcode " + fault.getFaultCode());
        throw new SOAPFaultException(fault);
    }
    // The response body will be of the format
    // <env:Body>
    // <j:performInquiryResponse>
    // <return><summaryStockBalancesOutDto>...</return>
    // <return><summaryStockBalancesOutDto>...</return>
    // ...
    // </j:performInquiryResponse>
    // </env:Body>
    // Unmarshal the contents of the "return" node to an instance of the responseClass
    Object output = null;
    NodeList returnNodes = response.getSOAPBody().getFirstChild().getChildNodes();
    if (returnNodes != null && returnNodes.getLength() > 0) {
        if (isCollection) {
            output = Array.newInstance(responseClass, returnNodes.getLength());
            JAXBContext jc = JAXBHelper.obtainJAXBContext(responseClass);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            for (int i = 0; i < returnNodes.getLength(); i++) {
                JAXBElement jaxbElement = unmarshaller.unmarshal(returnNodes.item(i), responseClass);
                Array.set(output, i, jaxbElement.getValue());
            }
            output = Arrays.asList(output);
        } else if (responseClass.isArray()) {
            responseClass = responseClass.getComponentType();
            output = Array.newInstance(responseClass, returnNodes.getLength());
            JAXBContext jc = JAXBHelper.obtainJAXBContext(responseClass);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            for (int i = 0; i < returnNodes.getLength(); i++) {
                JAXBElement jaxbElement = unmarshaller.unmarshal(returnNodes.item(i), responseClass);
                Array.set(output, i, jaxbElement.getValue());
            }
        } else {
            JAXBContext jc = JAXBHelper.obtainJAXBContext(responseClass);
            Unmarshaller unmarshaller = jc.createUnmarshaller();
            JAXBElement jaxbElement = unmarshaller.unmarshal(returnNodes.item(0), responseClass);
            output = jaxbElement.getValue();
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("Response unmarshalled to: " + output);
    }
    return output;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) StreamResult(javax.xml.transform.stream.StreamResult) NodeList(org.w3c.dom.NodeList) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) JAXBContext(javax.xml.bind.JAXBContext) Method(java.lang.reflect.Method) WebMethod(javax.jws.WebMethod) JAXBElement(javax.xml.bind.JAXBElement) SOAPException(javax.xml.soap.SOAPException) JAXBException(javax.xml.bind.JAXBException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) ParameterizedType(java.lang.reflect.ParameterizedType) StringWriter(java.io.StringWriter) SOAPFault(javax.xml.soap.SOAPFault) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 59 with WebMethod

use of javax.jws.WebMethod in project ats-framework by Axway.

the class AgentWsImpl method getMonitoringResults.

/**
     * @return the latest info about the Agent users activity
     *
     * @throws AgentException
     * @throws InternalComponentException
     */
@WebMethod
public synchronized byte[] getMonitoringResults() throws AgentException, InternalComponentException {
    try {
        ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutStream = new ObjectOutputStream(byteOutStream);
        objectOutStream.writeObject(UserActionsMonitoringAgent.getInstance(getCaller()).getMonitoringResults());
        return byteOutStream.toByteArray();
    } catch (Exception e) {
        handleExceptions(e);
        // always throw but the compiler is not aware of this
        return null;
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) InternalComponentException(com.axway.ats.agent.core.exceptions.InternalComponentException) AgentException(com.axway.ats.agent.core.exceptions.AgentException) NoSuchActionException(com.axway.ats.agent.core.exceptions.NoSuchActionException) NoCompatibleMethodFoundException(com.axway.ats.agent.core.exceptions.NoCompatibleMethodFoundException) NoSuchComponentException(com.axway.ats.agent.core.exceptions.NoSuchComponentException) IOException(java.io.IOException) ActionExecutionException(com.axway.ats.agent.core.exceptions.ActionExecutionException) WebMethod(javax.jws.WebMethod)

Example 60 with WebMethod

use of javax.jws.WebMethod in project bamboobsc by billchen198318.

the class ApiWebServiceImpl method getScorecard2.

@WebMethod
@GET
@Path("/scorecard2/")
@Override
public BscApiServiceResponse getScorecard2(@WebParam(name = "visionId") @QueryParam("visionId") String visionId, @WebParam(name = "startDate") @QueryParam("startDate") String startDate, @WebParam(name = "endDate") @QueryParam("endDate") String endDate, @WebParam(name = "startYearDate") @QueryParam("startYearDate") String startYearDate, @WebParam(name = "endYearDate") @QueryParam("endYearDate") String endYearDate, @WebParam(name = "frequency") @QueryParam("frequency") String frequency, @WebParam(name = "dataFor") @QueryParam("dataFor") String dataFor, @WebParam(name = "measureDataOrganizationId") @QueryParam("measureDataOrganizationId") String measureDataOrganizationId, @WebParam(name = "measureDataEmployeeId") @QueryParam("measureDataEmployeeId") String measureDataEmployeeId, @WebParam(name = "contentFlag") @QueryParam("contentFlag") String contentFlag) throws Exception {
    HttpServletRequest request = null;
    if (this.getWebServiceContext() != null && this.getWebServiceContext().getMessageContext() != null) {
        request = (HttpServletRequest) this.getWebServiceContext().getMessageContext().get(MessageContext.SERVLET_REQUEST);
    }
    Subject subject = null;
    BscApiServiceResponse responseObj = new BscApiServiceResponse();
    responseObj.setSuccess(YesNo.NO);
    try {
        subject = WsAuthenticateUtils.login();
        @SuppressWarnings("unchecked") IVisionService<VisionVO, BbVision, String> visionService = (IVisionService<VisionVO, BbVision, String>) AppContext.getBean("bsc.service.VisionService");
        @SuppressWarnings("unchecked") IEmployeeService<EmployeeVO, BbEmployee, String> employeeService = (IEmployeeService<EmployeeVO, BbEmployee, String>) AppContext.getBean("bsc.service.EmployeeService");
        @SuppressWarnings("unchecked") IOrganizationService<OrganizationVO, BbOrganization, String> organizationService = (IOrganizationService<OrganizationVO, BbOrganization, String>) AppContext.getBean("bsc.service.OrganizationService");
        String visionOid = "";
        String measureDataOrganizationOid = "";
        String measureDataEmployeeOid = "";
        DefaultResult<VisionVO> visionResult = visionService.findForSimpleByVisId(visionId);
        if (visionResult.getValue() == null) {
            throw new Exception(visionResult.getSystemMessage().getValue());
        }
        visionOid = visionResult.getValue().getOid();
        if (StringUtils.isBlank(measureDataOrganizationId)) {
            measureDataOrganizationOid = BscBaseLogicServiceCommonSupport.findEmployeeDataByEmpId(employeeService, measureDataOrganizationId).getOid();
        }
        if (StringUtils.isBlank(measureDataEmployeeId)) {
            measureDataEmployeeOid = BscBaseLogicServiceCommonSupport.findOrganizationDataByUK(organizationService, measureDataEmployeeId).getOid();
        }
        this.processForScorecard(responseObj, request, visionOid, startDate, endDate, startYearDate, endYearDate, frequency, dataFor, measureDataOrganizationOid, measureDataEmployeeOid, contentFlag);
    } catch (Exception e) {
        responseObj.setMessage(e.getMessage());
    } finally {
        if (!YesNo.YES.equals(responseObj.getSuccess())) {
            responseObj.setMessage(SysMessageUtil.get(GreenStepSysMsgConstants.SEARCH_NO_DATA));
        }
        WsAuthenticateUtils.logout(subject);
    }
    subject = null;
    return responseObj;
}
Also used : IVisionService(com.netsteadfast.greenstep.bsc.service.IVisionService) IOrganizationService(com.netsteadfast.greenstep.bsc.service.IOrganizationService) BbVision(com.netsteadfast.greenstep.po.hbm.BbVision) OrganizationVO(com.netsteadfast.greenstep.vo.OrganizationVO) VisionVO(com.netsteadfast.greenstep.vo.VisionVO) Subject(org.apache.shiro.subject.Subject) ServiceException(com.netsteadfast.greenstep.base.exception.ServiceException) HttpServletRequest(javax.servlet.http.HttpServletRequest) BbEmployee(com.netsteadfast.greenstep.po.hbm.BbEmployee) EmployeeVO(com.netsteadfast.greenstep.vo.EmployeeVO) BscApiServiceResponse(com.netsteadfast.greenstep.bsc.vo.BscApiServiceResponse) BbOrganization(com.netsteadfast.greenstep.po.hbm.BbOrganization) IEmployeeService(com.netsteadfast.greenstep.bsc.service.IEmployeeService) WebMethod(javax.jws.WebMethod) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

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