Index: src/org/teiid/designer/runtime/ui/GenerateRestWarAction.java =================================================================== --- src/org/teiid/designer/runtime/ui/GenerateRestWarAction.java (revision 2030) +++ src/org/teiid/designer/runtime/ui/GenerateRestWarAction.java (working copy) @@ -47,7 +47,7 @@ import com.metamatrix.modeler.ui.actions.ISelectionAction; import com.metamatrix.ui.internal.eventsupport.SelectionUtilities; -public class GenerateRestWarAction extends Action implements ISelectionListener, Comparable, ISelectionAction { +public class GenerateRestWarAction extends Action implements ISelectionListener, Comparable, ISelectionAction { protected static final String I18N_PREFIX = I18nUtil.getPropertyPrefix(GenerateRestWarAction.class); protected static final String VDB_EXTENSION = "vdb"; //$NON-NLS-1$ @@ -62,6 +62,7 @@ boolean contextIsLocal = false; public GenerateRestWarAction() { + restfulProcedureMap = new HashMap>(); this.setText(DqpUiConstants.UTIL.getString(I18N_PREFIX + "text")); //$NON-NLS-1$ this.setToolTipText(DqpUiConstants.UTIL.getString(I18N_PREFIX + "tooltip")); //$NON-NLS-1$ this.setImageDescriptor(DqpUiPlugin.getDefault().getImageDescriptor(DqpUiConstants.Images.CREATE_WAR)); @@ -155,7 +156,8 @@ public void selectionChanged( IWorkbenchPart part, ISelection selection ) { boolean enable = false; - List restfulProcedureArray = null; + List restfulProcedureArray = new ArrayList(); + restfulProcedureMap = new HashMap>(); if (!SelectionUtilities.isMultiSelection(selection)) { Object obj = SelectionUtilities.getSelectedObject(selection); // If a VDB is selected and it contains a web service model then @@ -169,7 +171,6 @@ for (VdbModelEntry vdbModelEntry : modelEntrySet) { final ModelResource modelResource = ModelerCore.getModelWorkspace().findModelResource(vdbModelEntry.getName()); if (ModelIdentifier.isVirtualModelType(modelResource)) { - restfulProcedureArray = new ArrayList(); String modelName = FileUtils.getFilenameWithoutExtension(vdbModelEntry.getName().lastSegment()); Collection eObjectList = null; try { @@ -194,6 +195,8 @@ if (restfulProcedureArray.size() > 0) { restfulProcedureMap.put(modelName, restfulProcedureArray); + restfulProcedureArray = new ArrayList(); + enable = true; } } catch (ModelWorkspaceException e) { @@ -202,10 +205,6 @@ throw new RuntimeException(e); } - if (restfulProcedureArray.size() > 0) { - enable = true; - } - } } @@ -223,7 +222,7 @@ private void createRestProcedureCollection( EObject eObject, String name, String fullName, - List restfulProcedureArray ) throws ModelerCoreException { + List restfulProcedureArray ) throws ModelerCoreException { Object restMethod; Object uri; boolean hasReturn = false; @@ -257,7 +256,8 @@ } } } else { - // The procedure is not eligible for REST exposure with a URI defined + // The procedure is not eligible for REST exposure with a URI + // defined return; } @@ -274,11 +274,15 @@ jsonRestProcedure.setRestMethod(restProcedure.getRestMethod()); jsonRestProcedure.setUri(restProcedure.getUri()); - // If the parameterCount is greater than the number of parameters passed + // If the parameterCount is greater than the number of parameters + // passed // on the URI, we can expect more parameters via an input stream - // so the consumes annotation will need to be set. We will set for XML and JSON methods. + // so the consumes annotation will need to be set. We will set for + // XML and JSON methods. + boolean hasInputStream = false; if (uriParameterCount < parameterCount) { + hasInputStream = true; restProcedure.setConsumesAnnotation("@Consumes( MediaType.APPLICATION_XML )"); //$NON-NLS-1$ jsonRestProcedure.setConsumesAnnotation("@Consumes( MediaType.APPLICATION_JSON )"); //$NON-NLS-1$ } @@ -289,7 +293,12 @@ } restfulProcedureArray.add(restProcedure); - restfulProcedureArray.add(jsonRestProcedure); + + // Only add JSON operation if there is a return or InputStream. Otherwise, one method will do. + if (hasReturn || hasInputStream) { + restfulProcedureArray.add(jsonRestProcedure); + } + } } } Index: src/org/teiid/designer/dqp/webservice/war/RestWebArchiveBuilderImpl.java =================================================================== --- src/org/teiid/designer/dqp/webservice/war/RestWebArchiveBuilderImpl.java (revision 2030) +++ src/org/teiid/designer/dqp/webservice/war/RestWebArchiveBuilderImpl.java (working copy) @@ -24,6 +24,9 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import javax.tools.Diagnostic; +import javax.tools.Diagnostic.Kind; +import javax.tools.DiagnosticCollector; import javax.tools.JavaCompiler; import javax.tools.JavaCompiler.CompilationTask; import javax.tools.JavaFileObject; @@ -409,11 +412,12 @@ * * @param webInfClassesDirectory * @param properties + * @throws Exception * @since 7.4 */ protected void createResourceJavaClasses( File webInfLibDirectory, File webInfClassesDirectory, - Properties properties ) throws IOException { + Properties properties ) throws Exception { String pathToResource = "/org" + File.separator + "teiid" + File.separator + "rest" + File.separator + "services"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ String pathToPlugin = "/org" + File.separator + "teiid" + File.separator + "rest"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ @@ -483,8 +487,17 @@ sourceFileList.add(teiidRestApplication); Iterable compilationUnits = fileManager.getJavaFileObjectsFromFiles(sourceFileList); - CompilationTask task = compilerTool.getTask(null, fileManager, null, null, null, compilationUnits); + /*Create a diagnostic controller, which holds the compilation problems*/ + DiagnosticCollector diagnostics = new DiagnosticCollector(); + CompilationTask task = compilerTool.getTask(null, fileManager, diagnostics, null, null, compilationUnits); task.call(); + List> diagnosticList = diagnostics.getDiagnostics(); + for (Diagnostic diagnostic : diagnosticList) { + diagnostic.getKind(); + if (diagnostic.getKind().equals(Kind.ERROR)) { + throw new Exception(diagnostic.getMessage(null)); + } + } fileManager.close(); Boolean includeJars = (Boolean)properties.get(WebArchiveBuilderConstants.PROPERTY_INCLUDE_RESTEASY_JARS); @@ -508,10 +521,10 @@ RestProcedure restProcedure = procedureIter.next(); if (restProcedure.getProducesAnnotation() != null - && restProcedure.getProducesAnnotation().contains("MediaType.APPLICATION_XML")) { //$NON-NLS-1$ - createXMLMethod(sb, restProcedure); - } else { + && restProcedure.getProducesAnnotation().contains("MediaType.APPLICATION_JSON")) { //$NON-NLS-1$ createJSONMethod(sb, restProcedure); + } else { + createXMLMethod(sb, restProcedure); } }