use of org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator in project cxf by apache.
the class OperationProcessor method processMethod.
void processMethod(JavaMethod method, OperationInfo operation) throws ToolException {
if (isAsyncMethod(method)) {
return;
}
MessageInfo inputMessage = operation.getInput();
MessageInfo outputMessage = operation.getOutput();
if (inputMessage == null) {
LOG.log(Level.WARNING, "NO_INPUT_MESSAGE", new Object[] { operation.getName() });
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("INVALID_MEP", LOG, new Object[] { operation.getName() });
throw new ToolException(msg);
}
ParameterProcessor paramProcessor = new ParameterProcessor(context);
method.clear();
JAXWSBinding opBinding = operation.getExtensor(JAXWSBinding.class);
JAXWSBinding ptBinding = operation.getInterface().getExtensor(JAXWSBinding.class);
JAXWSBinding defBinding = operation.getInterface().getService().getDescription().getExtensor(JAXWSBinding.class);
boolean enableAsync = false;
boolean enableMime = false;
boolean enableWrapper = method.isWrapperStyle();
if (defBinding != null) {
if (defBinding.isSetEnableMime()) {
enableMime = defBinding.isEnableMime();
}
if (defBinding.isSetEnableAsyncMapping()) {
enableAsync = defBinding.isEnableAsyncMapping();
}
if (defBinding.isSetEnableWrapperStyle()) {
enableWrapper = defBinding.isEnableWrapperStyle();
}
}
if (ptBinding != null) {
if (ptBinding.isSetEnableMime()) {
enableMime = ptBinding.isEnableMime();
}
if (ptBinding.isSetEnableAsyncMapping()) {
enableAsync = ptBinding.isEnableAsyncMapping();
}
if (ptBinding.isSetEnableWrapperStyle()) {
enableWrapper = ptBinding.isEnableWrapperStyle();
}
}
if (opBinding != null) {
if (opBinding.isSetEnableMime()) {
enableMime = opBinding.isEnableMime();
}
if (opBinding.isSetEnableAsyncMapping()) {
enableAsync = opBinding.isEnableAsyncMapping();
}
if (opBinding.isSetEnableWrapperStyle()) {
enableWrapper = opBinding.isEnableWrapperStyle();
}
}
enableWrapper = checkEnableWrapper(enableWrapper, method);
enableAsync = checkEnableAsync(enableAsync, method);
enableMime = checkEnableMime(enableMime, method);
method.setWrapperStyle(enableWrapper && method.isWrapperStyle());
paramProcessor.process(method, inputMessage, outputMessage, operation.getParameterOrdering());
if (method.isWrapperStyle()) {
setWrapper(operation);
method.annotate(new WrapperAnnotator(wrapperRequest, wrapperResponse));
}
method.annotate(new WebMethodAnnotator());
method.annotate(new WebResultAnnotator());
if (!method.isOneWay() && enableAsync && !isAddedAsycMethod(method)) {
addAsyncMethod(method);
}
if (enableMime) {
method.setMimeEnable(true);
}
}
use of org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator in project cxf by apache.
the class OperationProcessor method addCallbackMethod.
private void addCallbackMethod(JavaMethod method) throws ToolException {
JavaMethod callbackMethod = new JavaMethod(method.getInterface());
callbackMethod.setAsync(true);
callbackMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
callbackMethod.setStyle(method.getStyle());
callbackMethod.setWrapperStyle(method.isWrapperStyle());
callbackMethod.setSoapAction(method.getSoapAction());
callbackMethod.setOperationName(method.getOperationName());
JavaReturn future = new JavaReturn();
future.setClassName("Future<?>");
callbackMethod.setReturn(future);
// REVISIT: test the operation name in the annotation
callbackMethod.annotate(new WebMethodAnnotator());
callbackMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
callbackMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
callbackMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
String asyncCname = null;
for (JavaParameter param : method.getParameters()) {
if (convertOutToAsync) {
if (param.isHolder()) {
if (param.isINOUT()) {
JavaParameter p2 = new JavaParameter();
p2.setName(param.getName());
p2.setClassName(param.getHolderName());
p2.setStyle(JavaType.Style.IN);
callbackMethod.addParameter(p2);
for (String s : param.getAnnotationTags()) {
JAnnotation ann = param.getAnnotation(s);
p2.addAnnotation(s, ann);
}
} else if (!param.isHeader() && asyncCname == null) {
asyncCname = param.getClassName();
}
} else {
callbackMethod.addParameter(param);
}
} else {
callbackMethod.addParameter(param);
}
}
JavaParameter asyncHandler = new JavaParameter();
asyncHandler.setName("asyncHandler");
asyncHandler.setCallback(true);
asyncHandler.setClassName(getAsyncClassName(method, "AsyncHandler", asyncCname));
asyncHandler.setStyle(JavaType.Style.IN);
callbackMethod.addParameter(asyncHandler);
JAnnotation asyncHandlerAnnotation = new JAnnotation(WebParam.class);
asyncHandlerAnnotation.addElement(new JAnnotationElement("name", "asyncHandler"));
asyncHandlerAnnotation.addElement(new JAnnotationElement("targetNamespace", ""));
asyncHandler.addAnnotation("WebParam", asyncHandlerAnnotation);
method.getInterface().addImport("javax.jws.WebParam");
method.getInterface().addMethod(callbackMethod);
}
use of org.apache.cxf.tools.wsdlto.frontend.jaxws.processor.internal.annotator.WebMethodAnnotator in project cxf by apache.
the class OperationProcessor method addPollingMethod.
private void addPollingMethod(JavaMethod method) throws ToolException {
JavaMethod pollingMethod = new JavaMethod(method.getInterface());
pollingMethod.setAsync(true);
pollingMethod.setName(method.getName() + ToolConstants.ASYNC_METHOD_SUFFIX);
pollingMethod.setStyle(method.getStyle());
pollingMethod.setWrapperStyle(method.isWrapperStyle());
pollingMethod.setSoapAction(method.getSoapAction());
pollingMethod.setOperationName(method.getOperationName());
boolean convertOutToAsync = !method.isWrapperStyle() && "void".equals(method.getReturn().getClassName());
String asyncCname = null;
for (JavaParameter param : method.getParameters()) {
if (convertOutToAsync) {
if (param.isHolder()) {
if (param.isINOUT()) {
JavaParameter p2 = new JavaParameter();
p2.setName(param.getName());
p2.setClassName(param.getHolderName());
p2.setStyle(JavaType.Style.IN);
pollingMethod.addParameter(p2);
for (String s : param.getAnnotationTags()) {
JAnnotation ann = param.getAnnotation(s);
p2.addAnnotation(s, ann);
}
} else if (!param.isHeader() && asyncCname == null) {
asyncCname = param.getClassName();
}
} else {
pollingMethod.addParameter(param);
}
} else {
pollingMethod.addParameter(param);
}
}
JavaReturn response = new JavaReturn();
response.setClassName(getAsyncClassName(method, "Response", asyncCname));
pollingMethod.setReturn(response);
// REVISIT: test the operation name in the annotation
pollingMethod.annotate(new WebMethodAnnotator());
pollingMethod.addAnnotation("RequestWrapper", method.getAnnotationMap().get("RequestWrapper"));
pollingMethod.addAnnotation("ResponseWrapper", method.getAnnotationMap().get("ResponseWrapper"));
pollingMethod.addAnnotation("SOAPBinding", method.getAnnotationMap().get("SOAPBinding"));
method.getInterface().addMethod(pollingMethod);
}
Aggregations