use of org.apache.cxf.tools.common.model.JavaException in project cxf by apache.
the class WSActionAnnotator method annotate.
public void annotate(JavaAnnotatable ja) {
JavaMethod method;
if (ja instanceof JavaMethod) {
method = (JavaMethod) ja;
} else {
throw new RuntimeException("Action can only annotate JavaMethod");
}
boolean required = false;
JavaInterface intf = method.getInterface();
MessageInfo inputMessage = operation.getInput();
MessageInfo outputMessage = operation.getOutput();
JAnnotation actionAnnotation = new JAnnotation(Action.class);
if (inputMessage.getExtensionAttributes() != null) {
String inputAction = getAction(inputMessage);
if (inputAction != null) {
actionAnnotation.addElement(new JAnnotationElement("input", inputAction));
required = true;
}
}
if (outputMessage != null && outputMessage.getExtensionAttributes() != null) {
String outputAction = getAction(outputMessage);
if (outputAction != null) {
actionAnnotation.addElement(new JAnnotationElement("output", outputAction));
required = true;
}
}
if (operation.hasFaults()) {
List<JAnnotation> faultAnnotations = new ArrayList<>();
for (FaultInfo faultInfo : operation.getFaults()) {
if (faultInfo.getExtensionAttributes() != null) {
String faultAction = getAction(faultInfo);
if (faultAction == null) {
continue;
}
JavaException exceptionClass = getExceptionClass(method, faultInfo);
if (!StringUtils.isEmpty(exceptionClass.getPackageName()) && !exceptionClass.getPackageName().equals(intf.getPackageName())) {
intf.addImport(exceptionClass.getClassName());
}
JAnnotation faultAnnotation = new JAnnotation(FaultAction.class);
faultAnnotation.addElement(new JAnnotationElement("className", exceptionClass));
faultAnnotation.addElement(new JAnnotationElement("value", faultAction));
faultAnnotations.add(faultAnnotation);
required = true;
}
}
actionAnnotation.addElement(new JAnnotationElement("fault", faultAnnotations));
}
if (required) {
method.addAnnotation("Action", actionAnnotation);
}
}
use of org.apache.cxf.tools.common.model.JavaException in project cxf by apache.
the class JAXWSFrontEndProcessor method serviceInfo2JavaInf.
public JavaInterface serviceInfo2JavaInf(ServiceInfo service) {
JavaInterface javaInf = new JavaInterface();
InterfaceInfo inf = service.getInterface();
for (OperationInfo op : inf.getOperations()) {
JavaMethod jm = new JavaMethod();
Method m = (Method) op.getProperty(ReflectionServiceFactoryBean.METHOD);
jm.setName(m.getName());
int i = 0;
for (Type type : m.getGenericParameterTypes()) {
JavaParameter jp = new JavaParameter();
jp.setClassName(getClassName(type));
jp.setStyle(Style.IN);
jp.setName("arg" + i++);
jm.addParameter(jp);
}
for (Type type : m.getGenericExceptionTypes()) {
JavaException jex = new JavaException();
String className = getClassName(type);
jex.setClassName(className);
jex.setName(className);
jm.addException(jex);
}
JavaReturn jreturn = new JavaReturn();
jreturn.setClassName(getClassName(m.getGenericReturnType()));
jreturn.setStyle(Style.OUT);
jm.setReturn(jreturn);
String pkg = PackageUtils.getPackageName(m.getDeclaringClass());
javaInf.setPackageName(pkg.length() > 0 ? pkg : ToolConstants.DEFAULT_PACKAGE_NAME);
javaInf.addMethod(jm);
javaInf.setName(inf.getName().getLocalPart());
jm.getParameterList();
}
return javaInf;
}
use of org.apache.cxf.tools.common.model.JavaException in project cxf by apache.
the class JavaFirstUtil method serviceInfo2JavaInf.
public static JavaInterface serviceInfo2JavaInf(ServiceInfo service) {
JavaInterface javaInf = new JavaInterface();
InterfaceInfo inf = service.getInterface();
for (OperationInfo op : inf.getOperations()) {
JavaMethod jm = new JavaMethod();
Method m = (Method) op.getProperty(ReflectionServiceFactoryBean.METHOD);
jm.setName(m.getName());
int i = 0;
for (Type type : m.getGenericParameterTypes()) {
JavaParameter jp = new JavaParameter();
jp.setClassName(getClassName(type));
jp.setStyle(Style.IN);
jp.setName("arg" + i++);
jm.addParameter(jp);
}
for (Type type : m.getGenericExceptionTypes()) {
JavaException jex = new JavaException();
String className = getClassName(type);
jex.setClassName(className);
jex.setName(className);
jm.addException(jex);
}
JavaReturn jreturn = new JavaReturn();
jreturn.setClassName(getClassName(m.getGenericReturnType()));
jreturn.setStyle(Style.OUT);
jm.setReturn(jreturn);
String pkg = PackageUtils.getPackageName(m.getDeclaringClass());
javaInf.setPackageName(pkg.length() == 0 ? ToolConstants.DEFAULT_PACKAGE_NAME : pkg);
javaInf.addMethod(jm);
javaInf.setName(inf.getName().getLocalPart());
jm.getParameterList();
}
return javaInf;
}
use of org.apache.cxf.tools.common.model.JavaException in project cxf by apache.
the class JAXWSContainerTest method testSuppressCodeGen.
@Test
public void testSuppressCodeGen() {
try {
JAXWSContainer container = new JAXWSContainer(null);
ToolContext context = new ToolContext();
// Do not generate any artifacts, we just want the code model.
context.put(ToolConstants.CFG_SUPPRESS_GEN, "suppress");
// Where to put the generated source code
context.put(ToolConstants.CFG_OUTPUTDIR, output.getCanonicalPath());
context.put(ToolConstants.CFG_WSDLURL, getLocation("/wsdl2java_wsdl/hello_world.wsdl"));
// Delegate jaxb to generate the type classes
context.put(DataBindingProfile.class, PluginLoader.getInstance().getDataBindingProfile("jaxb"));
context.put(FrontEndProfile.class, PluginLoader.getInstance().getFrontEndProfile("jaxws"));
container.setContext(context);
// Now shoot
container.execute();
// At this point you should be able to get the
// SEI/Service(Client stub)/Exception classes/Types classes
assertNotNull(output.list());
assertEquals(0, output.list().length);
// Now you can get the JavaModel from the context.
Map<QName, JavaModel> map = CastUtils.cast((Map<?, ?>) context.get(WSDLToJavaProcessor.MODEL_MAP));
JavaModel javaModel = map.get(new QName("http://cxf.apache.org/w2j/hello_world_soap_http", "SOAPService"));
assertNotNull(javaModel);
Map<String, JavaInterface> interfaces = javaModel.getInterfaces();
assertEquals(1, interfaces.size());
JavaInterface intf = interfaces.values().iterator().next();
String interfaceName = intf.getName();
assertEquals("Greeter", interfaceName);
assertEquals("http://cxf.apache.org/w2j/hello_world_soap_http", intf.getNamespace());
assertEquals("org.apache.cxf.w2j.hello_world_soap_http", intf.getPackageName());
List<JavaMethod> methods = intf.getMethods();
assertEquals(6, methods.size());
Boolean methodSame = false;
JavaMethod m1 = null;
for (JavaMethod m2 : methods) {
if ("testDocLitFault".equals(m2.getName())) {
methodSame = true;
m1 = m2;
break;
}
}
assertTrue(methodSame);
assertNotNull(m1);
assertEquals(2, m1.getExceptions().size());
List<String> names = new ArrayList<>();
for (JavaException exc : m1.getExceptions()) {
names.add(exc.getName());
}
assertTrue("BadRecordLitFault", names.contains("BadRecordLitFault"));
assertTrue("NoSuchCodeLitFault", names.contains("NoSuchCodeLitFault"));
String address = null;
for (JavaServiceClass service : javaModel.getServiceClasses().values()) {
if ("SOAPService_Test1".equals(service.getName())) {
continue;
}
List<JavaPort> ports = service.getPorts();
for (JavaPort port : ports) {
if (interfaceName.equals(port.getPortType())) {
address = port.getBindingAdress();
break;
}
}
if (!"".equals(address)) {
break;
}
}
assertEquals("http://localhost:9000/SoapContext/SoapPort", address);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.cxf.tools.common.model.JavaException in project cxf by apache.
the class WSActionAnnotator method getExceptionClass.
private JavaException getExceptionClass(JavaMethod method, FaultInfo faultInfo) {
for (JavaException exception : method.getExceptions()) {
QName faultName = faultInfo.getName();
// Perform a case insensitive "startsWith" check that works for different locales
String prefix = faultName.getLocalPart();
if (exception.getTargetNamespace().equals(faultName.getNamespaceURI()) && exception.getName().regionMatches(true, 0, prefix, 0, prefix.length())) {
return exception;
}
}
return null;
}
Aggregations