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());
}
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());
}
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;
}
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;
}
}
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;
}
Aggregations