Skip to content

Commit

Permalink
TEIIDDES-2359 added check for response type to auto-set JSON ACCEPT v…
Browse files Browse the repository at this point in the history
…alue

 * added exception check and message dialog for case where JSON response type is defined in CP for an XML file.
  • Loading branch information
blafond committed Oct 2, 2014
1 parent 8fb88ae commit ef9ef5b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ TeiidMetadataImportSourcePage.selectedXmlFile=Selected Data File:
TeiidMetadataImportSourcePage.selectedRestFile=Selected Response File:
TeiidMetadataImportSourcePage.location=Location:
TeiidMetadataImportSourcePage.browse=...
TeiidMetadataImportSourcePage.name=Name:
TeiidMetadataImportSourcePage.name=Name:fIn
TeiidMetadataImportSourcePage.modelStatus=Model Status
TeiidMetadataImportSourcePage.sourceModelUndefined=No source model is defined
TeiidMetadataImportSourcePage.sourceModelWillBeCreated= NEW MODEL: Source model [ {0} ] does not exist.\nModel with required {1} procedure will be created on FINISH.
Expand Down Expand Up @@ -883,6 +883,10 @@ TeiidMetadataImportSourcePage.selectSourceModelMessage=Select source model and c
TeiidMetadataImportSourcePage.invalidXmlConnectionProfileMessage=The selected connection profile does not contain a valid or current reference to an existing XML file.\n\n\
Edit the connection profile to enter valid info or select another valid profile to continue.
TeiidMetadataImportSourcePage.invalidXmlConnectionProfileTitle=Invalid XML Connection Profile
TeiidMetadataImportSourcePage.invalidRESTConnectionProfileMessage=The selected connection profile does not contain a valid or current reference to an existing REST service.\n\n\
Edit the connection profile to enter valid info or select another valid profile to continue.
TeiidMetadataImportSourcePage.invalidRESTConnectionProfileTitle=Invalid REST Connection Profile
TeiidMetadataImportSourcePage.invalidRESTResponseTypeMessage=The return type for the connection profile is {0}. An invalid response was returned.
TeiidMetadataImportSourcePage.malformedUrlErrorTitle=Malformed URL Error
TeiidMetadataImportSourcePage.malformedUrlErrorMessage=Error building URL:
TeiidMetadataImportSourcePage.protocolErrorTitle=Protocol Error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public class TeiidRestImportSourcePage extends AbstractWizardPage implements
private static String getString(final String id) {
return Util.getString(I18N_PREFIX + id);
}

private static String getString(final String id, String arg) {
return Util.getString(I18N_PREFIX + id, arg);
}


private ILabelProvider srcLabelProvider;
private Combo srcCombo;
Expand Down Expand Up @@ -689,8 +694,8 @@ private void loadFileListViewer() {
} else {
fileViewer.setInput(null);
MessageDialog.openError(this.getShell(),
getString("invalidXmlConnectionProfileTitle"), //$NON-NLS-1$
getString("invalidXmlConnectionProfileMessage")); //$NON-NLS-1$
getString("invalidRESTConnectionProfileTitle"), //$NON-NLS-1$
getString("invalidRESTConnectionProfileMessage")); //$NON-NLS-1$
}
}
}
Expand Down Expand Up @@ -732,6 +737,11 @@ private File getXmlFileFromRestUrl(IConnectionProfile profile) {
this.parameterMap = (Map) props
.get(IWSProfileConstants.PARAMETER_MAP);
}

String responseType = IWSProfileConstants.XML;
if( props.get(IWSProfileConstants.RESPONSE_TYPE_PROPERTY_KEY) != null) {
responseType = (String)props.get(IWSProfileConstants.RESPONSE_TYPE_PROPERTY_KEY);
}

try {

Expand Down Expand Up @@ -759,9 +769,15 @@ private File getXmlFileFromRestUrl(IConnectionProfile profile) {
IWSProfileConstants.ACCEPT_PROPERTY_KEY, (String) props
.get(IWSProfileConstants.ACCEPT_PROPERTY_KEY));
} else {
httpConn.setRequestProperty(
IWSProfileConstants.ACCEPT_PROPERTY_KEY,
IWSProfileConstants.ACCEPT_DEFAULT_VALUE);
if( responseType.equalsIgnoreCase(IWSProfileConstants.JSON) ) {
httpConn.setRequestProperty(
IWSProfileConstants.ACCEPT_PROPERTY_KEY,
IWSProfileConstants.CONTENT_TYPE_JSON_VALUE);
} else {
httpConn.setRequestProperty(
IWSProfileConstants.ACCEPT_PROPERTY_KEY,
IWSProfileConstants.ACCEPT_DEFAULT_VALUE);
}
}

if (props.get(IWSProfileConstants.CONTENT_TYPE_PROPERTY_KEY) != null) {
Expand Down Expand Up @@ -834,8 +850,15 @@ private File getXmlFileFromRestUrl(IConnectionProfile profile) {
MessageDialog.openError(this.getShell(), getString("ioErrorTitle"), //$NON-NLS-1$
getString("ioErrorMessage") + ex.getMessage()); //$NON-NLS-1$
} catch (Exception ex) {
// TODO Auto-generated catch block
ex.printStackTrace();
if( ex instanceof JSONException && ex.getMessage().contains("A JSONObject text must begin with") ) {

String message = getString("invalidRESTResponseTypeMessage", responseType);
MessageDialog.openError(this.getShell(),
getString("invalidRESTConnectionProfileTitle"), //$NON-NLS-1$
message); //$NON-NLS-1$
} else {
ex.printStackTrace();
}
} finally {
try {
if (fos != null) {
Expand Down

0 comments on commit ef9ef5b

Please sign in to comment.