Compare commits
244 Commits
patch/TPS-
...
TESB-25671
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c911d5677 | ||
|
|
9f2241d8b6 | ||
|
|
fc0c54b7a4 | ||
|
|
2a4d457539 | ||
|
|
d34b53d93b | ||
|
|
61f412cbf7 | ||
|
|
cf0df8515f | ||
|
|
f8b2cbcbd2 | ||
|
|
bb41056c26 | ||
|
|
2fa6fa6042 | ||
|
|
b7c1385c89 | ||
|
|
80f246ea5c | ||
|
|
71a68d4554 | ||
|
|
aac5d2f428 | ||
|
|
1874473f00 | ||
|
|
c5c8697911 | ||
|
|
9312e207c8 | ||
|
|
2cbb343d01 | ||
|
|
7aa164b753 | ||
|
|
a76dc7b029 | ||
|
|
1e8bb0243f | ||
|
|
bfdc3d8c94 | ||
|
|
f7cbeabea2 | ||
|
|
4512ee5e5b | ||
|
|
413f98e6f3 | ||
|
|
3acb1e663e | ||
|
|
0689190571 | ||
|
|
cfc16c23c2 | ||
|
|
5b69be1aaf | ||
|
|
1ebadeeb5e | ||
|
|
f3b8cf6f50 | ||
|
|
1542e7bb2b | ||
|
|
d539ef6965 | ||
|
|
3c55505275 | ||
|
|
02e4d71489 | ||
|
|
928f980a63 | ||
|
|
f546409acb | ||
|
|
31d35c048c | ||
|
|
ef708a8348 | ||
|
|
3909cadc0b | ||
|
|
1292ddfa8b | ||
|
|
0c5e483893 | ||
|
|
f0b64d92c5 | ||
|
|
910b4d80d9 | ||
|
|
50771134b2 | ||
|
|
e79dbfc65a | ||
|
|
a50648cc5c | ||
|
|
0141a2021d | ||
|
|
b8c37376ea | ||
|
|
7c153538f9 | ||
|
|
da645d3ef4 | ||
|
|
264c9bda35 | ||
|
|
bcd9620908 | ||
|
|
bb377c59f2 | ||
|
|
ec0162809c | ||
|
|
32a0fa4f21 | ||
|
|
480d80db93 | ||
|
|
5d074a1787 | ||
|
|
84eea35c62 | ||
|
|
79fe200121 | ||
|
|
8e9614b94d | ||
|
|
396696ed31 | ||
|
|
195932029b | ||
|
|
7f77637515 | ||
|
|
f4ae68641f | ||
|
|
0a49c27be6 | ||
|
|
9711b099f9 | ||
|
|
8840aa1f78 | ||
|
|
9093da5300 | ||
|
|
7c99ec2246 | ||
|
|
a8285120c7 | ||
|
|
de666438af | ||
|
|
8189d3d0f9 | ||
|
|
4bde039bff | ||
|
|
9b030dfc71 | ||
|
|
59f6d682da | ||
|
|
54c6014e47 | ||
|
|
40654c88e4 | ||
|
|
df6a748a15 | ||
|
|
7e4a8d13ea | ||
|
|
70540b48e9 | ||
|
|
ce6691a31b | ||
|
|
2106f0dd3b | ||
|
|
9d4816bc69 | ||
|
|
649b3a812c | ||
|
|
fd97d3b4e7 | ||
|
|
1568163ff8 | ||
|
|
9dba659c3c | ||
|
|
9355e5b4a6 | ||
|
|
0c0b4d0317 | ||
|
|
a90a9434a8 | ||
|
|
b8bf58f282 | ||
|
|
29159385b5 | ||
|
|
3c522e7b15 | ||
|
|
17fd958ce5 | ||
|
|
2307f13545 | ||
|
|
f9e7590713 | ||
|
|
275fab14f8 | ||
|
|
143742acd7 | ||
|
|
3c52b631e9 | ||
|
|
c534373738 | ||
|
|
338297f3ab | ||
|
|
0bb9dc7670 | ||
|
|
b3433def41 | ||
|
|
776437eaf4 | ||
|
|
372c3bf77a | ||
|
|
4913c935d5 | ||
|
|
03b45217a8 | ||
|
|
3e80011d86 | ||
|
|
ca3610c9cb | ||
|
|
4d39844c21 | ||
|
|
d7b6c014dd | ||
|
|
30288171b7 | ||
|
|
7b40eddb53 | ||
|
|
f05b633e0e | ||
|
|
23aba4a3c4 | ||
|
|
c47bedbc88 | ||
|
|
531d9d042b | ||
|
|
3e5bafd2c6 | ||
|
|
d10e0a7776 | ||
|
|
fed318cea2 | ||
|
|
b42c990006 | ||
|
|
99b32aef61 | ||
|
|
1aff5b8292 | ||
|
|
aa502fbbda | ||
|
|
bb6eaa5c43 | ||
|
|
c3f90750df | ||
|
|
89402325e7 | ||
|
|
a6c3a11e54 | ||
|
|
f96f3171d1 | ||
|
|
76b1eb7da6 | ||
|
|
894ca53e5a | ||
|
|
4bc344bec5 | ||
|
|
69a9e3ca83 | ||
|
|
896bed8875 | ||
|
|
bd3301dc51 | ||
|
|
c71b2f994f | ||
|
|
04be41abf8 | ||
|
|
4b99b199cc | ||
|
|
48882724ac | ||
|
|
7b05a057b0 | ||
|
|
437df1c3c5 | ||
|
|
0742691497 | ||
|
|
99951891e9 | ||
|
|
7e3c8888e1 | ||
|
|
5745ce1d28 | ||
|
|
c23955d51f | ||
|
|
77aa27ccac | ||
|
|
e0310bfb60 | ||
|
|
0f323ab700 | ||
|
|
718a5d005e | ||
|
|
8fa59aefe9 | ||
|
|
a5f43e31e6 | ||
|
|
18fc81a240 | ||
|
|
68836af2d3 | ||
|
|
2538b24196 | ||
|
|
7255747144 | ||
|
|
f0bc81e9b6 | ||
|
|
d553d5ed06 | ||
|
|
f5b2456c9f | ||
|
|
7f045834e5 | ||
|
|
899eab4a2b | ||
|
|
d2d3a37b41 | ||
|
|
c42ccb1fe4 | ||
|
|
d66773ec0d | ||
|
|
ce310ab73f | ||
|
|
9e88f2c2c8 | ||
|
|
3c1664b5a6 | ||
|
|
31beed6bc8 | ||
|
|
b0fa04eba8 | ||
|
|
a67fd68b79 | ||
|
|
0415268aeb | ||
|
|
c2f52f2acc | ||
|
|
654e035974 | ||
|
|
37adcec242 | ||
|
|
b6323e92b5 | ||
|
|
e973624d17 | ||
|
|
732f041e0e | ||
|
|
d2b24287ef | ||
|
|
67b1f5f63e | ||
|
|
2ed16b7e8e | ||
|
|
b499d3432b | ||
|
|
bc66eff728 | ||
|
|
3539b4ce03 | ||
|
|
47082201e6 | ||
|
|
8632fd8cb3 | ||
|
|
a576d88ecd | ||
|
|
a4c9e0b7ee | ||
|
|
84e6601675 | ||
|
|
3282e07d77 | ||
|
|
673ed49d61 | ||
|
|
b5121333e4 | ||
|
|
6d73503d7d | ||
|
|
a7f05381d1 | ||
|
|
2c523cf75f | ||
|
|
41dfae7065 | ||
|
|
0d3439647a | ||
|
|
19a7dc5c6f | ||
|
|
5ba502c85d | ||
|
|
28f3145a94 | ||
|
|
23631b71ab | ||
|
|
323bd8c2d7 | ||
|
|
dec408bd00 | ||
|
|
66f40e1d02 | ||
|
|
5b5c190f6e | ||
|
|
3f830d830a | ||
|
|
fc678c7832 | ||
|
|
f396775201 | ||
|
|
1687d192ee | ||
|
|
29c562ae21 | ||
|
|
d782ae46fd | ||
|
|
3f6dad3d68 | ||
|
|
5f1bd9f2fc | ||
|
|
0f52288bd5 | ||
|
|
b01d49b3e7 | ||
|
|
0bed1c0407 | ||
|
|
8b3e95d6e1 | ||
|
|
5efb343458 | ||
|
|
2ab9f54921 | ||
|
|
1938554f29 | ||
|
|
047d082732 | ||
|
|
eb210a4c93 | ||
|
|
40689d795e | ||
|
|
cad81587f8 | ||
|
|
8eb4634665 | ||
|
|
e59ef61c8b | ||
|
|
bd1b2a8f02 | ||
|
|
b9ef91fac4 | ||
|
|
e82ad8e940 | ||
|
|
d8d9c02fdb | ||
|
|
386811a6d3 | ||
|
|
b8937d6a08 | ||
|
|
03e376ad7c | ||
|
|
28a1f3ab34 | ||
|
|
32d96b1acc | ||
|
|
1c31954b3b | ||
|
|
80f556e553 | ||
|
|
656d74e935 | ||
|
|
13d4c5c726 | ||
|
|
76c3d773f0 | ||
|
|
7e0dc01878 | ||
|
|
5b3cba8fb0 | ||
|
|
6e7a5a26c8 | ||
|
|
dc279e7a39 |
@@ -4,4 +4,5 @@ Huge thanks to these people who contributed in making Talend product better:
|
||||
- [jlolling](https://github.com/jlolling) (Jan -and Miss- Lolling)
|
||||
- [kirkalicious](https://github.com/kirkalicious) (Kirk Tarou)
|
||||
- [mrizzato](https://github.com/mrizzato) (Massimiliano Rizzato)
|
||||
- [brazabr](https://github.com/brazabr) (Thiago Benvenuto)
|
||||
- [brazabr](https://github.com/brazabr) (Thiago Benvenuto)
|
||||
- [phoflack](https://jira.talendforge.org/secure/ViewProfile.jspa?name=phoflack) (Philip Hoflack)
|
||||
@@ -10,7 +10,8 @@
|
||||
<import plugin="javax.wsdl" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="joda-time" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.eclipse.help.ui" version="0.0.0" match="greaterOrEqual"/>
|
||||
</requires>
|
||||
<import plugin="jaxb-api" version="0.0.0" match="greaterOrEqual"/>
|
||||
</requires>
|
||||
<plugin id="org.talend.components.api" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<plugin id="org.talend.components.api.service.osgi" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
<plugin id="org.talend.components.azurestorage" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
<copyright url="http://www.example.com/copyright">[Enter Copyright Description here.]</copyright>
|
||||
<license url="http://www.example.com/license">[Enter License Description here.]</license>
|
||||
<requires>
|
||||
<import feature="org.eclipse.nebula.widgets.nattable.extension.glazedlists.feature" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import feature="org.talend.libraries.jdbc.feature" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.beanutils" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.httpclient" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.logging" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.apache.commons.logging" version="1.2.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.eclipse.nebula.widgets.nattable.core" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.eclipse.nebula.widgets.nattable.extension.glazedlists" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.eclipse.nebula.widgets.tablecombo" version="0.0.0" match="greaterOrEqual"/>
|
||||
<import plugin="org.w3c.css.sac" version="0.0.0" match="greaterOrEqual"/>
|
||||
</requires>
|
||||
@@ -44,7 +44,6 @@
|
||||
<plugin id="org.talend.libraries.jxplorer" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin download-size="0" install-size="0" version="0.0.0" unpack="false" id="org.talend.libraries.mdm"/>
|
||||
<plugin id="org.talend.libraries.mondrian" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.nattable" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.netsuite" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.palo" download-size="0" install-size="0" version="0.0.0"/>
|
||||
<plugin id="org.talend.libraries.persist.lookup" download-size="0" install-size="0" version="0.0.0" unpack="false"/>
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.talend.commons.ui.gmf.util.DisplayUtils;
|
||||
import org.talend.core.model.process.AbstractNode;
|
||||
import org.talend.core.model.process.EConnectionType;
|
||||
import org.talend.core.model.process.IConnection;
|
||||
@@ -92,7 +93,7 @@ public class AlfrescoOutputManager {
|
||||
try {
|
||||
modelManager.load(); // NB. or when modelManager is created
|
||||
} catch (AlfrescoOutputException aoex) {
|
||||
MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL),
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(false),
|
||||
Messages.getString("AlfrescoOutputManager.failedLoadModel"), aoex.getMessage()); //$NON-NLS-1$
|
||||
modelManager.clear();
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Combo;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
@@ -42,6 +41,7 @@ import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.TableItem;
|
||||
import org.talend.commons.ui.gmf.util.DisplayUtils;
|
||||
import org.talend.commons.ui.runtime.image.ImageUtils.ICON_SIZE;
|
||||
import org.talend.core.model.components.IComponent;
|
||||
import org.talend.core.ui.images.CoreImageProvider;
|
||||
@@ -248,7 +248,7 @@ public class AlfrescoModelDialog extends Dialog {
|
||||
try {
|
||||
modelManager.addModel(AlfrescoModelDialog.this.chosenModelFilePath);
|
||||
} catch (AlfrescoOutputException aoex) {
|
||||
MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(false), Messages
|
||||
.getString("AlfrescoModelDialog.addModelFailed"), aoex.getMessage()); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
@@ -267,7 +267,7 @@ public class AlfrescoModelDialog extends Dialog {
|
||||
try {
|
||||
modelManager.removeModel(selectedItem);
|
||||
} catch (AlfrescoOutputException aoex) {
|
||||
MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(false), Messages
|
||||
.getString("AlfrescoModelDialog.removeModelFailed"), aoex.getMessage()); //$NON-NLS-1$
|
||||
return;
|
||||
}
|
||||
@@ -303,14 +303,14 @@ public class AlfrescoModelDialog extends Dialog {
|
||||
List<String> missingTypeNames = modelManager.getMetadataManager().getMissingTypeNames();
|
||||
List<String> missingAspectNames = modelManager.getMetadataManager().getMissingAspectNames();
|
||||
if (!missingTypeNames.isEmpty()) {
|
||||
MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(false), Messages
|
||||
.getString("AlfrescoModelDialog.missingTypeDefinitions.title"), Messages.getString( //$NON-NLS-1$
|
||||
"AlfrescoModelDialog.missingTypeDefinitions.msg", missingTypeNames)); //$NON-NLS-1$
|
||||
}
|
||||
if (!missingAspectNames.isEmpty()) {
|
||||
MessageDialog.openError(new Shell(Display.getCurrent(), SWT.APPLICATION_MODAL), Messages
|
||||
.getString("AlfrescoModelDialog.missingAspectDefinitions.title"), Messages.getString( //$NON-NLS-1$
|
||||
"AlfrescoModelDialog.missingAspectDefinitions.msg", missingAspectNames)); //$NON-NLS-1$
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(false),
|
||||
Messages.getString("AlfrescoModelDialog.missingAspectDefinitions.title"), Messages.getString( //$NON-NLS-1$
|
||||
"AlfrescoModelDialog.missingAspectDefinitions.msg", missingAspectNames)); //$NON-NLS-1$
|
||||
}
|
||||
// NB. model is only saved on closing the dialog with OK
|
||||
}
|
||||
|
||||
@@ -36,5 +36,7 @@ Require-Bundle: org.eclipse.ui.ide,
|
||||
com.ibm.icu,
|
||||
org.talend.libraries.apache,
|
||||
org.talend.repository.items.importexport,
|
||||
org.talend.repository.view.di
|
||||
org.talend.repository.view.di,
|
||||
org.talend.commons.runtime,
|
||||
org.talend.core.runtime
|
||||
Eclipse-LazyStart: true
|
||||
|
||||
@@ -10,7 +10,6 @@ import org.eclipse.jface.viewers.StructuredViewer;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IPerspectiveDescriptor;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
@@ -18,6 +17,7 @@ import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.WorkbenchException;
|
||||
import org.eclipse.ui.intro.IIntroSite;
|
||||
import org.eclipse.ui.intro.config.IIntroAction;
|
||||
import org.talend.commons.ui.gmf.util.DisplayUtils;
|
||||
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
|
||||
import org.talend.commons.ui.runtime.image.ECoreImage;
|
||||
import org.talend.commons.ui.runtime.image.ImageProvider;
|
||||
@@ -67,7 +67,7 @@ public class CreateDiagramAction extends AContextualAction implements IIntroActi
|
||||
SimpleBusinessCreationWizard wizard = new SimpleBusinessCreationWizard(getActivePage().getWorkbenchWindow()
|
||||
.getWorkbench(), getPath());
|
||||
|
||||
WizardDialog wizardDialog = new WizardDialog(new Shell(), wizard);
|
||||
WizardDialog wizardDialog = new WizardDialog(DisplayUtils.getDefaultShell(false), wizard);
|
||||
wizardDialog.create();
|
||||
wizardDialog.open();
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ Require-Bundle: org.talend.core.repository,
|
||||
org.eclipse.ui.workbench,
|
||||
org.apache.log4j,
|
||||
org.talend.components.api,
|
||||
org.talend.designer.core.generic,
|
||||
org.talend.daikon
|
||||
org.talend.daikon,
|
||||
org.talend.designer.core.generic
|
||||
Eclipse-LazyStart: true
|
||||
Bundle-ClassPath: .
|
||||
Export-Package: org.talend.designer.codegen,
|
||||
|
||||
@@ -336,10 +336,10 @@
|
||||
String instance_<%=testData%>=null;
|
||||
<%
|
||||
if(ProcessUtils.isSpark(process)){
|
||||
String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("line.separator"));
|
||||
String lineSeparator = "\r\n";
|
||||
String fileContentEnCodeStr = "";
|
||||
try {
|
||||
fileContentEnCodeStr = (new sun.misc.BASE64Encoder()).encode(path.getBytes("UTF-8"));
|
||||
fileContentEnCodeStr = java.util.Base64.getMimeEncoder().encodeToString(path.getBytes("UTF-8"));
|
||||
} catch (java.io.UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -351,7 +351,7 @@
|
||||
String testDataValue = result.toString();
|
||||
%>
|
||||
try {
|
||||
instance_<%=testData%> = new String((new sun.misc.BASE64Decoder()).decodeBuffer("<%=testDataValue%>"), utf8Charset);
|
||||
instance_<%=testData%> = new String(java.util.Base64.getMimeDecoder().decode("<%=testDataValue%>"), utf8Charset);
|
||||
} catch (java.lang.Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -506,11 +506,14 @@
|
||||
if (inContext == null) {
|
||||
inContext = <%=className%>.class.getClassLoader().getResourceAsStream("config/contexts/" + contextStr + ".properties");
|
||||
}
|
||||
if (inContext != null && context != null && context.isEmpty()) {
|
||||
if (inContext != null) {
|
||||
//defaultProps is in order to keep the original context value
|
||||
defaultProps.load(inContext);
|
||||
if(context != null && context.isEmpty()) {
|
||||
defaultProps.load(inContext);
|
||||
context = new ContextProperties(defaultProps);
|
||||
}
|
||||
|
||||
inContext.close();
|
||||
context = new ContextProperties(defaultProps);
|
||||
} else if (!isDefaultContext) {
|
||||
//print info and job continue to run, for case: context_param is not empty.
|
||||
System.err.println("Could not find the context " + contextStr);
|
||||
@@ -1161,8 +1164,12 @@ if (execStat) {
|
||||
if(conn_<%=hbaseComponent.getUniqueName()%> != null )
|
||||
{
|
||||
<%
|
||||
if((isCustom && isHadoop2) || (!isCustom && hbaseDistrib.doSupportNewHBaseAPI())) {%>
|
||||
org.apache.hadoop.hbase.client.HConnection hConnection_<%=hbaseComponent.getUniqueName() %> = org.apache.hadoop.hbase.client.HConnectionManager.getConnection(conn_<%=hbaseComponent.getUniqueName() %>);
|
||||
if((isCustom && isHadoop2) || (!isCustom && hbaseDistrib.doSupportNewHBaseAPI())) {
|
||||
if (!hbaseDistrib.doSupportHBase2x()) {%>
|
||||
org.apache.hadoop.hbase.client.HConnection hConnection_<%=hbaseComponent.getUniqueName() %> = org.apache.hadoop.hbase.client.HConnectionManager.getConnection(conn_<%=hbaseComponent.getUniqueName() %>);
|
||||
<% } else {%>
|
||||
org.apache.hadoop.hbase.client.Connection hConnection_<%=hbaseComponent.getUniqueName() %> = org.apache.hadoop.hbase.client.ConnectionFactory.createConnection(conn_<%=hbaseComponent.getUniqueName() %>);
|
||||
<% }%>
|
||||
if ((hConnection_<%=hbaseComponent.getUniqueName() %> != null) && (!hConnection_<%=hbaseComponent.getUniqueName() %>.isClosed())) {
|
||||
hConnection_<%=hbaseComponent.getUniqueName() %>.close();
|
||||
}
|
||||
|
||||
@@ -512,6 +512,8 @@ private class TalendException extends Exception {
|
||||
|
||||
if(!(e instanceof TDieException)){
|
||||
<%
|
||||
boolean needCatchTalendException = false;
|
||||
|
||||
if (process.getNodesOfType("tLogCatcher").size() > 0) {
|
||||
List<INode> logCatchers = (List<INode>)process.getNodesOfType("tLogCatcher");
|
||||
for (INode logCatcher : logCatchers) {
|
||||
@@ -543,6 +545,7 @@ private class TalendException extends Exception {
|
||||
if (ElementParameterParser.getValue(logCatcher, "__CATCH_JAVA_EXCEPTION__").equals("true")) {
|
||||
if(logCatcher!=virtualNCatchNode){
|
||||
// 2) launch logCatcher subProcess
|
||||
needCatchTalendException = true;
|
||||
%>
|
||||
<%=logCatcher.getDesignSubjobStartNode().getUniqueName() %>Process(globalMap);
|
||||
<%
|
||||
@@ -555,6 +558,7 @@ private class TalendException extends Exception {
|
||||
<%
|
||||
}
|
||||
if(virtualNCatchNode!=null){
|
||||
needCatchTalendException = true;
|
||||
%>
|
||||
<%=virtualNCatchNode.getDesignSubjobStartNode().getUniqueName() %>Process(globalMap);
|
||||
<%
|
||||
@@ -568,31 +572,12 @@ private class TalendException extends Exception {
|
||||
%>
|
||||
}
|
||||
<%
|
||||
boolean needCatchTalendException = false;
|
||||
if (process.getNodesOfType("tLogCatcher").size() > 0) {
|
||||
for(INode node:process.getNodesOfType("tLogCatcher")){
|
||||
if(ElementParameterParser.getValue(node, "__CATCH_JAVA_EXCEPTION__").equals("true")){
|
||||
needCatchTalendException = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((!needCatchTalendException) && (process.getNodesOfType("tAssertCatcher").size() > 0)) {
|
||||
for(INode node:process.getNodesOfType("tAssertCatcher")){
|
||||
if(ElementParameterParser.getValue(node, "__CATCH_JAVA_EXCEPTION__").equals("true")){
|
||||
needCatchTalendException = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(needCatchTalendException) {
|
||||
if (process.getNodesOfType("tLogCatcher").size() > 0) {
|
||||
%>
|
||||
} catch (TalendException e) {
|
||||
// do nothing
|
||||
<%
|
||||
}
|
||||
//TODO should catch the TalendException in assertcatcher process? but before should not work too as use java reflect, this exception can't catch
|
||||
%>
|
||||
} catch (TalendException e) {
|
||||
// do nothing
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -48,6 +48,7 @@ ComponentsFactory.componentNotFound=Component folder not found\:
|
||||
ComponentsFactory.load.components=Load Components...
|
||||
ComponentsFactory.parentNotRecompiled=Warning\: parents of *.inc.javajet are not recompiled \!
|
||||
ComponentsFactory.loadComponents.missingFolder=The folder "{0}" is missing in the plugin "{1}".
|
||||
ComponentsFactory.init.waitForFinish.timeout=Can't initialise ComponentsFactory, please try again.
|
||||
ComponentsLocalProviderService.componentLoadError=Component load error
|
||||
ComponentsLocalProviderService.talendExchangeError=Talend Exchange Error
|
||||
ComponentsPreferencePage.ButtonLabel0=Ok
|
||||
|
||||
@@ -30,6 +30,11 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Level;
|
||||
@@ -139,66 +144,119 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
private static boolean cleanDone = false;
|
||||
|
||||
protected static Map<String, Map<String, Set<IComponent>>> componentNameMap;
|
||||
|
||||
private AtomicBoolean isInitialising;
|
||||
|
||||
private volatile Lock initialiseLock;
|
||||
|
||||
public ComponentsFactory() {
|
||||
isInitialising = new AtomicBoolean(false);
|
||||
initialiseLock = new ReentrantLock();
|
||||
}
|
||||
|
||||
private void init(boolean duringLogon) {
|
||||
removeOldComponentsUserFolder(); // not used anymore
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
// TimeMeasure.display = true;
|
||||
// TimeMeasure.displaySteps = true;
|
||||
// TimeMeasure.measureActive = true;
|
||||
// TimeMeasure.begin("initComponents");
|
||||
componentList = Collections.synchronizedSet(new HashSet<IComponent>());
|
||||
customComponentList = new HashSet<IComponent>();
|
||||
skeletonList = new ArrayList<String>();
|
||||
userComponentList = new HashSet<IComponent>();
|
||||
String installLocation = new Path(Platform.getConfigurationLocation().getURL().getPath()).toFile().getAbsolutePath();
|
||||
componentToProviderMap = new HashMap<IComponent, AbstractComponentsProvider>();
|
||||
boolean isNeedClean = !cleanDone && TalendCacheUtils.isSetCleanComponentCache();
|
||||
cleanDone = true; // only check this parameter one time, or it will reinitialize things all the time...
|
||||
isCreated = hasComponentFile(installLocation) && !isNeedClean;
|
||||
ComponentsCache cache = ComponentManager.getComponentCache();
|
||||
try {
|
||||
if (isCreated) {
|
||||
// if cache is created and empty, means we never loaded it before.
|
||||
// if it was already loaded, then no need to go again, since it's a static variable, it's still in
|
||||
// memory.
|
||||
// it avoids to reload from disk again even more for commandline at each logon, since it's no use.
|
||||
if (cache.getComponentEntryMap().isEmpty()) {
|
||||
ComponentsCache loadCache = loadComponentResource(installLocation);
|
||||
cache.getComponentEntryMap().putAll(loadCache.getComponentEntryMap());
|
||||
}
|
||||
} else {
|
||||
cache.getComponentEntryMap().clear();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ExceptionHandler.process(e);
|
||||
cache.getComponentEntryMap().clear();
|
||||
isCreated = false;
|
||||
if (wait4InitialiseFinish()) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
try {
|
||||
initialiseLock.lock();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
isInitialising.set(true);
|
||||
removeOldComponentsUserFolder(); // not used anymore
|
||||
long startTime = System.currentTimeMillis();
|
||||
|
||||
loadComponentsFromComponentsProviderExtension();
|
||||
// TimeMeasure.display = true;
|
||||
// TimeMeasure.displaySteps = true;
|
||||
// TimeMeasure.measureActive = true;
|
||||
// TimeMeasure.begin("initComponents");
|
||||
componentList = Collections.synchronizedSet(new HashSet<IComponent>());
|
||||
customComponentList = new HashSet<IComponent>();
|
||||
skeletonList = new ArrayList<String>();
|
||||
userComponentList = new HashSet<IComponent>();
|
||||
String installLocation = new Path(Platform.getConfigurationLocation().getURL().getPath()).toFile().getAbsolutePath();
|
||||
componentToProviderMap = new HashMap<IComponent, AbstractComponentsProvider>();
|
||||
boolean isNeedClean = !cleanDone && TalendCacheUtils.isSetCleanComponentCache();
|
||||
cleanDone = true; // only check this parameter one time, or it will reinitialize things all the time...
|
||||
isCreated = hasComponentFile(installLocation) && !isNeedClean;
|
||||
ComponentsCache cache = ComponentManager.getComponentCache();
|
||||
try {
|
||||
if (isCreated) {
|
||||
// if cache is created and empty, means we never loaded it before.
|
||||
// if it was already loaded, then no need to go again, since it's a static variable, it's still in
|
||||
// memory.
|
||||
// it avoids to reload from disk again even more for commandline at each logon, since it's no use.
|
||||
if (cache.getComponentEntryMap().isEmpty()) {
|
||||
ComponentsCache loadCache = loadComponentResource(installLocation);
|
||||
cache.getComponentEntryMap().putAll(loadCache.getComponentEntryMap());
|
||||
}
|
||||
} else {
|
||||
cache.getComponentEntryMap().clear();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
ExceptionHandler.process(e);
|
||||
cache.getComponentEntryMap().clear();
|
||||
isCreated = false;
|
||||
}
|
||||
|
||||
// TimeMeasure.step("initComponents", "loadComponentsFromProvider");
|
||||
// 2.Load Component from extension point: component_definition
|
||||
loadComponentsFromExtensions();
|
||||
// TimeMeasure.step("initComponents", "loadComponentsFromExtension[joblets?]");
|
||||
loadComponentsFromComponentsProviderExtension();
|
||||
|
||||
ComponentManager.saveResource(); // will save only if needed.
|
||||
// TimeMeasure.step("initComponents", "loadComponentsFromProvider");
|
||||
// 2.Load Component from extension point: component_definition
|
||||
loadComponentsFromExtensions();
|
||||
// TimeMeasure.step("initComponents", "loadComponentsFromExtension[joblets?]");
|
||||
|
||||
// init component name map, used to pick specified component immediately
|
||||
initComponentNameMap();
|
||||
ComponentManager.saveResource(); // will save only if needed.
|
||||
|
||||
// TimeMeasure.step("initComponents", "createCache");
|
||||
log.debug(componentList.size() + " components loaded in " + (System.currentTimeMillis() - startTime) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
// init component name map, used to pick specified component immediately
|
||||
initComponentNameMap();
|
||||
|
||||
// TimeMeasure.end("initComponents");
|
||||
// TimeMeasure.display = false;
|
||||
// TimeMeasure.displaySteps = false;
|
||||
// TimeMeasure.measureActive = false;
|
||||
// TimeMeasure.step("initComponents", "createCache");
|
||||
log.debug(componentList.size() + " components loaded in " + (System.currentTimeMillis() - startTime) + " ms"); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
|
||||
// TimeMeasure.end("initComponents");
|
||||
// TimeMeasure.display = false;
|
||||
// TimeMeasure.displaySteps = false;
|
||||
// TimeMeasure.measureActive = false;
|
||||
} finally {
|
||||
isInitialising.set(false);
|
||||
initialiseLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wait4InitialiseFinish() {
|
||||
if (isInitialising.get()) {
|
||||
try {
|
||||
// wait for 10 min (10 * 60 seconds) by default
|
||||
long timeout = 600L;
|
||||
String timeoutStr = System.getProperty("studio.componentsFactory.init.timeout"); //$NON-NLS-1$
|
||||
if (!StringUtils.isBlank(timeoutStr)) {
|
||||
try {
|
||||
timeout = Long.valueOf(timeoutStr);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
if (initialiseLock.tryLock(timeout, TimeUnit.SECONDS)) {
|
||||
initialiseLock.unlock();
|
||||
} else {
|
||||
// may be track in dead lock, throw exception to try to break dead lock
|
||||
throw new RuntimeException(Messages.getString("ComponentsFactory.init.waitForFinish.timeout")); //$NON-NLS-1$
|
||||
}
|
||||
// initialise successfully or not
|
||||
return !isInitialising.get();
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
// initialise failed, still need to initialise
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void initComponentNameMap() {
|
||||
@@ -729,7 +787,8 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized int size() {
|
||||
public int size() {
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -737,7 +796,8 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized IComponent get(String name) {
|
||||
public IComponent get(String name) {
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -757,7 +817,8 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
* @see org.talend.core.model.components.IComponentsFactory#get(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public synchronized IComponent get(String name, String paletteType) {
|
||||
public IComponent get(String name, String paletteType) {
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -772,6 +833,7 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
|
||||
@Override
|
||||
public IComponent getJobletComponent(String name, String paletteType) {
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -799,6 +861,7 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
@Override
|
||||
public void initializeComponents(IProgressMonitor monitor) {
|
||||
this.monitor = monitor;
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -809,6 +872,7 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
@Override
|
||||
public void initializeComponents(IProgressMonitor monitor, boolean duringLogon) {
|
||||
this.monitor = monitor;
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(duringLogon);
|
||||
}
|
||||
@@ -822,12 +886,18 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
* @see org.talend.core.model.components.IComponentsFactory#getComponents()
|
||||
*/
|
||||
@Override
|
||||
public synchronized Set<IComponent> getComponents() {
|
||||
public Set<IComponent> getComponents() {
|
||||
wait4InitialiseFinish();
|
||||
if (componentList == null) {
|
||||
init(false);
|
||||
}
|
||||
return componentList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInitialising() {
|
||||
return isInitialising.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<IComponent> readComponents() {
|
||||
@@ -840,7 +910,8 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Map<String, Map<String, Set<IComponent>>> getComponentNameMap() {
|
||||
public Map<String, Map<String, Set<IComponent>>> getComponentNameMap() {
|
||||
wait4InitialiseFinish();
|
||||
if (componentNameMap == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -848,7 +919,8 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<IComponent> getCustomComponents() {
|
||||
public List<IComponent> getCustomComponents() {
|
||||
wait4InitialiseFinish();
|
||||
if (customComponentList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -862,6 +934,7 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
*/
|
||||
@Override
|
||||
public List<String> getSkeletons() {
|
||||
wait4InitialiseFinish();
|
||||
if (skeletonList == null) {
|
||||
init(false);
|
||||
}
|
||||
@@ -900,6 +973,7 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
jobletService.clearSparkStreamingJobletComponent();
|
||||
}
|
||||
}
|
||||
isInitialising.set(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -16,6 +16,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
import org.talend.commons.utils.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -393,7 +394,12 @@ public class JetBean {
|
||||
}
|
||||
|
||||
public String getFullTemplatePath() {
|
||||
return Platform.getPlugin(getJetPluginRepository()).getDescriptor().getInstallURL().toString() + getTemplateRelativeUri();
|
||||
try {
|
||||
return TemplateUtil.getPlatformUrlOfBundle(getJetPluginRepository()) + getTemplateRelativeUri();
|
||||
} catch (Throwable e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getGenerationError() {
|
||||
|
||||
@@ -21,7 +21,9 @@ import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.emf.codegen.jet.JETCompiler;
|
||||
import org.eclipse.emf.codegen.jet.JETException;
|
||||
import org.eclipse.emf.codegen.jet.JETMark;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.osgi.framework.Bundle;
|
||||
import org.talend.commons.exception.ExceptionHandler;
|
||||
|
||||
/**
|
||||
* ggu class global comment. Detailled comment
|
||||
@@ -76,6 +78,24 @@ public class TalendJETCompiler extends JETCompiler {
|
||||
if (newFileURI != null) {
|
||||
newAttributes.put(fileKey, newFileURI);
|
||||
}
|
||||
try {
|
||||
String filePath = newAttributes.get(fileKey);
|
||||
if (filePath != null && start != null && start.getFile() != null) {
|
||||
URI uri = URI.createURI(filePath);
|
||||
if (uri.isRelative() && uri.hasRelativePath()) {
|
||||
String basePath = start.getFile();
|
||||
String resolvedLocation = "";
|
||||
int index = basePath.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
resolvedLocation = basePath.substring(0, index + 1);
|
||||
}
|
||||
resolvedLocation = resolve(resolvedLocation, uri.toString());
|
||||
newAttributes.put(fileKey, resolvedLocation);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
} else if (directive.equals("jet")) { //$NON-NLS-1$
|
||||
String skeletonKey = "skeleton"; //$NON-NLS-1$
|
||||
String skeletonURI = newAttributes.get(skeletonKey);
|
||||
@@ -85,28 +105,79 @@ public class TalendJETCompiler extends JETCompiler {
|
||||
newAttributes.put(skeletonKey, newSkeletonURI);
|
||||
}
|
||||
}
|
||||
try {
|
||||
String filePath = newAttributes.get(skeletonKey);
|
||||
if (filePath != null && start != null && start.getFile() != null) {
|
||||
URI uri = URI.createURI(filePath);
|
||||
if (uri.isRelative() && uri.hasRelativePath()) {
|
||||
String basePath = start.getFile();
|
||||
String resolvedLocation = "";
|
||||
int index = basePath.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
resolvedLocation = basePath.substring(0, index + 1);
|
||||
}
|
||||
resolvedLocation = resolve(resolvedLocation, uri.toString());
|
||||
newAttributes.put(skeletonKey, resolvedLocation);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
}
|
||||
super.handleDirective(directive, start, stop, newAttributes);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private String checkAndReplace(String fileURI) {
|
||||
if (fileURI != null) {
|
||||
Matcher matcher = PLUGIN_VAR_PATTERN.matcher(fileURI);
|
||||
if (matcher.find()) {
|
||||
// get the plugin name from fileURI
|
||||
String refPluginName = matcher.group(1);
|
||||
// retrieve the plugin URI by pluginName.
|
||||
Bundle refBundle = Platform.getBundle(refPluginName);
|
||||
if (refBundle != null) {
|
||||
String realURI = Platform.getPlugin(refPluginName).getDescriptor().getInstallURL().toString();
|
||||
// replace the old fileURI to new one by pluginURI
|
||||
String newFileURI = fileURI.replaceFirst(PLUGIN_VAR_PATTERN.pattern(), realURI);
|
||||
return newFileURI;
|
||||
try {
|
||||
if (fileURI != null) {
|
||||
Matcher matcher = PLUGIN_VAR_PATTERN.matcher(fileURI);
|
||||
if (matcher.find()) {
|
||||
// get the plugin name from fileURI
|
||||
String refPluginName = matcher.group(1);
|
||||
// retrieve the plugin URI by pluginName.
|
||||
Bundle refBundle = Platform.getBundle(refPluginName);
|
||||
if (refBundle != null) {
|
||||
String realURI = TemplateUtil.getPlatformUrlOfBundle(refPluginName);
|
||||
// replace the old fileURI to new one by pluginURI
|
||||
String newFileURI = fileURI.replaceFirst(PLUGIN_VAR_PATTERN.pattern(), realURI);
|
||||
return newFileURI;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
ExceptionHandler.process(e);
|
||||
}
|
||||
return null; // not replace
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link JETCompiler#resolve(String, String)} has bug of resolving relative path when upgrading eclipse4.10, try to
|
||||
* override it
|
||||
*
|
||||
* @param base
|
||||
* @param relativePath
|
||||
* @return
|
||||
*/
|
||||
private static String resolve(String base, String relativePath) {
|
||||
while (relativePath.startsWith("./")) {
|
||||
relativePath = relativePath.substring(2);
|
||||
}
|
||||
|
||||
while (relativePath.startsWith("../")) {
|
||||
int index = base.lastIndexOf('/', base.length() - 2);
|
||||
if (index == -1) {
|
||||
base = "";
|
||||
relativePath = relativePath.substring(3);
|
||||
break;
|
||||
} else {
|
||||
base = base.substring(0, index) + "/";
|
||||
relativePath = relativePath.substring(3);
|
||||
}
|
||||
}
|
||||
|
||||
return base + relativePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
// ============================================================================
|
||||
package org.talend.designer.codegen.config;
|
||||
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.osgi.framework.Bundle;
|
||||
|
||||
/**
|
||||
* CodeGenerator Templates Ressources Utils.
|
||||
*
|
||||
@@ -150,5 +153,18 @@ public class TemplateUtil {
|
||||
public EInternalTemplate getType() {
|
||||
return this.template;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Replacement of Platform.getPlugin(bundleName).getDescriptor().getInstallURL().toString()
|
||||
*
|
||||
* @param bundleName
|
||||
* @return
|
||||
*/
|
||||
public static String getPlatformUrlOfBundle(String bundleName) {
|
||||
Bundle bundle = Platform.getBundle(bundleName);
|
||||
if (bundle == null) {
|
||||
return null;
|
||||
}
|
||||
return "platform:/plugin/" + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + "/";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
@@ -347,7 +346,8 @@ public class DownloadComponenentsAction extends Action implements IIntroAction {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
MessageDialog.openError(new Shell(), Messages.getString("DownloadComponenentsAction_failureTitle"), //$NON-NLS-1$
|
||||
MessageDialog.openError(DisplayUtils.getDefaultShell(false),
|
||||
Messages.getString("DownloadComponenentsAction_failureTitle"), //$NON-NLS-1$
|
||||
Messages.getString("DownloadComponenentsAction_failureMessage", extension.getLabel())); //$NON-NLS-1$
|
||||
}
|
||||
});
|
||||
|
||||
@@ -25,7 +25,6 @@ import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import jdk.internal.org.objectweb.asm.TypeReference;
|
||||
|
||||
import org.apache.axis.components.net.TransportClientProperties;
|
||||
import org.apache.axis.components.net.TransportClientPropertiesFactory;
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>TalendSAX</artifactId>
|
||||
<version>1.0.1-20190326</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>talend_open</id>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>talend_open_snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-zl.talend.com/nexus/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-zl.talend.com/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>talend-update</id>
|
||||
<url>https://talend-update.talend.com/nexus/content/repositories/libraries/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -43,14 +43,20 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
// node paths special which tab will be read as the row value
|
||||
private String[] nodePaths;
|
||||
|
||||
private final String LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
|
||||
|
||||
private final String EXTERNAL_GENERAL_ENTITIES = "http://xml.org/sax/features/external-general-entities";
|
||||
|
||||
private final String EXTERNAL_PARAMETER_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
|
||||
|
||||
// add to support node.asXML()
|
||||
private boolean[] asXMLs;
|
||||
|
||||
private LoopEntry entry;
|
||||
|
||||
private SAXLoopCompositeHandler result;
|
||||
|
||||
private boolean ignoreDTD=false;
|
||||
|
||||
private boolean ignoreDTD = false;
|
||||
|
||||
/**
|
||||
* DOC xzhang SAXLooper constructor comment.
|
||||
@@ -140,21 +146,14 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
Reader reader = null;
|
||||
try {
|
||||
DefaultHandler hd = null;
|
||||
SAXParser saxParser = null;
|
||||
if(!ignoreDTD) { //orginal code
|
||||
saxParser = SAXParserFactory.newInstance().newSAXParser();
|
||||
} else {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
saxParser = spf.newSAXParser();
|
||||
}
|
||||
SAXParser saxParser = createSaxParser();
|
||||
if (rootPath == null || rootPath.equals("")) {
|
||||
hd = newHandler();
|
||||
} else {
|
||||
hd = newHandler2();
|
||||
}
|
||||
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
|
||||
reader = new UnicodeReader(new java.io.FileInputStream(fileURL),this.charset);
|
||||
reader = new UnicodeReader(new java.io.FileInputStream(fileURL), this.charset);
|
||||
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
|
||||
saxParser.parse(inSource, hd);
|
||||
|
||||
@@ -165,10 +164,10 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if(reader!=null) {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -185,7 +184,7 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
Reader reader = null;
|
||||
try {
|
||||
DefaultHandler hd = null;
|
||||
SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
|
||||
SAXParser saxParser = createSaxParser();
|
||||
if (rootPath == null || rootPath.equals("")) {
|
||||
hd = newHandler();
|
||||
} else {
|
||||
@@ -193,7 +192,7 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
}
|
||||
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", hd);
|
||||
// routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
|
||||
reader = new UnicodeReader(is,this.charset);
|
||||
reader = new UnicodeReader(is, this.charset);
|
||||
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
|
||||
saxParser.parse(inSource, hd);
|
||||
|
||||
@@ -204,16 +203,34 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if(reader!=null) {
|
||||
if (reader != null) {
|
||||
try {
|
||||
reader.close();
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Sax parser and set required security features to it
|
||||
*
|
||||
* @return sax parser with required security features set
|
||||
* @throws ParserConfigurationException
|
||||
* @throws SAXException
|
||||
*/
|
||||
private SAXParser createSaxParser() throws ParserConfigurationException, SAXException {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
|
||||
if (ignoreDTD) {
|
||||
spf.setFeature(LOAD_EXTERNAL_DTD, false);
|
||||
spf.setFeature(EXTERNAL_GENERAL_ENTITIES, false);
|
||||
spf.setFeature(EXTERNAL_PARAMETER_ENTITIES, false);
|
||||
}
|
||||
return spf.newSAXParser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get result iterator. This must be call after the parse method.
|
||||
*
|
||||
@@ -292,7 +309,7 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
String column = nodePaths[m];
|
||||
String resultCol = this.loopPath;
|
||||
boolean isAsXML = this.asXMLs[m];
|
||||
boolean isDot = false;//fix for TDI-19435
|
||||
boolean isDot = false;// fix for TDI-19435
|
||||
String tmpLoopPath = null;
|
||||
String[] splits = column.split("/");
|
||||
for (String tmp : splits) {
|
||||
@@ -451,7 +468,7 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
tmpentry.setOriginalLoopPath(this.arrOrigLoopPath[i]);
|
||||
// =======================bug7632 end=============================
|
||||
|
||||
}// for(int i=0;i<length;i++)
|
||||
} // for(int i=0;i<length;i++)
|
||||
|
||||
}
|
||||
|
||||
@@ -485,12 +502,13 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
long timeStart = System.currentTimeMillis();
|
||||
|
||||
String file = "./src/org/talend/xml/sax/in.xml";
|
||||
String[] query = new String[] { "cust-vendor-num", "cust-vendor-num" + "/@xsi:nil", "cust", "cust" + "/@xsi:nil" };
|
||||
String[] query =
|
||||
new String[] { "cust-vendor-num", "cust-vendor-num" + "/@xsi:nil", "cust", "cust" + "/@xsi:nil" };
|
||||
boolean[] asXMLs = new boolean[] { true, false, true, false };
|
||||
String loopPath = "/orderdata/order/header";
|
||||
|
||||
ComplexSAXLooper looper = new ComplexSAXLooper(loopPath, query, asXMLs);
|
||||
looper.parse(file,"UTF-8");
|
||||
looper.parse(file, "UTF-8");
|
||||
|
||||
java.util.Iterator<java.util.Map<String, String>> iter = looper.iterator();
|
||||
|
||||
@@ -518,9 +536,9 @@ public class ComplexSAXLooper implements ISAXLooper {
|
||||
}
|
||||
}
|
||||
|
||||
public void setIgnoreDTD(boolean ignoreDTD) {
|
||||
|
||||
this.ignoreDTD=ignoreDTD;
|
||||
|
||||
}
|
||||
public void setIgnoreDTD(boolean ignoreDTD) {
|
||||
|
||||
this.ignoreDTD = ignoreDTD;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.FutureTask;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
@@ -28,38 +29,45 @@ import org.talend.xml.sax.commons.ISAXLooper;
|
||||
import org.talend.xml.sax.io.UnicodeReader;
|
||||
import org.talend.xml.sax.simpleparser.model.XMLNode;
|
||||
import org.talend.xml.sax.simpleparser.model.XMLNodes;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
/**
|
||||
* DOC Administrator class global comment. Detailled comment
|
||||
*/
|
||||
public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
public class SimpleSAXLooper implements ISAXLooper, Callable {
|
||||
|
||||
private XMLNodes nodes = new XMLNodes();
|
||||
|
||||
private DataBufferCache bcache;
|
||||
|
||||
|
||||
private DataBufferCache2 multiCache;
|
||||
|
||||
private Thread task;
|
||||
|
||||
|
||||
private FutureTask futureTask;
|
||||
|
||||
|
||||
private boolean ignoreDTD = false;
|
||||
|
||||
|
||||
SimpleSAXLoopHandler hd = null;
|
||||
|
||||
|
||||
private String[] arrOrigLoopPath;
|
||||
|
||||
private String rootPath;
|
||||
|
||||
private String[] arrLoopPath;
|
||||
|
||||
|
||||
private final String LOAD_EXTERNAL_DTD = "http://apache.org/xml/features/nonvalidating/load-external-dtd";
|
||||
|
||||
private final String EXTERNAL_GENERAL_ENTITIES = "http://xml.org/sax/features/external-general-entities";
|
||||
|
||||
private final String EXTERNAL_PARAMETER_ENTITIES = "http://xml.org/sax/features/external-parameter-entities";
|
||||
|
||||
private List<XMLNodes> nodesList = new ArrayList<XMLNodes>();
|
||||
|
||||
|
||||
public SimpleSAXLooper(String loopPath, String[] nodePaths, boolean[] asXMLs) {
|
||||
futureTask = new FutureTask(this);
|
||||
task = new Thread(futureTask);
|
||||
futureTask = new FutureTask(this);
|
||||
task = new Thread(futureTask);
|
||||
for (int i = 0; i < nodePaths.length; i++) {
|
||||
nodes.addNode(new XMLNode(loopPath, nodePaths[i], null, asXMLs[i]));
|
||||
}
|
||||
@@ -69,7 +77,7 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
public SimpleSAXLooper(String rootPath, String[] arrLoopPath, String[][] arrNodePaths) {
|
||||
futureTask = new FutureTask(this);
|
||||
task = new Thread(futureTask);
|
||||
|
||||
|
||||
this.arrOrigLoopPath = arrLoopPath;
|
||||
|
||||
String tmpRootPath = rootPath;
|
||||
@@ -80,19 +88,19 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
this.rootPath = tmpRootPath;
|
||||
|
||||
this.arrLoopPath = getLoopPaths(arrLoopPath);
|
||||
|
||||
for(int j = 0;j<arrNodePaths.length;j++) {
|
||||
|
||||
for (int j = 0; j < arrNodePaths.length; j++) {
|
||||
String[] nodePaths = arrNodePaths[j];
|
||||
XMLNodes ns = new XMLNodes();
|
||||
for (int i = 0; i < nodePaths.length; i++) {
|
||||
ns.addNode(new XMLNode(this.arrOrigLoopPath[j], this.arrLoopPath[j],nodePaths[i], null));
|
||||
ns.addNode(new XMLNode(this.arrOrigLoopPath[j], this.arrLoopPath[j], nodePaths[i], null));
|
||||
}
|
||||
nodesList.add(ns);
|
||||
}
|
||||
|
||||
|
||||
initLoopEntries();
|
||||
}
|
||||
|
||||
|
||||
private String[] getLoopPaths(String[] arrLoops) {
|
||||
|
||||
String[] loopPaths = new String[arrLoops.length];
|
||||
@@ -115,14 +123,16 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
|
||||
return loopPaths;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* handle the exception in task.
|
||||
* FutureTask.get() is a block method waiting for the Task over and it can throw the exception in Task(Callable,Thread,Runnable)
|
||||
* FutureTask.get() is a block method waiting for the Task over and it can throw the exception in
|
||||
* Task(Callable,Thread,Runnable)
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void handleException() throws Exception {
|
||||
futureTask.get();
|
||||
futureTask.get();
|
||||
}
|
||||
|
||||
private void initLoopEntry() {
|
||||
@@ -149,11 +159,11 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
}
|
||||
|
||||
private void initLoopEntries() {
|
||||
|
||||
|
||||
multiCache = DataBufferCache2.getInstance();
|
||||
|
||||
for(XMLNodes ns : nodesList) {
|
||||
|
||||
|
||||
for (XMLNodes ns : nodesList) {
|
||||
|
||||
for (XMLNode node : ns.getNodes().values()) {
|
||||
String column = node.originPath;
|
||||
String resultCol = node.loopPath;
|
||||
@@ -168,10 +178,10 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
resultCol += "/" + tmp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
node.nodePath = resultCol;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,59 +209,60 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
this.charset = charset;
|
||||
task.start();
|
||||
}
|
||||
|
||||
|
||||
public Object call() throws Exception {
|
||||
Reader reader = null;
|
||||
try {
|
||||
DefaultHandler handler = null;
|
||||
if(nodesList.size() > 0) {
|
||||
SAXLoopCompositeHandler chd = new SAXLoopCompositeHandler();
|
||||
for(int i=0;i<nodesList.size();i++) {
|
||||
try {
|
||||
DefaultHandler handler = null;
|
||||
if (nodesList.size() > 0) {
|
||||
SAXLoopCompositeHandler chd = new SAXLoopCompositeHandler();
|
||||
for (int i = 0; i < nodesList.size(); i++) {
|
||||
XMLNodes ns = nodesList.get(i);
|
||||
chd.register(new SimpleSAXLoopHandler(ns, multiCache));
|
||||
}
|
||||
handler = chd;
|
||||
} else {
|
||||
hd = new SimpleSAXLoopHandler(nodes, bcache);
|
||||
handler = hd;
|
||||
}
|
||||
|
||||
SAXParser saxParser = null;
|
||||
if(!ignoreDTD) { //orginal code
|
||||
saxParser = SAXParserFactory.newInstance().newSAXParser();
|
||||
} else {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||
saxParser = spf.newSAXParser();
|
||||
hd = new SimpleSAXLoopHandler(nodes, bcache);
|
||||
handler = hd;
|
||||
}
|
||||
|
||||
SAXParser saxParser = null;
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
|
||||
if (ignoreDTD) { // orginal code
|
||||
spf.setFeature(LOAD_EXTERNAL_DTD, false);
|
||||
spf.setFeature(EXTERNAL_GENERAL_ENTITIES, false);
|
||||
spf.setFeature(EXTERNAL_PARAMETER_ENTITIES, false);
|
||||
}
|
||||
saxParser = spf.newSAXParser();
|
||||
saxParser.setProperty("http://xml.org/sax/properties/lexical-handler", handler);
|
||||
if (fileURL != null) {
|
||||
// routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
|
||||
reader = new UnicodeReader(new java.io.FileInputStream(fileURL),this.charset);
|
||||
// routines.system.UnicodeReader.java is used to ignore the BOM of the source file.
|
||||
reader = new UnicodeReader(new java.io.FileInputStream(fileURL), this.charset);
|
||||
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
|
||||
saxParser.parse(inSource, handler);
|
||||
} else {
|
||||
reader = new UnicodeReader(is,this.charset);
|
||||
reader = new UnicodeReader(is, this.charset);
|
||||
org.xml.sax.InputSource inSource = new org.xml.sax.InputSource(reader);
|
||||
saxParser.parse(inSource, handler);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
if(reader!=null) {
|
||||
if (reader != null) {
|
||||
reader.close();
|
||||
}
|
||||
} finally {
|
||||
if(multiCache!=null) {
|
||||
if (multiCache != null) {
|
||||
multiCache.notifyErrorOccurred();
|
||||
}
|
||||
if(bcache!=null) {
|
||||
if (bcache != null) {
|
||||
bcache.notifyErrorOccurred();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
@@ -263,7 +274,8 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
|
||||
String file = "C:/Documents and Settings/Administrator/桌é<C592>¢/in.xml";
|
||||
// String file = "D:/test/outMain.xml";
|
||||
String[] query = new String[] { "cust-vendor-num", "cust-vendor-num" + "/@xsi:nil", "cust", "cust" + "/@xsi:nil" };
|
||||
String[] query =
|
||||
new String[] { "cust-vendor-num", "cust-vendor-num" + "/@xsi:nil", "cust", "cust" + "/@xsi:nil" };
|
||||
boolean[] asXMLs = new boolean[] { false, false, false, false };
|
||||
String loopPath = "/orderdata/order/header";
|
||||
|
||||
@@ -310,14 +322,14 @@ public class SimpleSAXLooper implements ISAXLooper,Callable {
|
||||
return new SimpleSAXMultiLoopIterator(multiCache);
|
||||
}
|
||||
|
||||
public void setIgnoreDTD(boolean ignoreDTD) {
|
||||
|
||||
this.ignoreDTD=ignoreDTD;
|
||||
|
||||
}
|
||||
public void setIgnoreDTD(boolean ignoreDTD) {
|
||||
|
||||
this.ignoreDTD = ignoreDTD;
|
||||
|
||||
}
|
||||
|
||||
public void stopRead() {
|
||||
if(hd != null) {
|
||||
if (hd != null) {
|
||||
hd.stopRead();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>commons-net-ftps-proxy</artifactId>
|
||||
<version>3.6.1-talend-20190128</version>
|
||||
|
||||
<name>commons-net-talend</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-net</groupId>
|
||||
<artifactId>commons-net</artifactId>
|
||||
<version>3.6</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
<snapshots><enabled>true</enabled></snapshots>
|
||||
<releases><enabled>false</enabled></releases>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
<snapshots><enabled>false</enabled></snapshots>
|
||||
<releases><enabled>true</enabled></releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,309 @@
|
||||
package org.talend.ftp;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.net.Inet6Address;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLException;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPCmd;
|
||||
import org.apache.commons.net.ftp.FTPReply;
|
||||
import org.apache.commons.net.util.Base64;
|
||||
|
||||
public class HTTPProxyFTPSClient extends SSLSessionReuseFTPSClient {
|
||||
|
||||
/** Default PROT Command */
|
||||
private static final String DEFAULT_PROT = "C";
|
||||
|
||||
private final String proxyHost;
|
||||
|
||||
private final int proxyPort;
|
||||
|
||||
private final String proxyUsername;
|
||||
|
||||
private final String proxyPassword;
|
||||
|
||||
private SSLContext context;
|
||||
|
||||
private String protectionLevel;
|
||||
|
||||
private String tunnelHost; // Save the host when setting up a tunnel (needed for EPSV)
|
||||
|
||||
private static final byte[] CRLF = { '\r', '\n' };
|
||||
|
||||
private final Base64 base64 = new Base64();
|
||||
|
||||
public HTTPProxyFTPSClient(boolean isImplicit, SSLContext context, String proxyHost, int proxyPort, String proxyUser,
|
||||
String proxyPass) {
|
||||
super(isImplicit, context);
|
||||
this.proxyHost = proxyHost;
|
||||
this.proxyPort = proxyPort;
|
||||
this.proxyUsername = proxyUser;
|
||||
this.proxyPassword = proxyPass;
|
||||
this.tunnelHost = null;
|
||||
this.context = context;
|
||||
this.protectionLevel = DEFAULT_PROT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call execPROT from Parent class and stores current protection level
|
||||
*
|
||||
* @see org.apache.commons.net.ftp.FTPSClient#execPROT(String)
|
||||
*/
|
||||
@Override
|
||||
public void execPROT(String prot) throws SSLException, IOException {
|
||||
super.execPROT(prot);
|
||||
this.protectionLevel = prot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.commons.net.SocketClient#connect(java.lang.String, int)
|
||||
*/
|
||||
@Override
|
||||
public void connect(String host, int port) throws IOException {
|
||||
|
||||
_socket_ = new Socket(proxyHost, proxyPort);
|
||||
_input_ = _socket_.getInputStream();
|
||||
_output_ = _socket_.getOutputStream();
|
||||
|
||||
try {
|
||||
tunnelHandshake(host, port, _input_, _output_);
|
||||
} catch (Exception e) {
|
||||
throw new IOException("Could not connect to " + host + " using port " + port, e);
|
||||
}
|
||||
|
||||
super._connectAction_();
|
||||
}
|
||||
|
||||
/**
|
||||
* Open ssl socket (if private protection level selected) using tunnel socket
|
||||
*
|
||||
* @see org.apache.commons.net.ftp.FTPSClient#_openDataConnection_(java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
protected Socket _openDataConnection_(String command, String arg) throws IOException {
|
||||
//Force local passive mode, active mode not supported by through proxy
|
||||
if (getDataConnectionMode() != PASSIVE_LOCAL_DATA_CONNECTION_MODE) {
|
||||
throw new IllegalStateException("Only passive connection mode supported using proxy");
|
||||
}
|
||||
|
||||
final boolean isInet6Address = getRemoteAddress() instanceof Inet6Address;
|
||||
String passiveHost;
|
||||
|
||||
// Try EPSV command first on IPv6 - and IPv4 if enabled.
|
||||
// When using IPv4 with NAT it has the advantage
|
||||
// to work with more rare configurations.
|
||||
// E.g. if FTP server has a static PASV address (external network)
|
||||
// and the client is coming from another internal network.
|
||||
// In that case the data connection after PASV command would fail,
|
||||
// while EPSV would make the client succeed by taking just the port.
|
||||
boolean attemptEPSV = isUseEPSVwithIPv4() || isInet6Address;
|
||||
|
||||
if (attemptEPSV && epsv() == FTPReply.ENTERING_EPSV_MODE) {
|
||||
_parseExtendedPassiveModeReply(_replyLines.get(0));
|
||||
passiveHost = this.tunnelHost;
|
||||
} else {
|
||||
if (isInet6Address) {
|
||||
return null; // Must use EPSV for IPV6
|
||||
}
|
||||
|
||||
// If EPSV failed on IPV4, revert to PASV
|
||||
if (pasv() != FTPReply.ENTERING_PASSIVE_MODE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
_parsePassiveModeReply(_replyLines.get(0));
|
||||
passiveHost = this.getPassiveHost();
|
||||
}
|
||||
|
||||
return DEFAULT_PROT.equals(protectionLevel) ?
|
||||
openPlainDataConnection(passiveHost, command, arg) : openEncryptedDataConnection(passiveHost, command, arg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, configure and open SSLSocket via plain tunnel Socket
|
||||
* @param passiveHost host returned from ftp server after sending PASV command
|
||||
* @param command to execute
|
||||
* @param arg for command
|
||||
* @return SSLSocket using to Data transmit
|
||||
* @throws IOException
|
||||
*/
|
||||
private Socket openEncryptedDataConnection(String passiveHost, String command, String arg) throws IOException {
|
||||
Socket proxySocket = createTunnelSocket();
|
||||
|
||||
proxySocket.connect(new InetSocketAddress(proxyHost, proxyPort), getConnectTimeout());
|
||||
|
||||
tunnelHandshake(passiveHost, this.getPassivePort(), proxySocket.getInputStream(),
|
||||
proxySocket.getOutputStream());
|
||||
Socket socket = context.getSocketFactory().createSocket(proxySocket, passiveHost, this.getPassivePort(), true);
|
||||
_prepareDataSocket_(socket);
|
||||
|
||||
configureDataSocket(socket);
|
||||
|
||||
if (isRestartOffsetIncorrect()) {
|
||||
proxySocket.close();
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
|
||||
proxySocket.close();
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (socket instanceof SSLSocket) {
|
||||
SSLSocket sslSocket = (SSLSocket) socket;
|
||||
configureSSLDataSocket(sslSocket);
|
||||
sslSocket.startHandshake();
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
private Socket createTunnelSocket() throws IOException {
|
||||
Socket proxySocket = new Socket();
|
||||
|
||||
configureDataSocket(proxySocket);
|
||||
|
||||
return proxySocket;
|
||||
}
|
||||
|
||||
private void configureSSLDataSocket(SSLSocket sslSocket) {
|
||||
sslSocket.setUseClientMode(getUseClientMode());
|
||||
sslSocket.setEnableSessionCreation(getEnableSessionCreation());
|
||||
|
||||
// server mode
|
||||
if (!getUseClientMode()) {
|
||||
sslSocket.setNeedClientAuth(getNeedClientAuth());
|
||||
sslSocket.setWantClientAuth(getWantClientAuth());
|
||||
}
|
||||
|
||||
if (getEnabledCipherSuites() != null) {
|
||||
sslSocket.setEnabledCipherSuites(getEnabledCipherSuites());
|
||||
}
|
||||
|
||||
if (getEnabledProtocols() != null) {
|
||||
sslSocket.setEnabledProtocols(getEnabledProtocols());
|
||||
}
|
||||
}
|
||||
|
||||
private void configureDataSocket(Socket socket) throws IOException {
|
||||
if (getReceiveDataSocketBufferSize() > 0) {
|
||||
socket.setReceiveBufferSize(getReceiveDataSocketBufferSize());
|
||||
}
|
||||
|
||||
if (getSendDataSocketBufferSize() > 0) {
|
||||
socket.setSendBufferSize(getSendDataSocketBufferSize());
|
||||
}
|
||||
|
||||
if (getPassiveLocalIPAddress() != null) {
|
||||
socket.bind(new InetSocketAddress(getPassiveLocalIPAddress(), 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.commons.net.ftp.FTPHTTPClient#_openDataConnection_(FTPCmd, String)
|
||||
* @return Plain Socket using HTTP proxy
|
||||
*/
|
||||
private Socket openPlainDataConnection(String passiveHost, String command, String arg) throws IOException {
|
||||
Socket socket = preparePlainDataTunnelSocket(passiveHost);
|
||||
|
||||
if (isRestartOffsetIncorrect()) {
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!FTPReply.isPositivePreliminary(sendCommand(command, arg))) {
|
||||
socket.close();
|
||||
return null;
|
||||
}
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create, prepare and connect plain data transmit socket via tunnel proxy
|
||||
*/
|
||||
private Socket preparePlainDataTunnelSocket(String passiveHost) throws IOException {
|
||||
Socket socket = _socketFactory_.createSocket(proxyHost, proxyPort);
|
||||
InputStream is = socket.getInputStream();
|
||||
OutputStream os = socket.getOutputStream();
|
||||
tunnelHandshake(passiveHost, this.getPassivePort(), is, os);
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP handshake for proxy
|
||||
*/
|
||||
private void tunnelHandshake(String host, int port, InputStream input, OutputStream output) throws IOException {
|
||||
final String connectString = "CONNECT " + host + ":" + port + " HTTP/1.1";
|
||||
final String hostString = "Host: " + host + ":" + port;
|
||||
|
||||
this.tunnelHost = host;
|
||||
output.write(connectString.getBytes(StandardCharsets.UTF_8));
|
||||
output.write(CRLF);
|
||||
output.write(hostString.getBytes(StandardCharsets.UTF_8));
|
||||
output.write(CRLF);
|
||||
|
||||
if (proxyUsername != null && proxyPassword != null) {
|
||||
final String auth = proxyUsername + ":" + proxyPassword;
|
||||
final String header =
|
||||
"Proxy-Authorization: Basic " + base64.encodeToString(auth.getBytes(StandardCharsets.UTF_8));
|
||||
output.write(header.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
output.write(CRLF);
|
||||
output.flush();
|
||||
|
||||
List<String> response = new ArrayList<>();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(input, getCharset()));
|
||||
String responseLine;
|
||||
while ((responseLine = reader.readLine()) != null && responseLine.length() > 0) {
|
||||
response.add(responseLine);
|
||||
}
|
||||
|
||||
int size = response.size();
|
||||
|
||||
if (size == 0) {
|
||||
throw new IOException("No response from proxy");
|
||||
}
|
||||
|
||||
String code;
|
||||
String resp = response.get(0);
|
||||
|
||||
if (resp.startsWith("HTTP/") && resp.length() >= 12) {
|
||||
code = resp.substring(9, 12);
|
||||
} else {
|
||||
throw new IOException("Invalid response from proxy: " + resp);
|
||||
}
|
||||
|
||||
if (!"200".equals(code)) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("HTTPTunnelConnector: connection failed\r\n");
|
||||
msg.append("Response received from the proxy:\r\n");
|
||||
|
||||
for (String line : response) {
|
||||
msg.append(line);
|
||||
msg.append("\r\n");
|
||||
}
|
||||
|
||||
throw new IOException(msg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isRestartOffsetIncorrect() throws IOException {
|
||||
return (getRestartOffset() > 0) && !restart(getRestartOffset());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package org.talend.ftp;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Socket;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSessionContext;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
|
||||
import org.apache.commons.net.ftp.FTPSClient;
|
||||
|
||||
public class SSLSessionReuseFTPSClient extends FTPSClient {
|
||||
|
||||
public SSLSessionReuseFTPSClient(boolean isImplicit, SSLContext context) {
|
||||
super(isImplicit, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _prepareDataSocket_(final Socket socket) {
|
||||
if (socket instanceof SSLSocket) {
|
||||
final SSLSession session = ((SSLSocket) _socket_).getSession();
|
||||
final SSLSessionContext context = session.getSessionContext();
|
||||
try {
|
||||
final Field sessionHostPortCache = context.getClass().getDeclaredField("sessionHostPortCache");
|
||||
sessionHostPortCache.setAccessible(true);
|
||||
final Object cache = sessionHostPortCache.get(context);
|
||||
final Method putMethod = cache.getClass().getDeclaredMethod("put", Object.class, Object.class);
|
||||
putMethod.setAccessible(true);
|
||||
final Method getHostMethod = socket.getClass().getDeclaredMethod("getHost");
|
||||
getHostMethod.setAccessible(true);
|
||||
Object host = getHostMethod.invoke(socket);
|
||||
final String key =
|
||||
String.format("%s:%s", host, String.valueOf(socket.getPort())).toLowerCase(Locale.ROOT);
|
||||
putMethod.invoke(cache, key, session);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
package org.talend.mq.headers.rfh2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
public class Rfh2AreaParser {
|
||||
private static class Property {
|
||||
public String name;
|
||||
public StringBuffer value = new StringBuffer();
|
||||
public String dataType;
|
||||
public boolean isNull;
|
||||
}
|
||||
|
||||
private static class SaxHandler extends DefaultHandler {
|
||||
|
||||
private RFH2Area area;
|
||||
private Property currentProperty;
|
||||
|
||||
public RFH2Area getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String name,
|
||||
Attributes attributes) throws SAXException {
|
||||
if(area == null) {
|
||||
// root element
|
||||
if(name.equals("jms")) {
|
||||
area = new JmsArea();
|
||||
} else if(name.equals("mcd")) {
|
||||
area = new McdArea();
|
||||
} else {
|
||||
area = new UsrArea(name);
|
||||
}
|
||||
} else {
|
||||
if(currentProperty == null) {
|
||||
currentProperty = new Property();
|
||||
currentProperty.name = name;
|
||||
|
||||
if("true".equals(attributes.getValue("xsi:nil"))) {
|
||||
currentProperty.isNull = true;
|
||||
}
|
||||
|
||||
currentProperty.dataType = attributes.getValue("dt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
if(currentProperty != null) {
|
||||
// TODO use start and length
|
||||
for(int i = start; i<start+length; i++) {
|
||||
currentProperty.value.append(ch[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localName, String name)
|
||||
throws SAXException {
|
||||
if(currentProperty != null) {
|
||||
String valueAsString = currentProperty.value.toString();
|
||||
Object value;
|
||||
if(currentProperty.isNull) {
|
||||
value = null;
|
||||
} else if(currentProperty.dataType == null) {
|
||||
// String
|
||||
value = valueAsString;
|
||||
} else if("i4".equals(currentProperty.dataType)) {
|
||||
value = Integer.valueOf(valueAsString);
|
||||
} else if("i8".equals(currentProperty.dataType)) {
|
||||
value = Long.valueOf(valueAsString);
|
||||
} else if("i2".equals(currentProperty.dataType)) {
|
||||
value = Short.valueOf(valueAsString);
|
||||
} else if("i1".equals(currentProperty.dataType)) {
|
||||
value = Byte.valueOf(valueAsString);
|
||||
} else if("boolean".equals(currentProperty.dataType)) {
|
||||
if("1".equals(valueAsString)) {
|
||||
value = Boolean.TRUE;
|
||||
} else {
|
||||
value = Boolean.FALSE;
|
||||
}
|
||||
} else if("r4".equals(currentProperty.dataType)) {
|
||||
value = Float.valueOf(valueAsString);
|
||||
} else if("r8".equals(currentProperty.dataType)) {
|
||||
value = Double.valueOf(valueAsString);
|
||||
} else {
|
||||
throw new RuntimeException("Unknown data type: " + currentProperty.dataType);
|
||||
}
|
||||
|
||||
area.setProperty(currentProperty.name, value);
|
||||
|
||||
currentProperty = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RFH2Area parse(String stringToParse) {
|
||||
SAXParser parser;
|
||||
try {
|
||||
parser = SAXParserFactory.newInstance().newSAXParser();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to create XML parser, can not parse RFH2 areas", e);
|
||||
}
|
||||
|
||||
SaxHandler handler = new SaxHandler();
|
||||
|
||||
try {
|
||||
parser.parse(new InputSource(new StringReader(stringToParse)), handler);
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException("Invalid RFH2 header", e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Invalid RFH2 header", e);
|
||||
}
|
||||
|
||||
return handler.getArea();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend</groupId>
|
||||
<artifactId>talendMQRFH2</artifactId>
|
||||
<version>1.0.1-20190206</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ibm.mq</groupId>
|
||||
<artifactId>com.ibm.mq</artifactId>
|
||||
<version>8.0.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ibm.mq</groupId>
|
||||
<artifactId>com.ibm.mqjms</artifactId>
|
||||
<version>8.0.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.ibm.mq</groupId>
|
||||
<artifactId>com.ibm.mq.allclient</artifactId>
|
||||
<version>8.0.0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>jnp-client</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>websphere-connector-1_5</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>trove</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>talend_open</id>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>talend_open_snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-zl.talend.com/nexus/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-zl.talend.com/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>talend-update</id>
|
||||
<url>https://talend-update.talend.com/nexus/content/repositories/libraries/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,134 @@
|
||||
package org.talend.mq.headers.rfh2;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.xml.parsers.SAXParser;
|
||||
import javax.xml.parsers.SAXParserFactory;
|
||||
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
|
||||
public class Rfh2AreaParser {
|
||||
|
||||
private final String DISALLOW_DOCTYPE_DECL = "http://apache.org/xml/features/disallow-doctype-decl";
|
||||
|
||||
private static class Property {
|
||||
|
||||
public String name;
|
||||
|
||||
public StringBuffer value = new StringBuffer();
|
||||
|
||||
public String dataType;
|
||||
|
||||
public boolean isNull;
|
||||
}
|
||||
|
||||
private static class SaxHandler extends DefaultHandler {
|
||||
|
||||
private RFH2Area area;
|
||||
|
||||
private Property currentProperty;
|
||||
|
||||
public RFH2Area getArea() {
|
||||
return area;
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String name, Attributes attributes) throws SAXException {
|
||||
if (area == null) {
|
||||
// root element
|
||||
if (name.equals("jms")) {
|
||||
area = new JmsArea();
|
||||
} else if (name.equals("mcd")) {
|
||||
area = new McdArea();
|
||||
} else {
|
||||
area = new UsrArea(name);
|
||||
}
|
||||
} else {
|
||||
if (currentProperty == null) {
|
||||
currentProperty = new Property();
|
||||
currentProperty.name = name;
|
||||
|
||||
if ("true".equals(attributes.getValue("xsi:nil"))) {
|
||||
currentProperty.isNull = true;
|
||||
}
|
||||
|
||||
currentProperty.dataType = attributes.getValue("dt");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length) throws SAXException {
|
||||
if (currentProperty != null) {
|
||||
// TODO use start and length
|
||||
for (int i = start; i < start + length; i++) {
|
||||
currentProperty.value.append(ch[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localName, String name) throws SAXException {
|
||||
if (currentProperty != null) {
|
||||
String valueAsString = currentProperty.value.toString();
|
||||
Object value;
|
||||
if (currentProperty.isNull) {
|
||||
value = null;
|
||||
} else if (currentProperty.dataType == null) {
|
||||
// String
|
||||
value = valueAsString;
|
||||
} else if ("i4".equals(currentProperty.dataType)) {
|
||||
value = Integer.valueOf(valueAsString);
|
||||
} else if ("i8".equals(currentProperty.dataType)) {
|
||||
value = Long.valueOf(valueAsString);
|
||||
} else if ("i2".equals(currentProperty.dataType)) {
|
||||
value = Short.valueOf(valueAsString);
|
||||
} else if ("i1".equals(currentProperty.dataType)) {
|
||||
value = Byte.valueOf(valueAsString);
|
||||
} else if ("boolean".equals(currentProperty.dataType)) {
|
||||
if ("1".equals(valueAsString)) {
|
||||
value = Boolean.TRUE;
|
||||
} else {
|
||||
value = Boolean.FALSE;
|
||||
}
|
||||
} else if ("r4".equals(currentProperty.dataType)) {
|
||||
value = Float.valueOf(valueAsString);
|
||||
} else if ("r8".equals(currentProperty.dataType)) {
|
||||
value = Double.valueOf(valueAsString);
|
||||
} else {
|
||||
throw new RuntimeException("Unknown data type: " + currentProperty.dataType);
|
||||
}
|
||||
|
||||
area.setProperty(currentProperty.name, value);
|
||||
|
||||
currentProperty = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public RFH2Area parse(String stringToParse) {
|
||||
SAXParser parser;
|
||||
try {
|
||||
SAXParserFactory spf = SAXParserFactory.newInstance();
|
||||
spf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
|
||||
spf.setFeature(DISALLOW_DOCTYPE_DECL, true);
|
||||
parser = spf.newSAXParser();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Failed to create XML parser, can not parse RFH2 areas", e);
|
||||
}
|
||||
|
||||
SaxHandler handler = new SaxHandler();
|
||||
|
||||
try {
|
||||
parser.parse(new InputSource(new StringReader(stringToParse)), handler);
|
||||
} catch (SAXException e) {
|
||||
throw new RuntimeException("Invalid RFH2 header", e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Invalid RFH2 header", e);
|
||||
}
|
||||
|
||||
return handler.getArea();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/httpclient-4.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/httpcore-4.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/httpmime-4.0.1.jar"/>
|
||||
<classpathentry kind="lib" path="lib/javacsv-2.0.jar"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/org.talend.libraries.csv"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -272,6 +272,7 @@ public class SOAPUtil {
|
||||
|
||||
try {
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
|
||||
Transformer t = tf.newTransformer();
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
t.transform(reSoapPart.getContent(), new StreamResult(bos));
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<groupId>org.talend</groupId>
|
||||
<artifactId>talend-httputil</artifactId>
|
||||
<name>talend-httputil</name>
|
||||
<version>1.0.2</version>
|
||||
<version>1.0.3</version>
|
||||
|
||||
<properties>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
@@ -20,7 +20,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.9.7</version>
|
||||
<version>2.9.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
@@ -31,6 +32,7 @@ import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
import javax.xml.xpath.XPathFactoryConfigurationException;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
@@ -43,6 +45,7 @@ import org.apache.http.params.CoreConnectionPNames;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.talend.commons.ui.runtime.exception.ExceptionHandler;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
@@ -215,7 +218,13 @@ public final class WsdlTokenManager {
|
||||
|
||||
Document document = builder.parse(new ByteArrayInputStream(inputXML.getBytes()));
|
||||
|
||||
XPath xpath = XPathFactory.newInstance().newXPath();
|
||||
XPathFactory xpf = XPathFactory.newInstance();
|
||||
try {
|
||||
xpf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||
} catch (XPathFactoryConfigurationException ex) {
|
||||
ExceptionHandler.process(ex);
|
||||
}
|
||||
XPath xpath = xpf.newXPath();
|
||||
String expression = xPathQuery;
|
||||
Node cipherValue = (Node) xpath.evaluate(expression, document, XPathConstants.NODE);
|
||||
return cipherValue == null ? null : cipherValue.getTextContent();
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="org.talend.designer.components.libs" default="process" basedir=".">
|
||||
|
||||
<property name="component.plugin.home" value="../../../org.talend.designer.components.localprovider/components" />
|
||||
|
||||
<!-- #################################################### -->
|
||||
|
||||
<!-- modification 1: config -->
|
||||
<property name="jar.name" value="talend-ws-1.0.jar" />
|
||||
<property name="component.name" value="tWebService" />
|
||||
<property name="author.name" value="bchen" />
|
||||
|
||||
<!-- modification 2: compile classpath -->
|
||||
<path id="compile.classpath">
|
||||
<pathelement location="${component.plugin.home}/tAlfrescoOutput/commons-codec-1.3.jar" />
|
||||
<pathelement location="${component.plugin.home}/tMicrosoftCrmInput/commons-httpclient-3.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tMicrosoftCrmInput/geronimo-stax-api_1.0_spec-1.0.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tMicrosoftCrmInput/commons-logging-1.1.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWriteJSONFieldIn/commons-lang-2.6.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/commons-collections-3.2.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/commons-beanutils-1.7.0.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/cxf-2.6.0-modified.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/jaxb-xjc-2.2.5-modified.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/jaxb-impl-2.2.5-modified.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/wsdl4j-1.6.2.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/xmlschema-core-2.0.2.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/geronimo-annotation_1.0_spec-1.1.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/geronimo-ws-metadata_2.0_spec-1.1.3.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/geronimo-jaxws_2.2_spec-1.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/woodstox-core-asl-4.1.2.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/saaj-impl-1.3.18.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/asm-3.3.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/neethi-3.0.2.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/saaj-api-1.3.4.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/stax2-api-3.1.1.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebService/velocity-1.7.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebServiceInput/activation.jar" />
|
||||
<pathelement location="${component.plugin.home}/tWebServiceInput/mail.jar" />
|
||||
</path>
|
||||
|
||||
<!-- #################################################### -->
|
||||
|
||||
|
||||
<!-- sourcecode and final jar path -->
|
||||
<property name="source.home" value="." />
|
||||
<property name="jar.home" value="${component.plugin.home}/${component.name}/${jar.name}" />
|
||||
|
||||
<!-- temp dir for clasee files -->
|
||||
<property name="build.dir" value="../../build" />
|
||||
|
||||
<!-- compile option -->
|
||||
<property name="compile.debug" value="true" />
|
||||
<property name="compile.deprecation" value="false" />
|
||||
<property name="compile.optimize" value="true" />
|
||||
|
||||
|
||||
<target name="process" description="prepare a temp dir">
|
||||
<antcall target="prepare" />
|
||||
<antcall target="compile" />
|
||||
<antcall target="clean" />
|
||||
</target>
|
||||
|
||||
<target name="prepare" description="prepare a temp dir">
|
||||
<delete dir="${build.dir}" />
|
||||
<mkdir dir="${build.dir}" />
|
||||
<mkdir dir="${build.dir}/classes" />
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile Java sources">
|
||||
|
||||
<!-- compile -->
|
||||
<javac srcdir="${source.home}" destdir="${build.dir}/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
|
||||
<classpath refid="compile.classpath" />
|
||||
</javac>
|
||||
|
||||
<!-- include source code -->
|
||||
<copy todir="${build.dir}/classes">
|
||||
<fileset dir="${source.home}">
|
||||
<exclude name="build.xml" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<!-- make jar -->
|
||||
<tstamp>
|
||||
<format property="date" pattern="yyyy-MM-dd HH:mm:ss" />
|
||||
</tstamp>
|
||||
|
||||
<jar destfile="${build.dir}/${jar.name}" basedir="${build.dir}/classes">
|
||||
<manifest>
|
||||
<!-- who -->
|
||||
<attribute name="Built-By" value="${author.name}" />
|
||||
<!-- when -->
|
||||
<attribute name="Built-Date" value="${date}"/>
|
||||
<!-- JDK version -->
|
||||
<attribute name="Created-By" value="${java.version} (${java.vendor})" />
|
||||
<!-- Information about the program itself -->
|
||||
<attribute name="Implementation-Vendor" value="Talend SA" />
|
||||
<attribute name="Implementation-Title" value="${jar.name}" />
|
||||
<attribute name="Implementation-Version" value="1.0" />
|
||||
</manifest>
|
||||
</jar>
|
||||
|
||||
<!-- move jar -->
|
||||
<move file="${build.dir}/${jar.name}" tofile="${jar.home}" />
|
||||
|
||||
</target>
|
||||
|
||||
<target name="clean" description="clean the temp dir">
|
||||
<delete dir="${build.dir}" />
|
||||
<mkdir dir="${build.dir}" />
|
||||
</target>
|
||||
</project>
|
||||
@@ -0,0 +1,254 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>talend-ws</artifactId>
|
||||
<version>1.0.1-20190204</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<cxf.version>3.1.1</cxf.version>
|
||||
<odata.version>4.3.0</odata.version>
|
||||
<slf4j.version>1.7.12</slf4j.version>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
|
||||
<dependency>
|
||||
<groupId>commons-httpclient</groupId>
|
||||
<artifactId>commons-httpclient</artifactId>
|
||||
<version>3.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.codehaus.woodstox/stax2-api -->
|
||||
<dependency>
|
||||
<groupId>org.codehaus.woodstox</groupId>
|
||||
<artifactId>stax2-api</artifactId>
|
||||
<version>4.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.geronimo.specs/geronimo-stax-api_1.0_spec -->
|
||||
<dependency>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
<artifactId>geronimo-stax-api_1.0_spec</artifactId>
|
||||
<version>1.0.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-lang/commons-lang -->
|
||||
<dependency>
|
||||
<groupId>commons-lang</groupId>
|
||||
<artifactId>commons-lang</artifactId>
|
||||
<version>2.6</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-beanutils/commons-beanutils -->
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.8.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-core</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-frontend-simple</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-tools-common</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-wsdl</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-bindings-soap</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-databinding-jaxb</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http-jetty</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.cxf</groupId>
|
||||
<artifactId>cxf-rt-transports-http</artifactId>
|
||||
<version>3.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>jaxb-xjc-2.2.6-modified</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>wsdl4j</groupId>
|
||||
<artifactId>wsdl4j</artifactId>
|
||||
<version>1.6.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.xmlschema</groupId>
|
||||
<artifactId>xmlschema-core</artifactId>
|
||||
<version>2.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.woodstox</groupId>
|
||||
<artifactId>woodstox-core</artifactId>
|
||||
<version>5.1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.soap</groupId>
|
||||
<artifactId>saaj-api</artifactId>
|
||||
<version>1.3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.sun.xml.messaging.saaj</groupId>
|
||||
<artifactId>saaj-impl</artifactId>
|
||||
<version>1.3.18</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
<version>3.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.neethi</groupId>
|
||||
<artifactId>neethi</artifactId>
|
||||
<version>3.0.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>1.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>talend_open</id>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>talend_open_snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-oss.talend.com/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>releases</id>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-zl.talend.com/nexus/content/repositories/releases/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>snapshots</id>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<url>https://artifacts-zl.talend.com/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>talend-update</id>
|
||||
<url>https://talend-update.talend.com/nexus/content/repositories/libraries/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/java</directory>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,51 @@
|
||||
1. (2009-10-16 modify by wyang) to close the verbose in console
|
||||
|
||||
Retrieving document at http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL'.
|
||||
|
||||
ServiceDiscoveryHelper.java
|
||||
|
||||
please @see talend-ws-1.0.jar\org\talend\ws\helper\ServiceDiscoveryHelper.java
|
||||
|
||||
2.(2009-10-20 modify by bchen) to work for this webservice: 'http://euro2008.dataaccess.eu/footballpoolwebservice.wso?WSDL'
|
||||
|
||||
ListPropertyMapper.java
|
||||
SimplePropertyMapper.java
|
||||
|
||||
please @see talend-ws-1.0.jar\org\talend\ws\mapper\ListPropertyMapper.java
|
||||
talend-ws-1.0.jar\org\talend\ws\mapper\SimplePropertyMapper.java
|
||||
|
||||
3.(2009-11-18 modified by bchen) fixed bug 9900
|
||||
|
||||
for wrap type of webservice: update to cxf-2.2.4.jar, jaxb-xjc-2.1.12.jar and jaxb-impl-2.1.12.jar.
|
||||
modified ListPropertyMapper.java
|
||||
for bare type of webservice: modified ServiceInvokerHelper.java
|
||||
|
||||
please @see talend-ws-1.0.jar\org\talend\ws\mapper\ListPropertyMapper.java
|
||||
talend-ws-1.0.jar\org\talend\ws\helper\ServiceInvokerHelper.java
|
||||
|
||||
4.(2009-11-18 modified by bchen) support for this webservice:http://www.ebi.ac.uk/intact/binary-search-ws/binarysearch?wsdl
|
||||
consider the situation about no targetnamespace in schema
|
||||
|
||||
modified ServiceInvokerHelper.java
|
||||
|
||||
please @see talend-ws-1.0.jar\org\talend\ws\helper\ServiceInvokerHelper.java
|
||||
|
||||
5.(2009-11-23 modified by bchen) fiexd bug 8674
|
||||
|
||||
please @see org\talend\ws\helper\ServiceDiscoveryHelper.java
|
||||
org\talend\ws\helper\ServiceInvokerHelper.java
|
||||
|
||||
6.(2010-01-05 modified by bchen) fiexd bug 8674
|
||||
|
||||
please @see org\talend\ws\helper\ServiceDiscoveryHelper.java
|
||||
org\talend\ws\helper\ServiceInvokerHelper.java
|
||||
|
||||
7.(2010-02-01 modified by bchen) fixed bug 11351
|
||||
|
||||
8.(2010-02-23 modified by bchen) fixed bug 11351 add an ability to config temporary path for wsdl file.
|
||||
|
||||
9.(2010-03-16 modified by bchen) fixed bug 11917
|
||||
please @see org\talend\ws\helper\ServiceInvokerHelper.java
|
||||
org\talend\ws\mapper\MapperFactory.java
|
||||
|
||||
10.(2019-01-18 modified by dchmyga) fixed TDI-41647
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.talend.webservice.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class IllegalPropertyAccessException extends LocalizedException {
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>IllegalPropertyAccessException</code> with the specified detail message.
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public IllegalPropertyAccessException(String property, String clazz, IllegalAccessException ex) {
|
||||
super("org.talend.ws.exception.IllegalPropertyAccessException", new String[] {property, clazz}, ex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class InvalidEnumValueException extends LocalizedException {
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>InvalidEnumValueException</code> with the specified detail message.
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public InvalidEnumValueException(String value, String enumeration) {
|
||||
super("org.talend.ws.exception.InvalidEnumValueException", new String[]{value, enumeration});
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return (String) arguments[0];
|
||||
}
|
||||
|
||||
public String getEnum() {
|
||||
return (String) arguments[1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class InvocationTargetPropertyAccessor extends LocalizedException {
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>NoSuchPropertyException</code> with the specified detail message.
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public InvocationTargetPropertyAccessor(String property, String clazz, Throwable ex) {
|
||||
super("org.talend.ws.exception.InvocationTargetPropertyAccessor", new String[]{property, clazz}, ex);
|
||||
}
|
||||
|
||||
public String getProperty() {
|
||||
return (String) arguments[0];
|
||||
}
|
||||
|
||||
public String getClazz() {
|
||||
return (String) arguments[1];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.exception;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class LocalizedException extends Exception {
|
||||
|
||||
protected Object[] arguments;
|
||||
private static ResourceBundle messages;
|
||||
|
||||
|
||||
static {
|
||||
messages = ResourceBundle.getBundle("messages");
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of <code>LocalizedException</code> without detail message.
|
||||
*/
|
||||
public LocalizedException() {
|
||||
}
|
||||
|
||||
public LocalizedException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public LocalizedException(String msg, Object[] arguments, Throwable cause) {
|
||||
super(msg, cause);
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public LocalizedException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>LocalizedException</code> with the specified detail message.
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public LocalizedException(String msg, Object[] arguments) {
|
||||
this(msg);
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLocalizedMessage() {
|
||||
String msg = getMessage();
|
||||
if (msg != null) {
|
||||
msg = messages.getString(msg);
|
||||
if (msg == null) {
|
||||
return getMessage();
|
||||
} else {
|
||||
if (arguments == null) {
|
||||
return msg;
|
||||
} else {
|
||||
return MessageFormat.format(msg, arguments);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.talend.webservice.exception;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class NoSuchPropertyException extends LocalizedException {
|
||||
|
||||
/**
|
||||
* Constructs an instance of <code>NoSuchPropertyException</code> with the specified detail message.
|
||||
* @param msg the detail message.
|
||||
*/
|
||||
public NoSuchPropertyException(String property, String clazz, NoSuchMethodException ex) {
|
||||
super("org.talend.ws.exception.NoSuchPropertyException", new String[] {property, clazz}, ex);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2018 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend.webservice.helper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
|
||||
|
||||
/**
|
||||
* created by wwang on 2013-1-10
|
||||
* util to procss the path string
|
||||
*
|
||||
*/
|
||||
public class PathUtil {
|
||||
|
||||
/**
|
||||
*
|
||||
* It is like String.indexOf(String),but not process the :anytype{*} part
|
||||
* @param path
|
||||
* @param sep
|
||||
* @return
|
||||
*/
|
||||
public static int indexOfPath(String path,String sep) {
|
||||
if(path == null || sep == null || sep.length() == 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(sep.contains(":") || sep.contains("{") || sep.contains("}")) {
|
||||
throw new RuntimeException("separator can't contain :,{,}");
|
||||
}
|
||||
|
||||
char first = sep.charAt(0);
|
||||
|
||||
boolean isTypeDefine = false;
|
||||
|
||||
for(int i=0;i<path.length();i++) {
|
||||
char c = path.charAt(i);
|
||||
|
||||
if(c == '{') {
|
||||
isTypeDefine = true;
|
||||
} else if(c == '}') {
|
||||
isTypeDefine = false;
|
||||
}
|
||||
|
||||
if(c != first) {
|
||||
while (++i < path.length()) {
|
||||
char ch = path.charAt(i);
|
||||
|
||||
if(!isTypeDefine && (ch == first)) {//look for the first char that is not in type define substring.
|
||||
break;
|
||||
}
|
||||
|
||||
if(ch == '{') {
|
||||
isTypeDefine = true;
|
||||
} else if(ch == '}') {
|
||||
isTypeDefine = false;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
if (i < path.length()) {//look for the rest that is not in type define substring.
|
||||
int j = i + 1;
|
||||
int end = j + sep.length() - 1;
|
||||
for (int k = 1; j < end && path.charAt(j) ==
|
||||
sep.charAt(k); j++, k++);
|
||||
|
||||
if (j == end) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* It is like org.apache.commons.lang.StringUtils.split(String,String),but not process the :anytype{*} part
|
||||
* @param path
|
||||
* @param sep
|
||||
* @return
|
||||
*/
|
||||
public static String[] splitPath(String path, String separatorChars) {
|
||||
if (path == null) {
|
||||
return null;
|
||||
}
|
||||
int len = path.length();
|
||||
if (len == 0) {
|
||||
return ArrayUtils.EMPTY_STRING_ARRAY;
|
||||
}
|
||||
List list = new ArrayList();
|
||||
int i = 0, start = 0;
|
||||
boolean match = false;
|
||||
boolean lastMatch = false;
|
||||
|
||||
boolean isTypeDefine = false;
|
||||
|
||||
if (separatorChars == null) {
|
||||
// Null separator means use whitespace
|
||||
while (i < len) {
|
||||
char c = path.charAt(i);
|
||||
|
||||
if(c == '{') {
|
||||
isTypeDefine = true;
|
||||
} else if(c == '}') {
|
||||
isTypeDefine = false;
|
||||
}
|
||||
|
||||
if (Character.isWhitespace(c) && !isTypeDefine) {
|
||||
if (match) {
|
||||
lastMatch = true;
|
||||
list.add(path.substring(start, i));
|
||||
match = false;
|
||||
}
|
||||
start = ++i;
|
||||
continue;
|
||||
}
|
||||
lastMatch = false;
|
||||
match = true;
|
||||
i++;
|
||||
}
|
||||
} else if (separatorChars.length() == 1) {
|
||||
// Optimise 1 character case
|
||||
char sep = separatorChars.charAt(0);
|
||||
while (i < len) {
|
||||
char c = path.charAt(i);
|
||||
|
||||
if(c == '{') {
|
||||
isTypeDefine = true;
|
||||
} else if(c == '}') {
|
||||
isTypeDefine = false;
|
||||
}
|
||||
|
||||
if ((c == sep) && !isTypeDefine) {
|
||||
if (match) {
|
||||
lastMatch = true;
|
||||
list.add(path.substring(start, i));
|
||||
match = false;
|
||||
}
|
||||
start = ++i;
|
||||
continue;
|
||||
}
|
||||
lastMatch = false;
|
||||
match = true;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
// standard case
|
||||
while (i < len) {
|
||||
char c = path.charAt(i);
|
||||
|
||||
if(c == '{') {
|
||||
isTypeDefine = true;
|
||||
} else if(c == '}') {
|
||||
isTypeDefine = false;
|
||||
}
|
||||
|
||||
if ((separatorChars.indexOf(c) >= 0) && !isTypeDefine) {
|
||||
if (match) {
|
||||
lastMatch = true;
|
||||
list.add(path.substring(start, i));
|
||||
match = false;
|
||||
}
|
||||
start = ++i;
|
||||
continue;
|
||||
}
|
||||
lastMatch = false;
|
||||
match = true;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
list.add(path.substring(start, i));
|
||||
}
|
||||
return (String[]) list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,467 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.helper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.wsdl.Definition;
|
||||
import javax.wsdl.Import;
|
||||
import javax.wsdl.Types;
|
||||
import javax.wsdl.WSDLException;
|
||||
import javax.wsdl.extensions.ExtensibilityElement;
|
||||
import javax.wsdl.extensions.schema.Schema;
|
||||
import javax.wsdl.extensions.schema.SchemaImport;
|
||||
import javax.wsdl.extensions.schema.SchemaReference;
|
||||
import javax.wsdl.factory.WSDLFactory;
|
||||
import javax.wsdl.xml.WSDLReader;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.apache.ws.commons.schema.XmlSchemaCollection;
|
||||
import org.talend.webservice.helper.conf.ServiceHelperConfiguration;
|
||||
import org.talend.webservice.helper.conf.WSDLLocatorImpl;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
import com.ibm.wsdl.Constants;
|
||||
import com.ibm.wsdl.extensions.schema.SchemaConstants;
|
||||
import com.ibm.wsdl.util.xml.DOMUtils;
|
||||
import com.ibm.wsdl.util.xml.QNameUtils;
|
||||
|
||||
/**
|
||||
* This helper allow easy discovery of services and types
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class ServiceDiscoveryHelper {
|
||||
|
||||
private String wsdlUri;
|
||||
|
||||
private WSDLFactory wsdlFactory;
|
||||
|
||||
private ServiceHelperConfiguration configuration;
|
||||
|
||||
private File wsdlTmpDir;
|
||||
|
||||
private Map<String, Definition> definitions;
|
||||
|
||||
private XmlSchemaCollection schemaCollection;
|
||||
|
||||
private Set<String> namespaces;
|
||||
|
||||
private final String LOCAL_WSDL_NAME = "mainWSDL.wsdl";
|
||||
|
||||
public ServiceDiscoveryHelper(String wsdlUri) throws WSDLException, IOException, TransformerException, URISyntaxException {
|
||||
this(wsdlUri, null, null);
|
||||
}
|
||||
|
||||
public ServiceDiscoveryHelper(String wsdlUri, String tempPath) throws WSDLException, IOException, TransformerException,
|
||||
URISyntaxException {
|
||||
this(wsdlUri, null, tempPath);
|
||||
}
|
||||
|
||||
public ServiceDiscoveryHelper(String wsdlUri, ServiceHelperConfiguration configuration) throws WSDLException, IOException,
|
||||
TransformerException, URISyntaxException {
|
||||
this(wsdlUri, configuration, null);
|
||||
}
|
||||
|
||||
public ServiceDiscoveryHelper(String wsdlUri, ServiceHelperConfiguration configuration, String tempPath)
|
||||
throws WSDLException, IOException, TransformerException, URISyntaxException {
|
||||
this.wsdlUri = wsdlUri;
|
||||
this.configuration = configuration;
|
||||
this.wsdlTmpDir = createTempWsdlDir(tempPath);
|
||||
init();
|
||||
}
|
||||
|
||||
private File createTempWsdlDir(String tempPath) {
|
||||
File tmpWsdlDir;
|
||||
if (tempPath != null && !"".equals(tempPath)) {
|
||||
tmpWsdlDir = new File(tempPath, "wsdl" + String.valueOf(new Date().getTime()) + Thread.currentThread().getId());
|
||||
} else {
|
||||
tmpWsdlDir = new File(System.getProperty("java.io.tmpdir"), "wsdl" + String.valueOf(new Date().getTime()) + Thread.currentThread().getId());
|
||||
}
|
||||
if (!tmpWsdlDir.mkdir()) {
|
||||
throw new SecurityException("Unable to create temporary directory," + tmpWsdlDir.getAbsolutePath());
|
||||
}
|
||||
tmpWsdlDir.deleteOnExit();
|
||||
return tmpWsdlDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the wsdl and schema
|
||||
*
|
||||
* @throws javax.wsdl.WSDLException
|
||||
* @throws TransformerException
|
||||
* @throws URISyntaxException
|
||||
*/
|
||||
private void init() throws WSDLException, IOException, TransformerException, URISyntaxException {
|
||||
wsdlFactory = WSDLFactory.newInstance();
|
||||
WSDLReader newWSDLReader = wsdlFactory.newWSDLReader();
|
||||
newWSDLReader.setFeature(com.ibm.wsdl.Constants.FEATURE_VERBOSE, false);
|
||||
Definition definition;
|
||||
|
||||
URI wsdlURI = new URI(wsdlUri);
|
||||
|
||||
if (configuration != null && wsdlURI.getScheme().startsWith("http")) {
|
||||
definition = newWSDLReader.readWSDL(configuration.createWSDLLocator(wsdlUri));
|
||||
} else {
|
||||
definition = newWSDLReader.readWSDL(wsdlUri);
|
||||
}
|
||||
|
||||
Map<String, Definition> defs = new HashMap<String, Definition>();
|
||||
defs.put(LOCAL_WSDL_NAME, definition);
|
||||
List<String> importKeys = new LinkedList<String>();
|
||||
String parentLoc = absoluteLocation(null, wsdlUri);
|
||||
importKeys.add(definition.getTargetNamespace() + " " + parentLoc);
|
||||
definitions = findWsdlImport(definition, parentLoc, defs, importKeys);
|
||||
|
||||
schemaCollection = getSchemaCollection(definitions);
|
||||
|
||||
namespaces = collectNamespaces();
|
||||
|
||||
generateTempWsdlFile();
|
||||
|
||||
}
|
||||
|
||||
private void generateTempWsdlFile() throws FileNotFoundException, WSDLException, TransformerException, URISyntaxException {
|
||||
generateImportAndIncludeXsd(definitions);
|
||||
|
||||
for (Object key : definitions.keySet()) {
|
||||
File importFile = new File(wsdlTmpDir, key.toString());
|
||||
importFile.deleteOnExit();
|
||||
wsdlFactory.newWSDLWriter().writeWSDL(definitions.get(key), new FileOutputStream(importFile));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void generateImportAndIncludeXsd(Map<String, Definition> definitions) throws FileNotFoundException,
|
||||
TransformerException, URISyntaxException {
|
||||
Map<String, Types> typesList = getTypesFromWsdl(definitions);
|
||||
Map<String, String> schemaIDs = null;
|
||||
|
||||
for (Object key : typesList.keySet()) {
|
||||
Types types = typesList.get(key);
|
||||
if (types != null) {
|
||||
List<ExtensibilityElement> extensibilityElements = types.getExtensibilityElements();
|
||||
for (ExtensibilityElement el : extensibilityElements) {
|
||||
if (el instanceof Schema) {
|
||||
Schema schema = (Schema) el;
|
||||
if (schemaIDs == null) {
|
||||
schemaIDs = new HashMap<String, String>();
|
||||
schemaIDs.put(schema.getDocumentBaseURI(), key.toString());
|
||||
}
|
||||
createTempImportSchemaFile(schema, schemaIDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void createTempImportSchemaFile(Schema schema, Map<String, String> schemaIDs) throws FileNotFoundException,
|
||||
TransformerException, URISyntaxException {
|
||||
|
||||
if (schema.getImports() != null) {
|
||||
Iterator<?> importSchemaIte = schema.getImports().values().iterator();
|
||||
while (importSchemaIte.hasNext()) {
|
||||
|
||||
List<?> importSchemaList = (List<?>) importSchemaIte.next();
|
||||
for (Object importSchemaObj : importSchemaList) {
|
||||
|
||||
if (importSchemaObj instanceof SchemaImport) {
|
||||
|
||||
SchemaImport importSchema = (SchemaImport) importSchemaObj;
|
||||
String schId = importSchema.getId();
|
||||
String schNS = importSchema.getNamespaceURI();
|
||||
String schLocUri = importSchema.getSchemaLocationURI();
|
||||
Schema refSchema = importSchema.getReferencedSchema();
|
||||
|
||||
createTempImportSchemaFile(schema, schLocUri, schNS, schId, refSchema, schemaIDs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.getIncludes() != null || schema.getRedefines() != null) {
|
||||
List<SchemaReference> includes = new ArrayList<SchemaReference>();
|
||||
if (schema.getIncludes() != null && !schema.getIncludes().isEmpty()) {
|
||||
includes.addAll(schema.getIncludes());
|
||||
}
|
||||
if (schema.getRedefines() != null && !schema.getRedefines().isEmpty()) {
|
||||
includes.addAll(schema.getRedefines());
|
||||
}
|
||||
|
||||
for (SchemaReference include : includes) {
|
||||
|
||||
Schema refSchema = include.getReferencedSchema();
|
||||
String schId = include.getId();
|
||||
String schLocUri = include.getSchemaLocationURI();
|
||||
|
||||
createTempImportSchemaFile(schema, schLocUri, null, schId, refSchema, schemaIDs);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createTempImportSchemaFile(Schema schema, String schLocUri, String schNS, String schId, Schema refSchema,
|
||||
Map<String, String> schemaIDs) throws FileNotFoundException, TransformerException, URISyntaxException {
|
||||
if (schLocUri != null && refSchema != null) {
|
||||
if (!schemaIDs.containsKey(refSchema.getDocumentBaseURI())) {
|
||||
String xsdFileName = "schemaXSD" + schemaIDs.size() + ".xsd";
|
||||
schemaIDs.put(refSchema.getDocumentBaseURI(), xsdFileName);
|
||||
|
||||
// lookup child import wsdl
|
||||
createTempImportSchemaFile(refSchema, schemaIDs);
|
||||
|
||||
// create current wsdl
|
||||
createTempXSDFile(refSchema, xsdFileName);
|
||||
|
||||
// modified the parent wsdl
|
||||
changeImportXsdLocation(schema, schId, schNS, schLocUri, xsdFileName);
|
||||
} else {
|
||||
changeImportXsdLocation(schema, schId, schNS, schLocUri, schemaIDs.get(refSchema.getDocumentBaseURI()));
|
||||
|
||||
// only remove the duplicate XSD:IMPORT, for bug[http://jira.talendforge.org/browse/TDI-18573]
|
||||
removeImportXsdLocation(schema, schId, schNS, schemaIDs.get(refSchema.getDocumentBaseURI()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createTempXSDFile(Schema sourceSchema, String xsdFileName) throws FileNotFoundException, TransformerException {
|
||||
Element e = sourceSchema.getElement();
|
||||
DOMSource domSource = new DOMSource(e);
|
||||
|
||||
File xsdFile = new File(this.wsdlTmpDir, xsdFileName);
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(xsdFile);
|
||||
StreamResult streamResult = new StreamResult(fileOutputStream);
|
||||
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
tf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.transform(domSource, streamResult);
|
||||
|
||||
}
|
||||
|
||||
private void removeImportXsdLocation(Schema schema, String id, String ns, String location) {
|
||||
Element schemaElem = schema.getElement();
|
||||
|
||||
Element tempEl = DOMUtils.getFirstChildElement(schemaElem);
|
||||
for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl)) {
|
||||
QName tempElType = QNameUtils.newQName(tempEl);
|
||||
if (SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType)) {
|
||||
if ((DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_ID) == null ? id == null : DOMUtils.getAttribute(tempEl,
|
||||
SchemaConstants.ATTR_ID).equals(id))
|
||||
&& (DOMUtils.getAttribute(tempEl, Constants.ATTR_NAMESPACE) == null ? ns == null : DOMUtils.getAttribute(
|
||||
tempEl, Constants.ATTR_NAMESPACE).equals(ns))
|
||||
&& (DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION) == null ? location == null
|
||||
: DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION).equals(location))) {
|
||||
schemaElem.removeChild(tempEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void changeImportXsdLocation(Schema schema, String id, String ns, String location, String newXSDFileName) {
|
||||
Element schemaElem = schema.getElement();
|
||||
|
||||
Element tempEl = DOMUtils.getFirstChildElement(schemaElem);
|
||||
|
||||
for (; tempEl != null; tempEl = DOMUtils.getNextSiblingElement(tempEl)) {
|
||||
QName tempElType = QNameUtils.newQName(tempEl);
|
||||
if (SchemaConstants.XSD_IMPORT_QNAME_LIST.contains(tempElType)
|
||||
|| SchemaConstants.XSD_INCLUDE_QNAME_LIST.contains(tempElType)
|
||||
|| SchemaConstants.XSD_REDEFINE_QNAME_LIST.contains(tempElType)) {
|
||||
if ((DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_ID) == null ? id == null : DOMUtils.getAttribute(tempEl,
|
||||
SchemaConstants.ATTR_ID).equals(id))
|
||||
&& (DOMUtils.getAttribute(tempEl, Constants.ATTR_NAMESPACE) == null ? ns == null : DOMUtils.getAttribute(
|
||||
tempEl, Constants.ATTR_NAMESPACE).equals(ns))
|
||||
&& (DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION) == null ? location == null
|
||||
: DOMUtils.getAttribute(tempEl, SchemaConstants.ATTR_SCHEMA_LOCATION).equals(location))) {
|
||||
tempEl.getAttributeNode(SchemaConstants.ATTR_SCHEMA_LOCATION).setValue(newXSDFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Definition> findWsdlImport(Definition definition, String parentLocation,
|
||||
Map<String, Definition> definitions, List<String> importKeys) {
|
||||
|
||||
if (definition.getImports() != null && !definition.getImports().isEmpty()) {
|
||||
|
||||
Map<?, ?> imports = definition.getImports();
|
||||
List<Import> importsToRemove = new LinkedList<Import>();
|
||||
for (Map.Entry<?, ?> entry : imports.entrySet()) {
|
||||
|
||||
String namespace = (String) entry.getKey();
|
||||
Vector<?> importsVector = (Vector<?>) entry.getValue();
|
||||
for (Object importObj : importsVector) {
|
||||
Import importDecl = (Import) importObj;
|
||||
String importLoc = absoluteLocation(parentLocation, importDecl.getLocationURI());
|
||||
String importKey = namespace + " " + importLoc;
|
||||
if (importKeys.contains(importKey)) {
|
||||
importsToRemove.add(importDecl);
|
||||
} else {
|
||||
importKeys.add(importKey);
|
||||
|
||||
String importWsdlFileName = "importWsdl" + definitions.size() + ".wsdl";
|
||||
Definition importDef = importDecl.getDefinition();
|
||||
|
||||
if (importDef != null) {
|
||||
definitions.put(importWsdlFileName, importDef);
|
||||
findWsdlImport(importDef, importLoc, definitions, importKeys);
|
||||
}
|
||||
importDecl.setLocationURI(importWsdlFileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!importsToRemove.isEmpty()) {
|
||||
for (Import importToRemove : importsToRemove) {
|
||||
definition.removeImport(importToRemove);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return definitions;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private XmlSchemaCollection getSchemaCollection(Map<String, Definition> definitions) throws FileNotFoundException,
|
||||
TransformerException, URISyntaxException {
|
||||
XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
|
||||
Map<String, Types> typesList = getTypesFromWsdl(definitions);
|
||||
|
||||
int tmpCount = 0;
|
||||
String tmpTNName = "";
|
||||
|
||||
for (Object key : typesList.keySet()) {
|
||||
Types types = typesList.get(key);
|
||||
if (types != null) {
|
||||
List<ExtensibilityElement> extensibilityElements = types.getExtensibilityElements();
|
||||
for (ExtensibilityElement el : extensibilityElements) {
|
||||
if (el instanceof Schema) {
|
||||
Schema schema = (Schema) el;
|
||||
// for bug 8674
|
||||
// set base uri for relative path in schemaLocation.
|
||||
schemaCollection.setBaseUri(schema.getDocumentBaseURI());
|
||||
|
||||
// synthetic URI for the schemas without targetNamespace,avoid conflict error.
|
||||
|
||||
if (schema.getElement().getAttributeNode("targetNamespace") == null) {
|
||||
tmpTNName = schema.getDocumentBaseURI() + "#type" + tmpCount;
|
||||
schemaCollection.read(schema.getElement(), tmpTNName);
|
||||
tmpCount++;
|
||||
} else {
|
||||
schemaCollection.read(schema.getElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return schemaCollection;
|
||||
|
||||
}
|
||||
|
||||
private Map<String, Types> getTypesFromWsdl(Map<String, Definition> importDefinitions) {
|
||||
Map<String, Types> typesList = new HashMap<String, Types>();
|
||||
|
||||
for (Object key : importDefinitions.keySet()) {
|
||||
Definition importDef = importDefinitions.get(key);
|
||||
if (importDef != null) {
|
||||
if (importDef.getTypes() != null) {
|
||||
typesList.put(key.toString(), importDef.getTypes());
|
||||
}
|
||||
}
|
||||
}
|
||||
return typesList;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<String> collectNamespaces() {
|
||||
Set<String> namespaces = new HashSet<String>();
|
||||
|
||||
for (Object key : definitions.keySet()) {
|
||||
Set<Map.Entry<String, String>> entrySet = definitions.get(key).getNamespaces().entrySet();
|
||||
for (Map.Entry<String, String> entry : entrySet) {
|
||||
if (namespaces.contains(entry.getValue())) {
|
||||
continue;
|
||||
}
|
||||
namespaces.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
// some targetnamespace in schema missing in definitions,code for bug 9900 (for bare webservice)
|
||||
if (schemaCollection != null) {
|
||||
org.apache.ws.commons.schema.XmlSchema[] xs = schemaCollection.getXmlSchemas();
|
||||
if (xs != null) {
|
||||
for (org.apache.ws.commons.schema.XmlSchema x : xs) {
|
||||
if (namespaces.contains(x.getTargetNamespace()) || x.getTargetNamespace() == null) {
|
||||
continue;
|
||||
}
|
||||
namespaces.add(x.getTargetNamespace());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parsed wsdl, it contains all services
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Definition getDefinition() {
|
||||
return definitions.get(this.LOCAL_WSDL_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the xml schema collection
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public XmlSchemaCollection getSchema() {
|
||||
return schemaCollection;
|
||||
}
|
||||
|
||||
public String getWsdlUri() {
|
||||
return wsdlUri;
|
||||
}
|
||||
|
||||
public String getLocalWsdlUri() {
|
||||
return new File(wsdlTmpDir, this.LOCAL_WSDL_NAME).toURI().toString();
|
||||
}
|
||||
|
||||
public Set<String> getNamespaces() {
|
||||
return namespaces;
|
||||
}
|
||||
|
||||
private static String absoluteLocation(String parentLocation, String wsdlLocation) {
|
||||
try {
|
||||
return WSDLLocatorImpl.getURL(parentLocation, wsdlLocation).toExternalForm();
|
||||
} catch (MalformedURLException e) {
|
||||
return "NOLOCATION";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,351 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.helper;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.wsdl.Input;
|
||||
import javax.wsdl.Message;
|
||||
import javax.wsdl.Operation;
|
||||
import javax.wsdl.Output;
|
||||
import javax.wsdl.Port;
|
||||
import javax.wsdl.Service;
|
||||
import javax.wsdl.WSDLException;
|
||||
import javax.xml.bind.annotation.XmlSchema;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.TransformerException;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.cxf.endpoint.Client;
|
||||
import org.apache.cxf.endpoint.dynamic.DynamicClientFactory;
|
||||
import org.apache.cxf.service.model.BindingOperationInfo;
|
||||
import org.apache.cxf.transport.http.HTTPConduit;
|
||||
import org.apache.ws.commons.schema.XmlSchemaType;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
import org.talend.webservice.helper.conf.ServiceHelperConfiguration;
|
||||
import org.talend.webservice.helper.map.MapConverter;
|
||||
import org.talend.webservice.jaxb.JAXBUtils;
|
||||
import org.talend.webservice.jaxb.JAXBUtils.IdentifierType;
|
||||
import org.talend.webservice.mapper.AnyPropertyMapper;
|
||||
import org.talend.webservice.mapper.ClassMapper;
|
||||
import org.talend.webservice.mapper.EmptyMessageMapper;
|
||||
import org.talend.webservice.mapper.MapperFactory;
|
||||
import org.talend.webservice.mapper.MessageMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class ServiceInvokerHelper implements ClassMapper {
|
||||
|
||||
private ServiceDiscoveryHelper serviceDiscoveryHelper;
|
||||
|
||||
private DynamicClientFactory dynamicClientFactory;
|
||||
|
||||
private final String packagePrefix;
|
||||
|
||||
private Map<String, String> namespacePackageMap;
|
||||
|
||||
private Map<String, String> packageNamespaceMap;
|
||||
|
||||
private Map<QName, Map<QName, Client>> clients;
|
||||
|
||||
private List<String> bindingFiles;
|
||||
|
||||
private Map<Message, MessageMapper> mappers;
|
||||
|
||||
private MapperFactory mapperFactory;
|
||||
|
||||
private ServiceHelperConfiguration configuration;
|
||||
|
||||
protected ServiceInvokerHelper() {
|
||||
packagePrefix = "tmp" + (String.valueOf((new Random(Calendar.getInstance().getTimeInMillis())).nextInt()).substring(1));
|
||||
dynamicClientFactory = DynamicClientFactory.newInstance();
|
||||
namespacePackageMap = new HashMap<String, String>();
|
||||
packageNamespaceMap = new HashMap<String, String>();
|
||||
clients = new HashMap<QName, Map<QName, Client>>();
|
||||
mappers = new HashMap<Message, MessageMapper>();
|
||||
}
|
||||
|
||||
public ServiceInvokerHelper(String wsdlUri) throws WSDLException, IOException, TransformerException, URISyntaxException {
|
||||
this(new ServiceDiscoveryHelper(wsdlUri));
|
||||
}
|
||||
|
||||
public ServiceInvokerHelper(String wsdlUri, String tempPath) throws WSDLException, IOException, TransformerException,
|
||||
URISyntaxException {
|
||||
this(new ServiceDiscoveryHelper(wsdlUri, tempPath));
|
||||
}
|
||||
|
||||
public ServiceInvokerHelper(String wsdlUri, ServiceHelperConfiguration configuration) throws WSDLException, IOException,
|
||||
TransformerException, URISyntaxException {
|
||||
this(new ServiceDiscoveryHelper(wsdlUri, configuration));
|
||||
}
|
||||
|
||||
public ServiceInvokerHelper(String wsdlUri, ServiceHelperConfiguration configuration, String tempPath) throws WSDLException,
|
||||
IOException, TransformerException, URISyntaxException {
|
||||
this(new ServiceDiscoveryHelper(wsdlUri, configuration, tempPath), configuration);
|
||||
}
|
||||
|
||||
public ServiceInvokerHelper(ServiceDiscoveryHelper serviceDiscoveryHelper, ServiceHelperConfiguration configuration) {
|
||||
this(serviceDiscoveryHelper);
|
||||
this.configuration = configuration;
|
||||
}
|
||||
|
||||
public ServiceInvokerHelper(ServiceDiscoveryHelper serviceDiscoveryHelper) {
|
||||
this();
|
||||
this.serviceDiscoveryHelper = serviceDiscoveryHelper;
|
||||
|
||||
Set<String> namespaces = serviceDiscoveryHelper.getNamespaces();
|
||||
|
||||
bindingFiles = new ArrayList<String>(namespaces.size());
|
||||
for (String ns : namespaces) {
|
||||
String packageName = packagePrefix + JAXBUtils.namespaceURIToPackage(ns);
|
||||
namespacePackageMap.put(ns, packageName);
|
||||
packageNamespaceMap.put(packageName, ns);
|
||||
|
||||
File f = org.apache.cxf.tools.util.JAXBUtils.getPackageMappingSchemaBindingFile(ns, packageName);
|
||||
f.deleteOnExit();
|
||||
bindingFiles.add(f.getAbsolutePath());
|
||||
}
|
||||
|
||||
mapperFactory = new MapperFactory(this, serviceDiscoveryHelper.getSchema());
|
||||
}
|
||||
|
||||
public Client getClient(QName service, QName port) {
|
||||
Map<QName, Client> serviceClients = clients.get(service);
|
||||
if (serviceClients == null) {
|
||||
serviceClients = new HashMap<QName, Client>();
|
||||
clients.put(service, serviceClients);
|
||||
}
|
||||
|
||||
if (serviceClients.get(port) == null) {
|
||||
serviceClients.put(port, createClient(service, port));
|
||||
}
|
||||
|
||||
return serviceClients.get(port);
|
||||
}
|
||||
|
||||
protected Client createClient(QName service, QName port) {
|
||||
// bug 8674
|
||||
|
||||
Client client = dynamicClientFactory.createClient(serviceDiscoveryHelper.getLocalWsdlUri(), service, Thread
|
||||
.currentThread().getContextClassLoader(), port, bindingFiles);
|
||||
// end
|
||||
HTTPConduit conduit = (HTTPConduit) client.getConduit();
|
||||
if (configuration != null) {
|
||||
configuration.configureHttpConduit(conduit);
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
private MessageMapper getMessageMapper(Message message) throws LocalizedException {
|
||||
|
||||
MessageMapper messageMapper = mappers.get(message);
|
||||
if (messageMapper == null) {
|
||||
messageMapper = createMessageMapper(message);
|
||||
mappers.put(message, messageMapper);
|
||||
}
|
||||
|
||||
return messageMapper;
|
||||
}
|
||||
|
||||
private MessageMapper createMessageMapper(Message message) throws LocalizedException {
|
||||
return mapperFactory.createMessageMapper(message);
|
||||
}
|
||||
|
||||
protected Map<String, Object> invoke(Client client, Operation operation, QName operationQName, Object value)
|
||||
throws Exception, LocalizedException {
|
||||
|
||||
Input input = operation.getInput();
|
||||
Output output = operation.getOutput();
|
||||
MessageMapper inMessageMapper = null;
|
||||
MessageMapper outMessageMapper = null;
|
||||
|
||||
BindingOperationInfo bindingOperationInfo = client.getEndpoint().getEndpointInfo().getBinding()
|
||||
.getOperation(operationQName);
|
||||
if (input != null) {
|
||||
inMessageMapper = getMessageMapper(input.getMessage());
|
||||
} else {
|
||||
inMessageMapper = new EmptyMessageMapper();
|
||||
}
|
||||
if (output != null) {
|
||||
outMessageMapper = getMessageMapper(output.getMessage());
|
||||
} else {
|
||||
outMessageMapper = new EmptyMessageMapper();
|
||||
}
|
||||
if (bindingOperationInfo.isUnwrappedCapable()) {
|
||||
inMessageMapper.setUnwrapped(true);
|
||||
outMessageMapper.setUnwrapped(true);
|
||||
}
|
||||
|
||||
Object[] retParams;
|
||||
if (value != null) {
|
||||
Object[] params = inMessageMapper.convertToParams(value);
|
||||
retParams = client.invoke(operationQName, params);
|
||||
} else {
|
||||
retParams = client.invoke(operationQName);
|
||||
}
|
||||
|
||||
Map<String, Object> retValues = outMessageMapper.convertToValue(retParams);
|
||||
|
||||
return retValues;
|
||||
}
|
||||
|
||||
public Map<String, Object> invoke(QName serviceName, QName portName, String operationName, Object params) throws Exception,
|
||||
LocalizedException {
|
||||
if (serviceName == null) {
|
||||
throw new IllegalArgumentException("serviceName is mandatory.");
|
||||
}
|
||||
Service service = serviceDiscoveryHelper.getDefinition().getService(serviceName);
|
||||
if (service == null) {
|
||||
throw new IllegalArgumentException("Service " + serviceName.toString() + " does not exists.");
|
||||
}
|
||||
|
||||
if (portName == null) {
|
||||
throw new IllegalArgumentException("portName is mandatory.");
|
||||
}
|
||||
Port port = service.getPort(portName.getLocalPart());
|
||||
if (port == null) {
|
||||
throw new IllegalArgumentException("Port " + portName + " does not exists for service " + serviceName.toString()
|
||||
+ ".");
|
||||
}
|
||||
if (operationName == null) {
|
||||
throw new IllegalArgumentException("operationName is mandatory.");
|
||||
}
|
||||
Operation operation = port.getBinding().getPortType().getOperation(operationName, null, null);
|
||||
if (operation == null) {
|
||||
throw new IllegalArgumentException("Operation " + operationName + " does not exists for service "
|
||||
+ serviceName.toString() + ".");
|
||||
}
|
||||
|
||||
QName operationQName = new QName(port.getBinding().getPortType().getQName().getNamespaceURI(), operation.getName());
|
||||
|
||||
Client client = getClient(serviceName, portName);
|
||||
|
||||
return invoke(client, operation, operationQName, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke a service with a simple map of parametes (address.city=LYON, address.zipCode=69003, etc ...) Returned
|
||||
* results are also in this format
|
||||
*
|
||||
* @param serviceName
|
||||
* @param portName
|
||||
* @param operationName
|
||||
* @param params
|
||||
* @return
|
||||
* @throws java.lang.Exception
|
||||
* @throws org.talend.webservice.exception.LocalizedException
|
||||
*/
|
||||
public Map<String, Object> invokeSimple(QName serviceName, QName portName, String operationName, Object params)
|
||||
throws Exception, LocalizedException {
|
||||
if (params instanceof Map) {
|
||||
params = MapConverter.mapToDeepMap((Map<String, Object>) params);
|
||||
}
|
||||
|
||||
Map<String, Object> result = invoke(serviceName, portName, operationName, params);
|
||||
|
||||
return MapConverter.deepMapToMap(result);
|
||||
}
|
||||
|
||||
protected String getClassNameForType(QName xmlSchemaTypeMapperQname) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(getPackageForNamespaceURI(xmlSchemaTypeMapperQname.getNamespaceURI()));
|
||||
sb.append(".");
|
||||
sb.append(getClassNameForTypeName(xmlSchemaTypeMapperQname.getLocalPart()));
|
||||
String className = sb.toString();
|
||||
|
||||
return className;
|
||||
}
|
||||
|
||||
protected String getPackageForNamespaceURI(String ns) {
|
||||
return namespacePackageMap.get(ns);
|
||||
}
|
||||
|
||||
protected String getNamespaceURIForPackage(String packageName) {
|
||||
return packageNamespaceMap.get(packageName);
|
||||
}
|
||||
|
||||
protected String getClassNameForTypeName(String typeName) {
|
||||
return toCamelCase(JAXBUtils.nameToIdentifier(typeName, IdentifierType.CLASS), true);
|
||||
}
|
||||
|
||||
public Class<?> getClassForType(QName xmlSchemaTypeMapperQname) {
|
||||
String className = getClassNameForType(xmlSchemaTypeMapperQname);
|
||||
try {
|
||||
Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
|
||||
return clazz;
|
||||
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getClassForType(QName xmlSchemaTypeMapperQName, List<String> propertiesName, int tempSuffix) {
|
||||
Class<?> clazz = getClassForType(xmlSchemaTypeMapperQName);
|
||||
boolean allCorrect = false;
|
||||
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz);
|
||||
|
||||
if (propertiesName.size() == 0) {
|
||||
allCorrect = true;
|
||||
}
|
||||
for (String propertyName : propertiesName) {
|
||||
for (PropertyDescriptor descriptor : descriptors) {
|
||||
if (propertyName.equalsIgnoreCase(descriptor.getName()) || (AnyPropertyMapper.LABEL.equalsIgnoreCase(propertyName) && ("any".equalsIgnoreCase(descriptor.getName()) || "content".equalsIgnoreCase(descriptor.getName())))) {
|
||||
allCorrect = true;
|
||||
break;
|
||||
} else {
|
||||
allCorrect = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!allCorrect) {
|
||||
return getClassForType(new QName(xmlSchemaTypeMapperQName.getNamespaceURI(), xmlSchemaTypeMapperQName.getLocalPart()
|
||||
+ tempSuffix), propertiesName, tempSuffix++);
|
||||
} else {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
public XmlSchemaType getTypeForClass(Class<?> clazz) {
|
||||
if (clazz.isAnnotationPresent(XmlType.class)) {
|
||||
XmlType type = clazz.getAnnotation(XmlType.class);
|
||||
XmlSchema schema = clazz.getPackage().getAnnotation(XmlSchema.class);
|
||||
QName qname = new QName(schema.namespace(), type.name());
|
||||
|
||||
return serviceDiscoveryHelper.getSchema().getTypeByQName(qname);
|
||||
} else {
|
||||
QName type = MapperFactory.javaTypeToBuiltInType(clazz.getName());
|
||||
if (type != null) {
|
||||
return serviceDiscoveryHelper.getSchema().getTypeByQName(type);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unmapped class : " + clazz.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ServiceDiscoveryHelper getServiceDiscoveryHelper() {
|
||||
return serviceDiscoveryHelper;
|
||||
}
|
||||
|
||||
private String toCamelCase(String value, boolean startWithLowerCase) {
|
||||
String[] strings = StringUtils.split(value, "_");
|
||||
for (int i = startWithLowerCase ? 1 : 0; i < strings.length; i++) {
|
||||
strings[i] = StringUtils.capitalize(strings[i]);
|
||||
}
|
||||
return StringUtils.join(strings, "_");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
package org.talend.webservice.helper;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.talend.webservice.jaxb.JAXBUtils;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public final String LIST_SIZE_SYMBOL = ".size";
|
||||
|
||||
public final String LEFT_SQUARE_BRACKET = "[";
|
||||
|
||||
public final String RIGHT_SQUARE_BRACKET = "]";
|
||||
|
||||
public final String ALL_LIST_SYMBOL = "[*]";
|
||||
|
||||
public void resolveInputPath(java.util.Map<String, Object> inputMap) {
|
||||
java.util.Map<String, Object> tempStoreMap = new java.util.HashMap<String, Object>();
|
||||
java.util.List<String> tempRemovePath = new java.util.ArrayList<String>();
|
||||
for (String key : inputMap.keySet()) {
|
||||
if (key.indexOf(ALL_LIST_SYMBOL) != -1) {
|
||||
String listHeadPath = key.substring(0, key.indexOf(ALL_LIST_SYMBOL));
|
||||
String listFootPath = key.substring(key.indexOf(ALL_LIST_SYMBOL) + ALL_LIST_SYMBOL.length());
|
||||
java.util.List listElement = (java.util.List) inputMap.get(key);
|
||||
// if the list is null, ignore it but remove the
|
||||
// original key
|
||||
if (listElement != null) {
|
||||
for (int i = 0; i < listElement.size(); i++) {
|
||||
tempStoreMap.put(listHeadPath + LEFT_SQUARE_BRACKET + i + RIGHT_SQUARE_BRACKET + listFootPath,
|
||||
listElement.get(i));
|
||||
}
|
||||
}
|
||||
tempRemovePath.add(key);
|
||||
}
|
||||
}
|
||||
inputMap.putAll(tempStoreMap);
|
||||
for (String removePath : tempRemovePath) {
|
||||
inputMap.remove(removePath);
|
||||
}
|
||||
}
|
||||
|
||||
public String removePunctuation(String path) {
|
||||
String[] strings = PathUtil.splitPath(path, ".");
|
||||
for (int i = 0; i < strings.length; i++) {
|
||||
strings[i] = JAXBUtils.removePunctuation(strings[i]);
|
||||
}
|
||||
return StringUtils.join(strings, ".");
|
||||
}
|
||||
|
||||
public Object getValue(java.util.Map<String, Object> map, String path) {
|
||||
if (path == null || "".equals(path)) {
|
||||
return null;
|
||||
}
|
||||
if (map == null || map.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
java.util.List<String> paths = new java.util.ArrayList<String>();
|
||||
resolvePath(map, path, paths);
|
||||
if (paths.size() > 0) {
|
||||
if (path.indexOf(ALL_LIST_SYMBOL) == -1) {
|
||||
return map.get(paths.get(0));
|
||||
} else {
|
||||
int size = paths.size();
|
||||
java.util.List<Object> out = new java.util.ArrayList<Object>(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
out.add(map.get(paths.get(i)));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void resolvePath(java.util.Map<String, Object> map, String path, java.util.List<String> paths) {
|
||||
String listHeadPath = "";
|
||||
String listFootPath = "";
|
||||
int size = 0;
|
||||
String tempPath = "";
|
||||
if (path.indexOf(ALL_LIST_SYMBOL) != -1) {
|
||||
listHeadPath = path.substring(0, path.indexOf(ALL_LIST_SYMBOL));
|
||||
listFootPath = path.substring(path.indexOf(ALL_LIST_SYMBOL) + ALL_LIST_SYMBOL.length());
|
||||
if (map.get(listHeadPath) == null && map.get(listHeadPath + LIST_SIZE_SYMBOL) != null) {
|
||||
size = Integer.parseInt(map.get(listHeadPath + LIST_SIZE_SYMBOL).toString());
|
||||
for (int i = 0; i < size; i++) {
|
||||
tempPath = listHeadPath + LEFT_SQUARE_BRACKET + i + RIGHT_SQUARE_BRACKET + listFootPath;
|
||||
if (tempPath.indexOf(ALL_LIST_SYMBOL) != -1) {
|
||||
resolvePath(map, tempPath, paths);
|
||||
} else {
|
||||
paths.add(tempPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
paths.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
public java.util.List<Object> normalize(String inputValue, String delimiter) {
|
||||
if (inputValue == null || "".equals(inputValue)) {
|
||||
return null;
|
||||
}
|
||||
Object[] inputValues = inputValue.split(delimiter);
|
||||
return java.util.Arrays.asList(inputValues);
|
||||
|
||||
}
|
||||
|
||||
public String denormalize(java.util.List inputValues, String delimiter) {
|
||||
if (inputValues == null || inputValues.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
StringBuffer sb = new StringBuffer();
|
||||
for (Object o : inputValues) {
|
||||
sb.append(String.valueOf(o));
|
||||
sb.append(delimiter);
|
||||
}
|
||||
if (sb.length() > 0) {
|
||||
sb.delete(sb.length() - delimiter.length(), sb.length());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.helper.conf;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.security.KeyStore;
|
||||
|
||||
import javax.net.ssl.KeyManager;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
import javax.wsdl.xml.WSDLLocator;
|
||||
|
||||
import org.apache.cxf.configuration.jsse.TLSClientParameters;
|
||||
import org.apache.cxf.configuration.security.AuthorizationPolicy;
|
||||
import org.apache.cxf.configuration.security.ProxyAuthorizationPolicy;
|
||||
import org.apache.cxf.transport.http.HTTPConduit;
|
||||
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
|
||||
import org.apache.cxf.transports.http.configuration.ProxyServerType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class ServiceHelperConfiguration {
|
||||
|
||||
private String proxyServer;
|
||||
|
||||
private int proxyPort;
|
||||
|
||||
private Long connectionTimeout;
|
||||
|
||||
private Long receiveTimeout;
|
||||
|
||||
private String cookie;
|
||||
|
||||
private String username;
|
||||
|
||||
private String password;
|
||||
|
||||
private String proxyUsername;
|
||||
|
||||
private String proxyPassword;
|
||||
|
||||
private String trustStoreFile;
|
||||
|
||||
private String trustStorePwd;
|
||||
|
||||
private String trustStoreType;
|
||||
|
||||
private String keyStoreFile;
|
||||
|
||||
private String keyStorePwd;
|
||||
|
||||
private String keyStoreType;
|
||||
|
||||
private boolean allowChunking = true;
|
||||
|
||||
public boolean isAllowChunking() {
|
||||
return allowChunking;
|
||||
}
|
||||
|
||||
public void setAllowChunking(boolean allowChunking) {
|
||||
this.allowChunking = allowChunking;
|
||||
}
|
||||
|
||||
public WSDLLocator createWSDLLocator(String wsdlUri) {
|
||||
return new WSDLLocatorImpl(this, wsdlUri);
|
||||
}
|
||||
|
||||
private void updateClientPolicy(HTTPClientPolicy hTTPClientPolicy) {
|
||||
if (proxyServer != null) {
|
||||
hTTPClientPolicy.setProxyServer(proxyServer);
|
||||
hTTPClientPolicy.setProxyServerPort(proxyPort);
|
||||
hTTPClientPolicy.setProxyServerType(ProxyServerType.HTTP);
|
||||
} else {
|
||||
hTTPClientPolicy.setProxyServer(null);
|
||||
}
|
||||
if (connectionTimeout != null) {
|
||||
hTTPClientPolicy.setConnectionTimeout(connectionTimeout);
|
||||
}
|
||||
if (receiveTimeout != null) {
|
||||
hTTPClientPolicy.setReceiveTimeout(receiveTimeout);
|
||||
}
|
||||
if (cookie != null) {
|
||||
hTTPClientPolicy.setCookie(cookie);
|
||||
} else {
|
||||
hTTPClientPolicy.setCookie(null);
|
||||
}
|
||||
hTTPClientPolicy.setAllowChunking(allowChunking);
|
||||
}
|
||||
|
||||
public void configureHttpConduit(HTTPConduit httpConduit) {
|
||||
createAuthorizationPolicy(httpConduit);
|
||||
createProxyAuthorizationPolicy(httpConduit);
|
||||
httpConduit.setTlsClientParameters(createTLSClientParameters());
|
||||
updateClientPolicy(httpConduit.getClient());
|
||||
}
|
||||
|
||||
private void createAuthorizationPolicy(HTTPConduit httpConduit) {
|
||||
if (username != null) {
|
||||
AuthorizationPolicy authorizationPolicy = httpConduit.getAuthorization();
|
||||
// authorizationPolicy.setAuthorizationType("Basic");
|
||||
authorizationPolicy.setUserName(username);
|
||||
authorizationPolicy.setPassword(password);
|
||||
}
|
||||
}
|
||||
|
||||
private void createProxyAuthorizationPolicy(HTTPConduit httpConduit) {
|
||||
if (proxyUsername != null) {
|
||||
ProxyAuthorizationPolicy authorizationPolicy = httpConduit.getProxyAuthorization();
|
||||
// authorizationPolicy.setAuthorizationType("Basic");
|
||||
authorizationPolicy.setUserName(proxyUsername);
|
||||
authorizationPolicy.setPassword(proxyPassword);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private TLSClientParameters createTLSClientParameters() {
|
||||
if (trustStoreFile != null || keyStoreFile != null) {
|
||||
TLSClientParameters tlsCP = new TLSClientParameters();
|
||||
if (trustStoreFile != null) {
|
||||
try {
|
||||
KeyStore trustStore = KeyStore.getInstance(trustStoreType);
|
||||
trustStore.load(new FileInputStream(trustStoreFile), trustStorePwd.toCharArray());
|
||||
String alg = TrustManagerFactory.getDefaultAlgorithm();
|
||||
TrustManagerFactory fac = TrustManagerFactory.getInstance(alg);
|
||||
fac.init(trustStore);
|
||||
TrustManager[] myTrustStoreKeyManagers = fac.getTrustManagers();
|
||||
tlsCP.setTrustManagers(myTrustStoreKeyManagers);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (keyStoreFile != null) {
|
||||
try {
|
||||
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
|
||||
keyStore.load(new FileInputStream(keyStoreFile), keyStorePwd.toCharArray());
|
||||
String alg = KeyManagerFactory.getDefaultAlgorithm();
|
||||
char[] keyPass = keyStorePwd != null ? keyStorePwd.toCharArray() : null;
|
||||
KeyManagerFactory fac = KeyManagerFactory.getInstance(alg);
|
||||
fac.init(keyStore, keyPass);
|
||||
KeyManager[] myKeyManagers = fac.getKeyManagers();
|
||||
tlsCP.setKeyManagers(myKeyManagers);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
tlsCP.setDisableCNCheck(true);
|
||||
return tlsCP;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public Long getConnectionTimeout() {
|
||||
return connectionTimeout;
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(Long connectionTimeout) {
|
||||
this.connectionTimeout = connectionTimeout;
|
||||
}
|
||||
|
||||
public String getCookie() {
|
||||
return cookie;
|
||||
}
|
||||
|
||||
public void setCookie(String cookie) {
|
||||
this.cookie = cookie;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public int getProxyPort() {
|
||||
return proxyPort;
|
||||
}
|
||||
|
||||
public void setProxyPort(int proxyPort) {
|
||||
this.proxyPort = proxyPort;
|
||||
}
|
||||
|
||||
public String getProxyServer() {
|
||||
return proxyServer;
|
||||
}
|
||||
|
||||
public void setProxyServer(String proxyServer) {
|
||||
this.proxyServer = proxyServer;
|
||||
}
|
||||
|
||||
public Long getReceiveTimeout() {
|
||||
return receiveTimeout;
|
||||
}
|
||||
|
||||
public void setReceiveTimeout(Long receiveTimeout) {
|
||||
this.receiveTimeout = receiveTimeout;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getProxyPassword() {
|
||||
return proxyPassword;
|
||||
}
|
||||
|
||||
public void setProxyPassword(String proxyPassword) {
|
||||
this.proxyPassword = proxyPassword;
|
||||
}
|
||||
|
||||
public String getProxyUsername() {
|
||||
return proxyUsername;
|
||||
}
|
||||
|
||||
public void setProxyUsername(String proxyUsername) {
|
||||
this.proxyUsername = proxyUsername;
|
||||
}
|
||||
|
||||
public String getTrustStoreFile() {
|
||||
return trustStoreFile;
|
||||
}
|
||||
|
||||
public void setTrustStoreFile(String trustStoreFile) {
|
||||
this.trustStoreFile = trustStoreFile;
|
||||
}
|
||||
|
||||
public String getTrustStorePwd() {
|
||||
return trustStorePwd;
|
||||
}
|
||||
|
||||
public void setTrustStorePwd(String trustStorePwd) {
|
||||
this.trustStorePwd = trustStorePwd;
|
||||
}
|
||||
|
||||
public String getTrustStoreType() {
|
||||
return trustStoreType;
|
||||
}
|
||||
|
||||
public void setTrustStoreType(String trustStoreType) {
|
||||
this.trustStoreType = trustStoreType;
|
||||
}
|
||||
|
||||
public String getKeyStoreFile() {
|
||||
return keyStoreFile;
|
||||
}
|
||||
|
||||
public void setKeyStoreFile(String keyStoreFile) {
|
||||
this.keyStoreFile = keyStoreFile;
|
||||
}
|
||||
|
||||
public String getKeyStorePwd() {
|
||||
return keyStorePwd;
|
||||
}
|
||||
|
||||
public void setKeyStorePwd(String keyStorePwd) {
|
||||
this.keyStorePwd = keyStorePwd;
|
||||
}
|
||||
|
||||
public String getKeyStoreType() {
|
||||
return keyStoreType;
|
||||
}
|
||||
|
||||
public void setKeyStoreType(String keyStoreType) {
|
||||
this.keyStoreType = keyStoreType;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.helper.conf;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.wsdl.xml.WSDLLocator;
|
||||
|
||||
import org.apache.commons.httpclient.Credentials;
|
||||
import org.apache.commons.httpclient.HostConfiguration;
|
||||
import org.apache.commons.httpclient.HttpClient;
|
||||
import org.apache.commons.httpclient.UsernamePasswordCredentials;
|
||||
import org.apache.commons.httpclient.auth.AuthScope;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class WSDLLocatorImpl implements WSDLLocator {
|
||||
|
||||
private static final String HTTP_HEADER_COOKIE = "Cookie";
|
||||
|
||||
private String wsdlUri;
|
||||
|
||||
private String latestImportUri;
|
||||
|
||||
private ServiceHelperConfiguration configuration;
|
||||
|
||||
private HttpClient httpClient;
|
||||
|
||||
private Set<InputStream> inputStreams;
|
||||
|
||||
public WSDLLocatorImpl(ServiceHelperConfiguration configuration, String wsdlUri) {
|
||||
this.configuration = configuration;
|
||||
this.httpClient = createHttpClient();
|
||||
this.wsdlUri = wsdlUri;
|
||||
inputStreams = new HashSet<InputStream>();
|
||||
}
|
||||
|
||||
public InputSource getBaseInputSource() {
|
||||
GetMethod get = createGetMethod(wsdlUri);
|
||||
try {
|
||||
httpClient.executeMethod(get);
|
||||
InputStream is = get.getResponseBodyAsStream();
|
||||
inputStreams.add(is);
|
||||
return new InputSource(is);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public InputSource getImportInputSource(String parentLocation, String importLocation) {
|
||||
try {
|
||||
URL url = getURL(parentLocation, importLocation);
|
||||
latestImportUri = url.toExternalForm();
|
||||
GetMethod get = createGetMethod(latestImportUri);
|
||||
httpClient.executeMethod(get);
|
||||
InputStream is = get.getResponseBodyAsStream();
|
||||
inputStreams.add(is);
|
||||
return new InputSource(is);
|
||||
} catch (MalformedURLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static URL getURL(String parentLocation, String wsdlLocation) throws MalformedURLException {
|
||||
URL contextURL = (parentLocation != null) ? getURL(null, parentLocation) : null;
|
||||
try {
|
||||
return new URL(contextURL, wsdlLocation);
|
||||
} catch (MalformedURLException e) {
|
||||
File tempFile = new File(wsdlLocation);
|
||||
if (contextURL == null || (contextURL != null && tempFile.isAbsolute())) {
|
||||
return tempFile.toURI().toURL();
|
||||
}
|
||||
// this line is reached if contextURL != null, wsdlLocation is a relative path,
|
||||
// and a MalformedURLException has been thrown - so re-throw the Exception.
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public String getBaseURI() {
|
||||
return wsdlUri;
|
||||
}
|
||||
|
||||
public String getLatestImportURI() {
|
||||
return latestImportUri;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
for (InputStream is : inputStreams) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(WSDLLocatorImpl.class.getName()).log(Level.WARNING, null, ex);
|
||||
}
|
||||
}
|
||||
inputStreams.clear();
|
||||
}
|
||||
|
||||
private GetMethod createGetMethod(String uri) {
|
||||
GetMethod get = new GetMethod(uri);
|
||||
if (configuration.getCookie() != null) {
|
||||
get.setRequestHeader(HTTP_HEADER_COOKIE, configuration.getCookie());
|
||||
}
|
||||
|
||||
return get;
|
||||
}
|
||||
|
||||
private HttpClient createHttpClient() {
|
||||
HttpClient httpClient = new HttpClient();
|
||||
if (configuration.getProxyServer() != null) {
|
||||
HostConfiguration hostConfiguration = new HostConfiguration();
|
||||
hostConfiguration.setProxy(configuration.getProxyServer(), configuration.getProxyPort());
|
||||
httpClient.setHostConfiguration(hostConfiguration);
|
||||
}
|
||||
|
||||
if (configuration.getUsername() != null) {
|
||||
Credentials credentials = new UsernamePasswordCredentials(configuration.getUsername(), configuration.getPassword());
|
||||
|
||||
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
|
||||
}
|
||||
|
||||
if (configuration.getProxyUsername() != null) {
|
||||
Credentials credentials = new UsernamePasswordCredentials(configuration.getProxyUsername(),
|
||||
configuration.getProxyPassword());
|
||||
|
||||
httpClient.getState().setProxyCredentials(AuthScope.ANY, credentials);
|
||||
httpClient.getHostConfiguration().setProxy(configuration.getProxyServer(), configuration.getProxyPort());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.helper.map;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.talend.webservice.helper.PathUtil;
|
||||
import org.talend.webservice.mapper.AnyTypeMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class MapConverter {
|
||||
|
||||
public static final String SEPARATOR = ".";
|
||||
public static final String LEFT_SQUARE_BRACKET = "[";
|
||||
public static final String RIGHT_SQUARE_BRACKET = "]";
|
||||
|
||||
public static Map<String, Object> deepMapToMap(Map<String, Object> map) {
|
||||
return deepMapToMap(map, null, SEPARATOR);
|
||||
}
|
||||
|
||||
public static Map<String, Object> mapToDeepMap(Map<String, Object> map) {
|
||||
return mapToDeepMap(map, SEPARATOR);
|
||||
}
|
||||
|
||||
private static Map<String, Object> deepMapToMap(Object value, String k, String sep) {
|
||||
if (value instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
Map<String, Object> out = new HashMap<String, Object>();
|
||||
for (Map.Entry<String, Object> entry : map.entrySet()) {
|
||||
if (k == null) {
|
||||
out.putAll(deepMapToMap(entry.getValue(), entry.getKey(), sep));
|
||||
} else {
|
||||
out.putAll(deepMapToMap(entry.getValue(), k + sep + entry.
|
||||
getKey(), sep));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
} else if (value instanceof List) {
|
||||
List<Object> list = (List<Object>) value;
|
||||
Map<String, Object> out = new HashMap<String, Object>();
|
||||
int i = 0;
|
||||
for (Object val : list) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(k).append(LEFT_SQUARE_BRACKET).append(i).append(RIGHT_SQUARE_BRACKET);
|
||||
out.putAll(deepMapToMap(val, sb.toString(), sep));
|
||||
i++;
|
||||
}
|
||||
out.put(k + ".size", list.size());
|
||||
return out;
|
||||
} else {
|
||||
if (k == null) {
|
||||
throw new IllegalArgumentException("value must be a map or you must provide a key name");
|
||||
} else {
|
||||
Map<String, Object> out = new HashMap<String, Object>(1);
|
||||
out.put(k, value);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, Object> mapToDeepMap(Map<String, Object> in, String sep) {
|
||||
Map<String, Object> out = new HashMap<String, Object>();
|
||||
Map<String, Map<String, Object>> stack = new HashMap<String, Map<String, Object>>();
|
||||
|
||||
Map<String, List<Object>> listStack = new HashMap<String, List<Object>>();
|
||||
|
||||
for (Map.Entry<String, Object> entry : in.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
int pos = PathUtil.indexOfPath(key, sep);
|
||||
if (pos == -1) {
|
||||
int index = getIndexOfKey(key);
|
||||
if (index == -1) {
|
||||
processAnyType(out,key,entry.getValue(),null);
|
||||
} else {
|
||||
String listName = key.substring(0, key.indexOf(LEFT_SQUARE_BRACKET));
|
||||
List<Object> list = listStack.get(listName);
|
||||
if (list == null) {
|
||||
list = new ArrayList<Object>();
|
||||
listStack.put(listName, list);
|
||||
}
|
||||
if (index < list.size()) {
|
||||
list.set(index, entry.getValue());
|
||||
} else {
|
||||
for (int i = list.size(); i < index; i++) {
|
||||
list.add(null);
|
||||
}
|
||||
list.add(entry.getValue());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String k = key.substring(0, pos);
|
||||
int index = getIndexOfKey(k);
|
||||
String subK = key.substring(pos + sep.length());
|
||||
if (index == -1) {
|
||||
Map<String, Object> stackVal = stack.get(k);
|
||||
if (stackVal == null) {
|
||||
stackVal = new HashMap<String, Object>();
|
||||
stack.put(k, stackVal);
|
||||
}
|
||||
stackVal.put(subK, entry.getValue());
|
||||
} else {
|
||||
String listName = k.substring(0, k.indexOf(LEFT_SQUARE_BRACKET));
|
||||
List<Object> list = listStack.get(listName);
|
||||
if (list == null) {
|
||||
list = new ArrayList<Object>();
|
||||
listStack.put(listName, list);
|
||||
}
|
||||
Map<String, Object> lmap = null;
|
||||
if (index < list.size()) {
|
||||
lmap = (Map<String, Object>) list.get(index);
|
||||
if (lmap == null) {
|
||||
lmap = new HashMap<String, Object>();
|
||||
list.set(index, lmap);
|
||||
}
|
||||
} else {
|
||||
for (int i = list.size(); i < index; i++) {
|
||||
list.add(null);
|
||||
}
|
||||
list.add(new HashMap<String, Object>());
|
||||
lmap = (Map<String, Object>) list.get(index);
|
||||
}
|
||||
|
||||
lmap.put(subK, entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, Map<String, Object>> entry : stack.entrySet()) {
|
||||
processAnyType(out,entry.getKey(),mapToDeepMap(entry.getValue(), sep),null);
|
||||
}
|
||||
for (Map.Entry<String, List<Object>> entry : listStack.entrySet()) {
|
||||
List<Object> values = new ArrayList<Object>(entry.getValue().size());
|
||||
for (Object val : entry.getValue()) {
|
||||
if (val instanceof Map) {
|
||||
values.add(mapToDeepMap((Map<String, Object>) val, sep));
|
||||
} else {
|
||||
values.add(val);
|
||||
}
|
||||
}
|
||||
|
||||
processAnyType(out,entry.getKey(),null,values);
|
||||
}
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
private static void processAnyType(Map<String,Object> out,String key,Object value,List<Object> values) {
|
||||
int i = key.indexOf(AnyTypeMapper.ANYTYPE_PREFIX);
|
||||
|
||||
String namespace = null;
|
||||
String localnameOfType = null;
|
||||
|
||||
if(i!=-1) {
|
||||
int j = key.indexOf(",");
|
||||
namespace = key.substring(key.indexOf("{")+1,j);
|
||||
localnameOfType = key.substring(j+1,key.indexOf("}"));
|
||||
key = key.substring(0,i);
|
||||
}
|
||||
|
||||
if(values!=null) {
|
||||
if(i!=-1) {
|
||||
for(int k=0;k<values.size();k++) {
|
||||
Map<String,Object> anyTypeValue = new HashMap<String,Object>();
|
||||
anyTypeValue.put(AnyTypeMapper.ANYTYPE_TYPE,new QName(namespace,localnameOfType));
|
||||
anyTypeValue.put(AnyTypeMapper.ANYTYPE_VALUE,values.get(k));
|
||||
|
||||
values.set(k, anyTypeValue);
|
||||
}
|
||||
}
|
||||
|
||||
out.put(key, values);
|
||||
} else {
|
||||
if(i == -1) {
|
||||
out.put(key, value);
|
||||
} else {
|
||||
Map<String,Object> anyTypeValue = new HashMap<String,Object>();
|
||||
anyTypeValue.put(AnyTypeMapper.ANYTYPE_TYPE,new QName(namespace,localnameOfType));
|
||||
anyTypeValue.put(AnyTypeMapper.ANYTYPE_VALUE,value);
|
||||
|
||||
out.put(key, anyTypeValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static int getIndexOfKey(String key) {
|
||||
int lpos = key.indexOf(LEFT_SQUARE_BRACKET);
|
||||
if (lpos == -1) {
|
||||
return -1;
|
||||
} else {
|
||||
int rpos = key.indexOf(RIGHT_SQUARE_BRACKET);
|
||||
if (rpos != key.length() - 1) {
|
||||
return -1;
|
||||
} else {
|
||||
if (rpos - lpos > 1) {
|
||||
String strVal = key.substring(lpos + 1, rpos);
|
||||
|
||||
try {
|
||||
return Integer.valueOf(strVal);
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,142 @@
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.namespace.QName;
|
||||
import javax.xml.transform.Result;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerConfigurationException;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.TransformerFactoryConfigurationError;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.talend.webservice.exception.IllegalPropertyAccessException;
|
||||
import org.talend.webservice.exception.InvocationTargetPropertyAccessor;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
public class AnyPropertyMapper implements PropertyMapper {
|
||||
|
||||
public static String LABEL = "_content_";
|
||||
|
||||
private MapperFactory mapperFactory;
|
||||
|
||||
private TypeMapper xmlBeanMapper;
|
||||
|
||||
private String propertyName;
|
||||
|
||||
private final String AnyPropertyName = "any";
|
||||
|
||||
private final String AnyContentPropertyName = "content";
|
||||
|
||||
private PropertyDescriptor propertyDescriptor;
|
||||
|
||||
private QName schemaTypeQName;
|
||||
|
||||
public AnyPropertyMapper(Class<?> clazz, MapperFactory mapperFactory) throws LocalizedException {
|
||||
this.mapperFactory = mapperFactory;
|
||||
|
||||
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz);
|
||||
for (PropertyDescriptor descriptor : descriptors) {
|
||||
if (AnyPropertyName.equalsIgnoreCase(descriptor.getName())
|
||||
|| AnyContentPropertyName.equalsIgnoreCase(descriptor.getName())) {
|
||||
this.propertyName = descriptor.getName();
|
||||
propertyDescriptor = descriptor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propertyDescriptor == null) {
|
||||
throw new IllegalArgumentException("Unable to get propertyDescriptor for bean " + clazz.getName() + " and property "
|
||||
+ propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public String getMappedPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setValueTo(Object destination, Object value) throws LocalizedException {
|
||||
try {
|
||||
Method method = propertyDescriptor.getWriteMethod();
|
||||
if (method.getParameterTypes()[0].equals(JAXBElement.class)) {
|
||||
value = new JAXBElement(new QName(getMappedPropertyName()), getMappedClass(), value);
|
||||
propertyDescriptor.getWriteMethod().invoke(destination, value);
|
||||
} else {
|
||||
propertyDescriptor.getWriteMethod().invoke(destination, value);
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new IllegalPropertyAccessException(propertyDescriptor.getName(), destination.getClass().getName(), ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new InvocationTargetPropertyAccessor(propertyDescriptor.getName(), destination.getClass().getName(), ex
|
||||
.getTargetException());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValueFrom(Object source) throws LocalizedException {
|
||||
try {
|
||||
Method method = propertyDescriptor.getReadMethod();
|
||||
String value = "";
|
||||
if (method.getReturnType().equals(java.util.List.class)) {
|
||||
List<Element> anyList = (List<Element>) propertyDescriptor.getReadMethod().invoke(source);
|
||||
for (Element child : anyList) {
|
||||
Document doc = child.getOwnerDocument();
|
||||
DOMSource domSource = new DOMSource(doc);
|
||||
StringWriter writer = new StringWriter();
|
||||
Result result = new StreamResult(writer);
|
||||
Transformer transformer;
|
||||
try {
|
||||
TransformerFactory transFactory = TransformerFactory.newInstance();
|
||||
transFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
|
||||
transformer = transFactory.newTransformer();
|
||||
transformer.transform(domSource, result);
|
||||
} catch (TransformerConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (TransformerFactoryConfigurationError e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (TransformerException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
value += writer.getBuffer().toString();
|
||||
}
|
||||
return value;
|
||||
} else {
|
||||
// shouldn't be there.
|
||||
return null;
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new IllegalPropertyAccessException(propertyDescriptor.getName(), source.getClass().getName(), ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new InvocationTargetPropertyAccessor(propertyDescriptor.getName(), source.getClass().getName(), ex
|
||||
.getTargetException());
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getMappedClass() {
|
||||
return xmlBeanMapper.getClazz();
|
||||
}
|
||||
|
||||
public Object createProperty(Object value) throws LocalizedException {
|
||||
xmlBeanMapper = mapperFactory.typeMappers.get(schemaTypeQName);
|
||||
return xmlBeanMapper.convertToType(value);
|
||||
}
|
||||
|
||||
public Object createValue(Object property) throws LocalizedException {
|
||||
xmlBeanMapper = mapperFactory.typeMappers.get(schemaTypeQName);
|
||||
return xmlBeanMapper.typeToValue(property);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.ws.commons.schema.XmlSchemaType;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class AnyTypeMapper implements TypeMapper {
|
||||
|
||||
public static final String ANYTYPE_VALUE = "anyType";
|
||||
|
||||
public static final String ANYTYPE_TYPE = "anyType_type";
|
||||
|
||||
public static final String ANYTYPE_PREFIX = ":anyType";
|
||||
|
||||
private MapperFactory mapperFactory;
|
||||
|
||||
private Map<QName, TypeMapper> mappers = new HashMap<QName, TypeMapper>();
|
||||
|
||||
private TypeMapper lastTypeMapper = null;
|
||||
|
||||
public AnyTypeMapper(MapperFactory mapperFactory) {
|
||||
this.mapperFactory = mapperFactory;
|
||||
}
|
||||
|
||||
public Class<?> getClazz() {
|
||||
if (lastTypeMapper != null) {
|
||||
return lastTypeMapper.getClazz();
|
||||
} else {
|
||||
return Object.class;
|
||||
}
|
||||
}
|
||||
|
||||
public Object convertToType(Object value) throws LocalizedException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!(value instanceof Map)) {
|
||||
throw new LocalizedException("org.talend.ws.exception.InvalidParameterAnyType");
|
||||
}
|
||||
Map<String, Object> map = (Map<String, Object>) value;
|
||||
|
||||
value = map.get(ANYTYPE_VALUE);
|
||||
if (value == null) {
|
||||
throw new LocalizedException("org.talend.ws.exception.InvalidParameterAnyType");
|
||||
}
|
||||
|
||||
Object typeValue = map.get(ANYTYPE_TYPE);
|
||||
if (typeValue == null || !(typeValue instanceof QName)) {
|
||||
throw new LocalizedException("org.talend.ws.exception.InvalidParameterAnyType");
|
||||
}
|
||||
|
||||
QName type = (QName) typeValue;
|
||||
lastTypeMapper = getTypeMapper(type);
|
||||
if (lastTypeMapper == null) {
|
||||
throw new IllegalArgumentException("Type " + type + " is invalid.");
|
||||
}
|
||||
return lastTypeMapper.convertToType(value);
|
||||
}
|
||||
|
||||
public Object typeToValue(Object bean) throws LocalizedException {
|
||||
if (bean == null) {
|
||||
return null;
|
||||
}
|
||||
XmlSchemaType type = mapperFactory.getClassMapper().getTypeForClass(bean.getClass());
|
||||
|
||||
lastTypeMapper = getTypeMapper(type.getQName());
|
||||
if (lastTypeMapper == null) {
|
||||
throw new IllegalArgumentException("Class " + bean.getClass().getName() + " is not mapped.");
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put(ANYTYPE_TYPE, type.getQName());
|
||||
map.put(ANYTYPE_VALUE, lastTypeMapper.typeToValue(bean));
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
private TypeMapper getTypeMapper(QName type) throws LocalizedException {
|
||||
TypeMapper typeMapper = mappers.get(type);
|
||||
if (typeMapper == null) {
|
||||
XmlSchemaType xmlSchemaType = mapperFactory.getSchemaCollection().getTypeByQName(type);
|
||||
if (xmlSchemaType == null) {
|
||||
throw new IllegalArgumentException("Unsupported schema type : " + type);
|
||||
}
|
||||
|
||||
typeMapper = mapperFactory.createTypeMapper(xmlSchemaType);
|
||||
|
||||
mappers.put(type, typeMapper);
|
||||
}
|
||||
|
||||
return typeMapper;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.ws.commons.schema.XmlSchemaType;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public interface ClassMapper {
|
||||
|
||||
public Class<?> getClassForType(QName xmlSchemaTypeMapperQName, List<String> propertiesName, int tempSuffix);
|
||||
|
||||
public Class<?> getClassForType(QName xmlSchemaTypeMapperQName);
|
||||
|
||||
public XmlSchemaType getTypeForClass(Class<?> clazz);
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class ComplexTypeMapper implements TypeMapper {
|
||||
|
||||
private Map<String, PropertyMapper> mappers;
|
||||
|
||||
private Class<?> clazz;
|
||||
|
||||
private List<String> propertiesOrder;
|
||||
|
||||
private Map<QName, ComplexTypeMapper> instanceComplexTypeMapper;
|
||||
|
||||
private boolean hasInstance = false;
|
||||
|
||||
private QName typeName = null;
|
||||
|
||||
private final String ABSTRACT_TYPE_NAME = "@type";
|
||||
|
||||
public boolean hasInstance() {
|
||||
return hasInstance;
|
||||
}
|
||||
|
||||
protected ComplexTypeMapper(Map<String, PropertyMapper> mappers, Class<?> clazz, List<String> propertiesOrder, QName typeName) {
|
||||
this.mappers = mappers;
|
||||
this.clazz = clazz;
|
||||
this.propertiesOrder = propertiesOrder;
|
||||
this.typeName = typeName;
|
||||
}
|
||||
|
||||
public void setInstanceComplexTypeMapper(Map<QName, ComplexTypeMapper> instanceComplexTypeMapper) {
|
||||
if (instanceComplexTypeMapper != null) {
|
||||
this.instanceComplexTypeMapper = instanceComplexTypeMapper;
|
||||
hasInstance = true;
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public Object convertToType(Object value) throws LocalizedException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (hasInstance) {
|
||||
if (value instanceof Map) {
|
||||
Map<String, Object> values = (Map<String, Object>) value;
|
||||
if (values.containsKey(ABSTRACT_TYPE_NAME)) {
|
||||
QName type = (QName) values.get(ABSTRACT_TYPE_NAME);
|
||||
ComplexTypeMapper instanceComplexTypeMapper = findInstanceByQName(type);
|
||||
if (instanceComplexTypeMapper != null) {
|
||||
return instanceComplexTypeMapper.convertToType(values.get(instanceComplexTypeMapper.typeName
|
||||
.getLocalPart()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Object bean = null;
|
||||
try {
|
||||
bean = clazz.newInstance();
|
||||
} catch (InstantiationException ex) {
|
||||
throw new RuntimeException("Unable to instantiate bean of type " + clazz.getName(), ex);
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new RuntimeException("Unable to instantiate bean of type " + clazz.getName(), ex);
|
||||
}
|
||||
|
||||
if (!(value instanceof Map)) {
|
||||
if (mappers.get("value") != null && mappers.get("value") instanceof SimpleContentPropertyMapper) {
|
||||
PropertyMapper propertyMapper = mappers.get("value");
|
||||
|
||||
if (propertyMapper != null) {
|
||||
propertyMapper.setValueTo(bean, value);
|
||||
} else {
|
||||
// TODO log a warning ?
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("You must provide a Map to create a complexType.");
|
||||
}
|
||||
} else {
|
||||
Map<String, Object> values = (Map<String, Object>) value;
|
||||
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
PropertyMapper propertyMapper = mappers.get(entry.getKey());
|
||||
|
||||
if (propertyMapper != null) {
|
||||
propertyMapper.setValueTo(bean, entry.getValue());
|
||||
} else {
|
||||
// TODO log a warning ?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bean;
|
||||
}
|
||||
|
||||
public ComplexTypeMapper findInstanceByQName(QName typeQName) {
|
||||
ComplexTypeMapper complexTypeMapper = instanceComplexTypeMapper.get(typeQName);
|
||||
if (complexTypeMapper != null) {
|
||||
return complexTypeMapper;
|
||||
} else {
|
||||
for (ComplexTypeMapper childComplexTypeMapper : instanceComplexTypeMapper.values()) {
|
||||
if (childComplexTypeMapper.hasInstance()) {
|
||||
ComplexTypeMapper iComplexTypeMapper = childComplexTypeMapper.findInstanceByQName(typeQName);
|
||||
if (iComplexTypeMapper != null) {
|
||||
return iComplexTypeMapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ComplexTypeMapper findInstanceByClassName(String className) {
|
||||
for (ComplexTypeMapper complexTypeMapper : instanceComplexTypeMapper.values()) {
|
||||
if (complexTypeMapper.getClazz().getName().equals(className)) {
|
||||
return complexTypeMapper;
|
||||
} else if (complexTypeMapper.hasInstance()) {
|
||||
ComplexTypeMapper iComplexTypeMapper = complexTypeMapper.findInstanceByClassName(className);
|
||||
if (iComplexTypeMapper != null) {
|
||||
return iComplexTypeMapper;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object typeToValue(Object bean) throws LocalizedException {
|
||||
if (bean == null) {
|
||||
return null;
|
||||
} else {
|
||||
if (!clazz.isInstance(bean)) {
|
||||
throw new IllegalArgumentException("You must provide an object of type specified by property clazz.");
|
||||
}
|
||||
if (hasInstance) {
|
||||
String beanName = bean.getClass().getName();
|
||||
if (!clazz.getName().equals(beanName)) {
|
||||
ComplexTypeMapper instanceComplexTypeMapper = findInstanceByClassName(beanName);
|
||||
if (instanceComplexTypeMapper != null) {
|
||||
Map<String, Object> values = new HashMap<String, Object>();
|
||||
values.put(ABSTRACT_TYPE_NAME, instanceComplexTypeMapper.typeName);
|
||||
values.put(instanceComplexTypeMapper.typeName.getLocalPart(), instanceComplexTypeMapper.typeToValue(bean));
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mappers.get("value") != null && mappers.get("value") instanceof SimpleContentPropertyMapper) {
|
||||
PropertyMapper propertyMapper = mappers.get("value");
|
||||
if (propertyMapper != null) {
|
||||
return propertyMapper.getValueFrom(bean);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
Map<String, Object> values = new HashMap<String, Object>(mappers.size());
|
||||
for (Map.Entry<String, PropertyMapper> entry : mappers.entrySet()) {
|
||||
Object value = entry.getValue().getValueFrom(bean);
|
||||
if (value != null) {
|
||||
values.put(entry.getKey(), value);
|
||||
}
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object[] convertToTypeUnwrapped(Map<String, Object> values) throws LocalizedException {
|
||||
Object[] objects = new Object[propertiesOrder.size()];
|
||||
int i = 0;
|
||||
for (String property : propertiesOrder) {
|
||||
Object value = values.get(property);
|
||||
if (value != null) {
|
||||
PropertyMapper propertyMapper = mappers.get(property);
|
||||
objects[i] = propertyMapper.createProperty(value);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
return objects;
|
||||
}
|
||||
|
||||
public Map<String, Object> typeToValueUnwrapped(Object[] params) throws LocalizedException {
|
||||
if (params == null) {
|
||||
return null;
|
||||
}
|
||||
Map<String, Object> values = new HashMap<String, Object>(mappers.size());
|
||||
|
||||
int i = 0;
|
||||
for (Object param : params) {
|
||||
if (i >= propertiesOrder.size()) {
|
||||
throw new IllegalArgumentException("Too much params.");
|
||||
}
|
||||
String property = propertiesOrder.get(i);
|
||||
PropertyMapper propertyMapper = mappers.get(property);
|
||||
values.put(property, propertyMapper.createValue(param));
|
||||
i++;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.wsdl.Message;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class EmptyMessageMapper implements MessageMapper {
|
||||
|
||||
public Message getMessage() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object[] convertToParams(Object value) throws LocalizedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Map<String, Object> convertToValue(Object[] params) throws LocalizedException {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isUnwrapped() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setUnwrapped(boolean unwrapped) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.talend.webservice.exception.InvalidEnumValueException;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class EnumTypeMapper implements TypeMapper {
|
||||
|
||||
private Class<?> clazz;
|
||||
|
||||
private Method value;
|
||||
|
||||
private Method fromValue;
|
||||
|
||||
public EnumTypeMapper(Class<?> clazz) {
|
||||
if (!clazz.isEnum()) {
|
||||
throw new IllegalArgumentException("You must provide an enum class.");
|
||||
}
|
||||
this.clazz = clazz;
|
||||
try {
|
||||
this.fromValue = clazz.getMethod("fromValue", String.class);
|
||||
this.value = clazz.getMethod("value");
|
||||
} catch (NoSuchMethodException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
} catch (SecurityException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public Object convertToType(Object value) throws LocalizedException {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!clazz.isInstance(value)) {
|
||||
String str = ConvertUtils.convert(value);
|
||||
try {
|
||||
return fromValue.invoke(null, str);// bug 13000
|
||||
// return valueOf.invoke(null, str);
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new LocalizedException("org.talend.ws.exception.illegalAccessValueOf", new String[] { clazz.getName() }, ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
if (ex.getTargetException() instanceof IllegalArgumentException) {
|
||||
throw new InvalidEnumValueException(str, clazz.getName());
|
||||
} else {
|
||||
throw new LocalizedException("org.talend.ws.exception.Unknown", ex.getTargetException());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public Object typeToValue(Object bean) throws LocalizedException {
|
||||
if (bean == null) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return value.invoke(bean); // bug 13000
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.talend.webservice.exception.IllegalPropertyAccessException;
|
||||
import org.talend.webservice.exception.InvocationTargetPropertyAccessor;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class ListPropertyMapper implements PropertyMapper {
|
||||
|
||||
private Map<QName, TypeMapper> schemaTypeMap;
|
||||
|
||||
private TypeMapper xmlBeanMapper;
|
||||
|
||||
private String propertyName;
|
||||
|
||||
private PropertyDescriptor propertyDescriptor;
|
||||
|
||||
private QName schemaTypeQName;
|
||||
|
||||
public ListPropertyMapper(Class<?> clazz, QName typeQName, String propertyName, Map<QName, TypeMapper> schemaTypeMap) {
|
||||
this.schemaTypeMap = schemaTypeMap;
|
||||
this.schemaTypeQName = typeQName;
|
||||
|
||||
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz);
|
||||
for (PropertyDescriptor descriptor : descriptors) {
|
||||
if (propertyName.equalsIgnoreCase(descriptor.getName())) {
|
||||
this.propertyName = descriptor.getName();
|
||||
propertyDescriptor = descriptor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propertyDescriptor == null) {
|
||||
throw new IllegalArgumentException("Unable to get propertyDescriptor for bean " + typeQName + " and property "
|
||||
+ propertyName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Class<?> getMappedClass() {
|
||||
return xmlBeanMapper.getClazz();
|
||||
}
|
||||
|
||||
public String getMappedPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setValueTo(Object destination, Object value) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
if (value == null) {
|
||||
return;
|
||||
}
|
||||
List values;
|
||||
if (value instanceof List) {
|
||||
values = (List) value;
|
||||
} else {
|
||||
values = Arrays.asList(value);
|
||||
}
|
||||
|
||||
List target;
|
||||
try {
|
||||
target = (List) propertyDescriptor.getReadMethod().invoke(destination);
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new IllegalPropertyAccessException(propertyDescriptor.getName(), destination.getClass().getName(), ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new InvocationTargetPropertyAccessor(propertyDescriptor.getName(), destination.getClass().getName(), ex);
|
||||
}
|
||||
|
||||
for (Object val : values) {
|
||||
target.add(xmlBeanMapper.convertToType(val));
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValueFrom(Object source) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
List values;
|
||||
try {
|
||||
values = (List) propertyDescriptor.getReadMethod().invoke(source);
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new IllegalPropertyAccessException(propertyDescriptor.getName(), source.getClass().getName(), ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new InvocationTargetPropertyAccessor(propertyDescriptor.getName(), source.getClass().getName(), ex);
|
||||
}
|
||||
|
||||
List newValues = new ArrayList(values.size());
|
||||
for (Object value : values) {
|
||||
newValues.add(xmlBeanMapper.typeToValue(value));
|
||||
}
|
||||
|
||||
return newValues;
|
||||
}
|
||||
|
||||
public Object createProperty(Object value) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
List values;
|
||||
if (value instanceof List) {
|
||||
values = (List) value;
|
||||
} else {
|
||||
values = Arrays.asList(value);
|
||||
}
|
||||
|
||||
List property = new ArrayList(values.size());
|
||||
for (Object val : values) {
|
||||
property.add(xmlBeanMapper.convertToType(val));
|
||||
}
|
||||
|
||||
return property;
|
||||
}
|
||||
|
||||
public Object createValue(Object property) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
if (property == null) {
|
||||
return null;
|
||||
}
|
||||
if (!(property instanceof List)) {
|
||||
if (!(property instanceof Object[])) {// treat Object[] as List ,bug for 9900 (wrap webservice)
|
||||
throw new IllegalArgumentException("You must provide a list of properties");
|
||||
}// end
|
||||
}
|
||||
List<Object> properties = null;
|
||||
if (property instanceof Object[]) {// treat Object[] as List ,bug for 9900 (wrap webservice)
|
||||
Object[] os = (Object[]) property;
|
||||
properties = Arrays.asList(os);
|
||||
} else {// end
|
||||
properties = (List<Object>) property;
|
||||
}
|
||||
List<Object> values = new ArrayList<Object>(properties.size());
|
||||
|
||||
for (Object prop : properties) {
|
||||
values.add(xmlBeanMapper.typeToValue(prop));
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,567 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.wsdl.Message;
|
||||
import javax.wsdl.Part;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.commons.collections.map.ListOrderedMap;
|
||||
import org.apache.ws.commons.schema.XmlSchema;
|
||||
import org.apache.ws.commons.schema.XmlSchemaAll;
|
||||
import org.apache.ws.commons.schema.XmlSchemaAny;
|
||||
import org.apache.ws.commons.schema.XmlSchemaChoice;
|
||||
import org.apache.ws.commons.schema.XmlSchemaCollection;
|
||||
import org.apache.ws.commons.schema.XmlSchemaComplexContent;
|
||||
import org.apache.ws.commons.schema.XmlSchemaComplexContentExtension;
|
||||
import org.apache.ws.commons.schema.XmlSchemaComplexContentRestriction;
|
||||
import org.apache.ws.commons.schema.XmlSchemaComplexType;
|
||||
import org.apache.ws.commons.schema.XmlSchemaContent;
|
||||
import org.apache.ws.commons.schema.XmlSchemaContentModel;
|
||||
import org.apache.ws.commons.schema.XmlSchemaElement;
|
||||
import org.apache.ws.commons.schema.XmlSchemaEnumerationFacet;
|
||||
import org.apache.ws.commons.schema.XmlSchemaFacet;
|
||||
import org.apache.ws.commons.schema.XmlSchemaGroupParticle;
|
||||
import org.apache.ws.commons.schema.XmlSchemaGroupRef;
|
||||
import org.apache.ws.commons.schema.XmlSchemaObject;
|
||||
import org.apache.ws.commons.schema.XmlSchemaParticle;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSequence;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSequenceMember;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleContent;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleContentExtension;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleContentRestriction;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleType;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeContent;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeList;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeRestriction;
|
||||
import org.apache.ws.commons.schema.XmlSchemaSimpleTypeUnion;
|
||||
import org.apache.ws.commons.schema.XmlSchemaType;
|
||||
import org.apache.ws.commons.schema.utils.XmlSchemaObjectBase;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
import org.talend.webservice.jaxb.JAXBUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class MapperFactory {
|
||||
|
||||
private static final Map<String, String> BUILTIN_DATATYPES_MAP;
|
||||
|
||||
private static final Map<String, String> BUILTIN_DATATYPES_MAP_REVERSE;
|
||||
|
||||
private static final String W3C_XML_SCHEMA_URI = "http://www.w3.org/2001/XMLSchema";
|
||||
|
||||
private static final String W3C_XML_SCHEMA_DATETYPES_URI = "http://www.w3.org/2001/XMLSchema-datatypes";
|
||||
|
||||
private static final QName ANYTYPE_QNAME = new QName(W3C_XML_SCHEMA_URI, "anyType");
|
||||
|
||||
private static String byteArrayName = new byte[0].getClass().getName();
|
||||
// refer to :http://www.w3.org/TR/xmlschema-2/
|
||||
|
||||
static {
|
||||
BUILTIN_DATATYPES_MAP = new HashMap<String, String>();
|
||||
BUILTIN_DATATYPES_MAP.put("string", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("integer", "java.math.BigInteger");
|
||||
BUILTIN_DATATYPES_MAP.put("int", "java.lang.Integer");
|
||||
BUILTIN_DATATYPES_MAP.put("long", "java.lang.Long");
|
||||
BUILTIN_DATATYPES_MAP.put("short", "java.lang.Short");
|
||||
BUILTIN_DATATYPES_MAP.put("decimal", "java.math.BigDecimal");
|
||||
BUILTIN_DATATYPES_MAP.put("float", "java.lang.Float");
|
||||
BUILTIN_DATATYPES_MAP.put("double", "java.lang.Double");
|
||||
BUILTIN_DATATYPES_MAP.put("boolean", "java.lang.Boolean");
|
||||
BUILTIN_DATATYPES_MAP.put("byte", "java.lang.Byte");
|
||||
BUILTIN_DATATYPES_MAP.put("QName", "javax.xml.namespace.QName");
|
||||
BUILTIN_DATATYPES_MAP.put("dateTime", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("base64Binary", byteArrayName);
|
||||
BUILTIN_DATATYPES_MAP.put("hexBinary", byteArrayName);
|
||||
BUILTIN_DATATYPES_MAP.put("unsignedInt", "java.lang.Long");
|
||||
BUILTIN_DATATYPES_MAP.put("unsignedShort", "java.lang.Integer");
|
||||
BUILTIN_DATATYPES_MAP.put("unsignedByte", "java.lang.Short");
|
||||
BUILTIN_DATATYPES_MAP.put("time", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("date", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("gYear", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("gYearMonth", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("gMonth", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("gMonthDay", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("gDay", "javax.xml.datatype.XMLGregorianCalendar");
|
||||
BUILTIN_DATATYPES_MAP.put("duration", "javax.xml.datatype.Duration");
|
||||
BUILTIN_DATATYPES_MAP.put("NOTATION", "javax.xml.namespace.QName");
|
||||
BUILTIN_DATATYPES_MAP.put("anyURI", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("token", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("IDREF", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("NCName", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("ENTITY", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("normalizedString", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("language", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("Name", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("NMTOKEN", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("NMTOKENS", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("ID", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("IDREFS", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("ENTITIES", "java.lang.String");
|
||||
BUILTIN_DATATYPES_MAP.put("nonPositiveInteger", "java.math.BigInteger");
|
||||
BUILTIN_DATATYPES_MAP.put("nonNegativeInteger", "java.math.BigInteger");
|
||||
BUILTIN_DATATYPES_MAP.put("negativeInteger", "java.math.BigInteger");
|
||||
BUILTIN_DATATYPES_MAP.put("positiveInteger", "java.math.BigInteger");
|
||||
BUILTIN_DATATYPES_MAP.put("unsignedLong", "java.math.BigInteger");
|
||||
|
||||
BUILTIN_DATATYPES_MAP_REVERSE = new HashMap<String, String>();
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.String", "string");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.math.BigInteger", "integer");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Integer", "int");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Long", "long");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Short", "short");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.math.BigDecimal", "decimal");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Float", "float");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Double", "double");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Boolean", "boolean");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Byte", "byte");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.namespace.QName", "QName");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "dateTime");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put(byteArrayName, "base64Binary");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put(byteArrayName, "hexBinary");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Long", "unsignedInt");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Short", "unsignedShort");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.Byte", "unsignedByte");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "time");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "date");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "gYear");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "gYearMonth");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "gMonth");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "gMonthDay");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.XMLGregorianCalendar", "gDay");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.datatype.Duration", "duration");
|
||||
BUILTIN_DATATYPES_MAP_REVERSE.put("javax.xml.namespace.QName", "NOTATION");
|
||||
// BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.String", "anyURI"); // bug13001
|
||||
// BUILTIN_DATATYPES_MAP_REVERSE.put("java.lang.String", "token"); // bug13001
|
||||
|
||||
}
|
||||
|
||||
protected ClassMapper classMapper;
|
||||
|
||||
protected XmlSchemaCollection schemaCollection;
|
||||
|
||||
// bug 13001 nested call type
|
||||
protected Map<QName, TypeMapper> typeMappers;
|
||||
|
||||
public MapperFactory(ClassMapper classMapper, XmlSchemaCollection schemaCollection) {
|
||||
this.classMapper = classMapper;
|
||||
this.schemaCollection = schemaCollection;
|
||||
this.typeMappers = new HashMap<QName, TypeMapper>();
|
||||
}
|
||||
|
||||
public XmlSchemaCollection getSchemaCollection() {
|
||||
return schemaCollection;
|
||||
}
|
||||
|
||||
public ClassMapper getClassMapper() {
|
||||
return classMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the message mapper or null if the message does not have any parts or is null
|
||||
*
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public MessageMapper createMessageMapper(Message message) throws LocalizedException {
|
||||
if (message == null) {
|
||||
return new EmptyMessageMapper();
|
||||
}
|
||||
|
||||
Map<String, Part> parts = message.getParts();
|
||||
if (parts == null || parts != null && parts.size() == 0) {
|
||||
return new EmptyMessageMapper();
|
||||
} else {
|
||||
Map<String, TypeMapper> mappers = new HashMap<String, TypeMapper>(parts.size());
|
||||
|
||||
for (Map.Entry<String, Part> entry : parts.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
Part part = entry.getValue();
|
||||
|
||||
XmlSchemaType xmlSchemaType = null;
|
||||
QName elementName = part.getElementName();
|
||||
if (elementName == null) {
|
||||
QName typeName = part.getTypeName();
|
||||
if (typeName == null) {
|
||||
throw new IllegalArgumentException("Unable to find type of part " + part.getName() + " for message "
|
||||
+ message.getQName());
|
||||
}
|
||||
|
||||
xmlSchemaType = schemaCollection.getTypeByQName(typeName);
|
||||
if (xmlSchemaType.getName() == null) {
|
||||
xmlSchemaType.setName(typeName.getLocalPart());
|
||||
}
|
||||
} else {
|
||||
XmlSchemaElement xmlSchemaElement = schemaCollection.getElementByQName(part.getElementName());
|
||||
xmlSchemaType = xmlSchemaElement.getSchemaType();
|
||||
if (xmlSchemaType.getName() == null) {
|
||||
xmlSchemaType.setName(xmlSchemaElement.getName());
|
||||
}
|
||||
}
|
||||
if (xmlSchemaType == null) {
|
||||
throw new IllegalArgumentException("Type " + part.getElementName() + " was not found in the schema.");
|
||||
}
|
||||
|
||||
mappers.put(name, createTypeMapper(xmlSchemaType));
|
||||
}
|
||||
|
||||
return new MessageMapperImpl(mappers, message);
|
||||
}
|
||||
}
|
||||
|
||||
protected TypeMapper createTypeMapper(XmlSchemaType xmlSchemaType) throws LocalizedException {
|
||||
if (!typeMappers.containsKey(xmlSchemaType.getQName())) {
|
||||
typeMappers.put(xmlSchemaType.getQName(), null);
|
||||
TypeMapper typeMapper = null;
|
||||
if (xmlSchemaType instanceof XmlSchemaComplexType) {
|
||||
typeMapper = createComplexTypeMapper((XmlSchemaComplexType) xmlSchemaType);
|
||||
} else if (xmlSchemaType instanceof XmlSchemaSimpleType) {
|
||||
if (ANYTYPE_QNAME.equals(xmlSchemaType.getQName())) {
|
||||
typeMapper = new AnyTypeMapper(this);
|
||||
} else {
|
||||
typeMapper = createSimpleTypeMapper((XmlSchemaSimpleType) xmlSchemaType);
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Type " + xmlSchemaType.getClass().getName() + " is not yes supported.");
|
||||
}
|
||||
typeMappers.put(xmlSchemaType.getQName(), typeMapper);
|
||||
return typeMapper;
|
||||
} else {
|
||||
return typeMappers.get(xmlSchemaType.getQName());
|
||||
}
|
||||
}
|
||||
|
||||
private TypeMapper createSimpleTypeMapper(XmlSchemaSimpleType xmlSchemaSimpleType) {
|
||||
|
||||
XmlSchemaSimpleTypeContent xmlSchemaSimpleTypeContent = xmlSchemaSimpleType.getContent();
|
||||
|
||||
QName qname = xmlSchemaSimpleType.getQName();
|
||||
String namespaceuri = qname == null ? null : qname.getNamespaceURI();
|
||||
|
||||
// simple type
|
||||
String simpleClassName = builtInTypeToJavaType(xmlSchemaSimpleType.getName());
|
||||
|
||||
if (simpleClassName != null && (W3C_XML_SCHEMA_URI.equals(namespaceuri) || W3C_XML_SCHEMA_DATETYPES_URI.equals(namespaceuri))) {
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(simpleClassName);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException("Unable to find java type " + simpleClassName, ex);
|
||||
}
|
||||
|
||||
return new SimpleTypeMapper(clazz);
|
||||
|
||||
} else if (xmlSchemaSimpleTypeContent instanceof XmlSchemaSimpleTypeList) {
|
||||
// using java.util.list to map xmlschemasimpletypelist
|
||||
// bug 13922
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName("java.util.List");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException("Unable to find java type java.util.List", ex);
|
||||
}
|
||||
|
||||
return new SimpleTypeMapper(clazz);
|
||||
} else if (xmlSchemaSimpleTypeContent instanceof XmlSchemaSimpleTypeRestriction) {
|
||||
// Enum or others
|
||||
|
||||
// bug 13001 for
|
||||
// <xsd:simpleType name="EventType">
|
||||
// <xsd:restriction base="xsd:string"/>
|
||||
// </xsd:simpleType>
|
||||
// and not enum
|
||||
// and enum have not typename,means jaxb didn't gen class for the enum without simpleType.getName
|
||||
XmlSchemaSimpleTypeRestriction xmlSchemaSimpleTypeRestriction = (XmlSchemaSimpleTypeRestriction) xmlSchemaSimpleTypeContent;
|
||||
|
||||
List<XmlSchemaFacet> facets = xmlSchemaSimpleTypeRestriction.getFacets();
|
||||
if (facets.size() > 0 && facets.get(0) instanceof XmlSchemaEnumerationFacet && xmlSchemaSimpleType.getName() != null) {
|
||||
Class<?> clazz = classMapper.getClassForType(xmlSchemaSimpleType.getQName());
|
||||
if (!clazz.isEnum()) {
|
||||
throw new IllegalArgumentException("Class " + clazz.getName() + " should be an enum.");
|
||||
}
|
||||
return new EnumTypeMapper(clazz);
|
||||
} else {
|
||||
String className = builtInTypeToJavaType(((XmlSchemaSimpleTypeRestriction) xmlSchemaSimpleTypeContent)
|
||||
.getBaseTypeName().getLocalPart());
|
||||
if (className == null) {
|
||||
throw new IllegalArgumentException("Unsupported type " + xmlSchemaSimpleType.getQName());
|
||||
}
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException("Unable to find java type " + className, ex);
|
||||
}
|
||||
return new SimpleTypeMapper(clazz);
|
||||
}
|
||||
} else if (xmlSchemaSimpleTypeContent instanceof XmlSchemaSimpleTypeUnion) {
|
||||
Class<?> clazz;
|
||||
try {
|
||||
clazz = Class.forName("java.lang.String");
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new IllegalArgumentException("Unable to find java type java.lang.String", ex);
|
||||
}
|
||||
return new SimpleTypeMapper(clazz);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported type " + xmlSchemaSimpleTypeContent.getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private ComplexTypeMapper createComplexTypeMapper(XmlSchemaComplexType xmlSchemaComplexType) throws LocalizedException {
|
||||
// 0. if that class is abstract, find the instance class
|
||||
Map<QName, ComplexTypeMapper> instanceComplexTypeMapper = null;
|
||||
if (xmlSchemaComplexType.isAbstract()) {
|
||||
instanceComplexTypeMapper = findInstance(xmlSchemaComplexType.getQName());
|
||||
}
|
||||
// 1. get the all properties from complexType
|
||||
Map<String, Object> properties = getProperties(xmlSchemaComplexType);
|
||||
|
||||
Map<String, Object> tempProperties = new ListOrderedMap();
|
||||
for (String key : properties.keySet()) {
|
||||
tempProperties.put(JAXBUtils.removePunctuation(key), properties.get(key));
|
||||
}
|
||||
properties.clear();
|
||||
properties.putAll(tempProperties);
|
||||
|
||||
// 2. get class with typeMapperQname(type Qname, element Qname, inner class Qname)
|
||||
// and use properties to check the class name(class,class1,class2)
|
||||
ListOrderedMap orderedMap = (ListOrderedMap) properties;
|
||||
Class<?> clazz = classMapper.getClassForType(xmlSchemaComplexType.getQName(), orderedMap.keyList(), 1);
|
||||
|
||||
// 3.create propertyMapper (propertyName,class,schemaTypeMap,typeMapperQname)
|
||||
Map<String, PropertyMapper> mappers = new HashMap<String, PropertyMapper>();
|
||||
for (String key : properties.keySet()) {
|
||||
Object xmlSchemaObject = properties.get(key);
|
||||
if (xmlSchemaObject == null) {
|
||||
if (AnyPropertyMapper.LABEL.equals(key)) {
|
||||
mappers.put(key, new AnyPropertyMapper(clazz, this));
|
||||
}
|
||||
} else if (xmlSchemaObject instanceof XmlSchemaElement) {
|
||||
mappers.put(key, createPropertyMapper((XmlSchemaElement) xmlSchemaObject, clazz, key));
|
||||
|
||||
} else if (xmlSchemaObject instanceof XmlSchemaType) {
|
||||
mappers.put(key, createPropertyMapper((XmlSchemaType) xmlSchemaObject, clazz, key));
|
||||
}
|
||||
}
|
||||
|
||||
// 4.create new ComplexTypeMapper
|
||||
ComplexTypeMapper complexTypeMapper = new ComplexTypeMapper(mappers, clazz, orderedMap.keyList(),
|
||||
xmlSchemaComplexType.getQName());
|
||||
if (instanceComplexTypeMapper != null && !instanceComplexTypeMapper.isEmpty()) {
|
||||
complexTypeMapper.setInstanceComplexTypeMapper(instanceComplexTypeMapper);
|
||||
}
|
||||
return complexTypeMapper;
|
||||
}
|
||||
|
||||
/**
|
||||
* DOC bchen Comment method "findInstance".
|
||||
*
|
||||
* @param qName
|
||||
* @throws LocalizedException
|
||||
*/
|
||||
private Map<QName, ComplexTypeMapper> findInstance(QName abstractQName) throws LocalizedException {
|
||||
Map<QName, ComplexTypeMapper> instanceTypeMappers = new HashMap<QName, ComplexTypeMapper>();
|
||||
XmlSchema[] xmlSchemas = schemaCollection.getXmlSchemas();
|
||||
for (XmlSchema xmlSchema : xmlSchemas) {
|
||||
Map<QName, XmlSchemaType> xmlSchemaTypes = xmlSchema.getSchemaTypes();
|
||||
for (QName key : xmlSchemaTypes.keySet()) {
|
||||
XmlSchemaType xmlSchemaType = xmlSchemaTypes.get(key);
|
||||
if (xmlSchemaType instanceof XmlSchemaComplexType) {
|
||||
XmlSchemaContentModel xmlSchemaContentModel = ((XmlSchemaComplexType) xmlSchemaType).getContentModel();
|
||||
XmlSchemaComplexContent xmlSchemaComplexContent = (XmlSchemaComplexContent) xmlSchemaContentModel;
|
||||
if (xmlSchemaContentModel instanceof XmlSchemaComplexContent) {
|
||||
XmlSchemaContent xmlSchemaContent = xmlSchemaComplexContent.getContent();
|
||||
if (xmlSchemaContent instanceof XmlSchemaComplexContentExtension) {
|
||||
XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = (XmlSchemaComplexContentExtension) xmlSchemaContent;
|
||||
if (xmlSchemaComplexContentExtension.getBaseTypeName().equals(abstractQName)) {
|
||||
instanceTypeMappers.put(xmlSchemaType.getQName(),
|
||||
(ComplexTypeMapper) createTypeMapper(xmlSchemaType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return instanceTypeMappers;
|
||||
}
|
||||
|
||||
protected PropertyMapper createPropertyMapper(XmlSchemaType xmlSchemaType, Class<?> clazz, String propertyName)
|
||||
throws LocalizedException {
|
||||
if (propertyName == null || "".equals(propertyName)) {
|
||||
propertyName = xmlSchemaType.getName();
|
||||
}
|
||||
createTypeMapper(xmlSchemaType);
|
||||
return new SimpleContentPropertyMapper(clazz, xmlSchemaType.getQName(), propertyName, typeMappers);
|
||||
}
|
||||
|
||||
protected PropertyMapper createPropertyMapper(XmlSchemaElement xmlSchemaElement, Class<?> clazz, String propertyName)
|
||||
throws LocalizedException {
|
||||
XmlSchemaType xmlSchemaType = xmlSchemaElement.getSchemaType();
|
||||
// bug 13001
|
||||
if (xmlSchemaType == null && xmlSchemaElement.getRef() != null && xmlSchemaElement.getRef().getTarget() != null) {
|
||||
xmlSchemaElement = schemaCollection.getElementByQName(xmlSchemaElement.getRef().getTargetQName());
|
||||
xmlSchemaType = xmlSchemaElement.getSchemaType();
|
||||
}
|
||||
|
||||
// bug 13001, inner class
|
||||
if (xmlSchemaType.getName() == null) {
|
||||
if (xmlSchemaType instanceof XmlSchemaComplexType) {
|
||||
String innerClassName = clazz.getName().substring(clazz.getName().lastIndexOf(".") + 1);
|
||||
innerClassName += "$";
|
||||
// innerClassName += xmlSchemaElement.getName(); inner Class name
|
||||
// should be capital first
|
||||
innerClassName += xmlSchemaElement.getName().substring(0, 1).toUpperCase()
|
||||
+ xmlSchemaElement.getName().substring(1);
|
||||
xmlSchemaType.setName(innerClassName);
|
||||
|
||||
} else {
|
||||
// The name is required if the simpleType element is a child of the
|
||||
// schema element, otherwise it is not allowed
|
||||
xmlSchemaType.setName(xmlSchemaElement.getName());
|
||||
}
|
||||
}
|
||||
|
||||
createTypeMapper(xmlSchemaType);
|
||||
|
||||
if (xmlSchemaElement.getMaxOccurs() > 1) {
|
||||
return new ListPropertyMapper(clazz, xmlSchemaType.getQName(), propertyName, typeMappers);
|
||||
} else {
|
||||
return new SimplePropertyMapper(clazz, xmlSchemaType.getQName(), propertyName, typeMappers);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> getProperties(XmlSchemaComplexType xmlSchemaComplexType) throws LocalizedException {
|
||||
Map<String, Object> mappers = new ListOrderedMap();
|
||||
XmlSchemaContentModel xmlSchemaContentModel = xmlSchemaComplexType.getContentModel();
|
||||
if (xmlSchemaContentModel == null) {
|
||||
XmlSchemaParticle xmlSchemaParticle = xmlSchemaComplexType.getParticle();
|
||||
if (xmlSchemaParticle instanceof XmlSchemaGroupParticle) {
|
||||
XmlSchemaGroupParticle xmlSchemaGroupParticle = (XmlSchemaGroupParticle) xmlSchemaParticle;
|
||||
mappers.putAll(getProperties(xmlSchemaGroupParticle));
|
||||
} else if (xmlSchemaParticle instanceof XmlSchemaGroupRef) {
|
||||
XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) xmlSchemaParticle;
|
||||
XmlSchemaGroupParticle xmlSchemaGroupRefParticle = xmlSchemaGroupRef.getParticle();
|
||||
mappers.putAll(getProperties(xmlSchemaGroupRefParticle));
|
||||
} else {
|
||||
// if(!xmlSchemaComplexType.isAbstract())
|
||||
// throw new IllegalArgumentException("unknown Content of XmlSchemaComplexType:" +
|
||||
// xmlSchemaComplexType.getQName());
|
||||
}
|
||||
} else if (xmlSchemaContentModel instanceof XmlSchemaComplexContent) {
|
||||
XmlSchemaComplexContent xmlSchemaComplexContent = (XmlSchemaComplexContent) xmlSchemaContentModel;
|
||||
XmlSchemaContent xmlSchemaContent = xmlSchemaComplexContent.getContent();
|
||||
if (xmlSchemaContent instanceof XmlSchemaComplexContentExtension) {
|
||||
XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = (XmlSchemaComplexContentExtension) xmlSchemaContent;
|
||||
XmlSchemaComplexType baseXmlSchemaComplexType = (XmlSchemaComplexType) schemaCollection
|
||||
.getTypeByQName(xmlSchemaComplexContentExtension.getBaseTypeName());
|
||||
// First, recursion on parent class (for properties order)
|
||||
mappers.putAll(getProperties(baseXmlSchemaComplexType));
|
||||
|
||||
XmlSchemaParticle xmlSchemaParticle = xmlSchemaComplexContentExtension.getParticle();
|
||||
if (xmlSchemaParticle instanceof XmlSchemaGroupParticle) {
|
||||
mappers.putAll(getProperties((XmlSchemaGroupParticle) xmlSchemaParticle));
|
||||
}
|
||||
} else if (xmlSchemaContent instanceof XmlSchemaComplexContentRestriction) {
|
||||
// TODO
|
||||
throw new IllegalArgumentException("XmlSchemaComplexContentRestriction is not yet supported.");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid XmlSchemaContent for a XmlSchemaComplexContent.");
|
||||
}
|
||||
} else if (xmlSchemaContentModel instanceof XmlSchemaSimpleContent) {
|
||||
XmlSchemaSimpleContent xmlSchemaSimpleContent = (XmlSchemaSimpleContent) xmlSchemaContentModel;
|
||||
XmlSchemaContent xmlSchemaContent = xmlSchemaSimpleContent.getContent();
|
||||
if (xmlSchemaContent instanceof XmlSchemaSimpleContentExtension) {
|
||||
XmlSchemaSimpleContentExtension xmlSchemaSimpleContentExtension = (XmlSchemaSimpleContentExtension) xmlSchemaContent;
|
||||
XmlSchemaType baseXmlSchemaType = schemaCollection.getTypeByQName(xmlSchemaSimpleContentExtension
|
||||
.getBaseTypeName());
|
||||
if (baseXmlSchemaType instanceof XmlSchemaSimpleType) {
|
||||
mappers.put("value", baseXmlSchemaType);
|
||||
} else if (baseXmlSchemaType instanceof XmlSchemaComplexType) {
|
||||
throw new IllegalArgumentException(
|
||||
"A complex type with a simple content or a simple type is expected but found:"
|
||||
+ baseXmlSchemaType.getQName());
|
||||
}
|
||||
} else if (xmlSchemaContent instanceof XmlSchemaSimpleContentRestriction) {
|
||||
XmlSchemaSimpleContentRestriction xmlSchemaSimpleContentRestriction = (XmlSchemaSimpleContentRestriction) xmlSchemaContent;
|
||||
// TODO
|
||||
throw new IllegalArgumentException("XmlSchemaSimpleContentRestriction is not yet supported.");
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid XmlSchemaContent for a XmlSchemaComplexContent.");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("unknown XmlSchemaContentModel.");
|
||||
}
|
||||
|
||||
return mappers;
|
||||
}
|
||||
|
||||
private Map<String, XmlSchemaElement> getProperties(XmlSchemaGroupParticle xmlSchemaGroupParticle) throws LocalizedException {
|
||||
Map<String, XmlSchemaElement> mappers = new ListOrderedMap();
|
||||
if (xmlSchemaGroupParticle instanceof XmlSchemaSequence) {
|
||||
XmlSchemaSequence xmlSchemaSequence = (XmlSchemaSequence) xmlSchemaGroupParticle;
|
||||
List<XmlSchemaSequenceMember> sequences = xmlSchemaSequence.getItems();
|
||||
for (XmlSchemaSequenceMember sequence : sequences) {
|
||||
mappers.putAll(getProperties(sequence));
|
||||
}
|
||||
} else if (xmlSchemaGroupParticle instanceof XmlSchemaAll) {
|
||||
XmlSchemaAll xmlSchemaAll = (XmlSchemaAll) xmlSchemaGroupParticle;
|
||||
List<XmlSchemaElement> elements = xmlSchemaAll.getItems();
|
||||
for (XmlSchemaElement element : elements) {
|
||||
mappers.put(element.getName(), element);
|
||||
}
|
||||
} else if (xmlSchemaGroupParticle instanceof XmlSchemaChoice) {
|
||||
XmlSchemaChoice xmlSchemaChoice = (XmlSchemaChoice) xmlSchemaGroupParticle;
|
||||
List<XmlSchemaObject> xmlSchemaObjects = xmlSchemaChoice.getItems();
|
||||
for (XmlSchemaObject xmlSchemaObject : xmlSchemaObjects) {
|
||||
mappers.putAll(getProperties(xmlSchemaObject));
|
||||
}
|
||||
}
|
||||
return mappers;
|
||||
}
|
||||
|
||||
private Map<String, XmlSchemaElement> getProperties(XmlSchemaObjectBase xmlSchemaObjectBase) throws LocalizedException {
|
||||
Map<String, XmlSchemaElement> mappers = new ListOrderedMap();
|
||||
|
||||
if (xmlSchemaObjectBase instanceof XmlSchemaElement) {
|
||||
XmlSchemaElement xmlSchemaElement = (XmlSchemaElement) xmlSchemaObjectBase;
|
||||
if (xmlSchemaElement.getName() == null) {
|
||||
if (xmlSchemaElement.getRefBase() != null && xmlSchemaElement.getRefBase().getTargetQName() != null) {
|
||||
mappers.put(xmlSchemaElement.getRefBase().getTargetQName().getLocalPart(), xmlSchemaElement);
|
||||
} else {
|
||||
throw new IllegalArgumentException("An Element don't defined name.");
|
||||
}
|
||||
} else {
|
||||
mappers.put(xmlSchemaElement.getName(), xmlSchemaElement);
|
||||
}
|
||||
} else if (xmlSchemaObjectBase instanceof XmlSchemaAny) { // bug 14053
|
||||
mappers.put(AnyPropertyMapper.LABEL, null);
|
||||
} else if (xmlSchemaObjectBase instanceof XmlSchemaChoice) {
|
||||
mappers.putAll(getProperties((XmlSchemaChoice) xmlSchemaObjectBase));
|
||||
} else if (xmlSchemaObjectBase instanceof XmlSchemaGroupRef) {
|
||||
XmlSchemaGroupRef xmlSchemaGroupRef = (XmlSchemaGroupRef) xmlSchemaObjectBase;
|
||||
XmlSchemaGroupParticle xmlSchemaGroupRefParticle = xmlSchemaGroupRef.getParticle();
|
||||
mappers.putAll(getProperties(xmlSchemaGroupRefParticle));
|
||||
} else if (xmlSchemaObjectBase instanceof XmlSchemaSequence) {
|
||||
mappers.putAll(getProperties((XmlSchemaSequence) xmlSchemaObjectBase));
|
||||
} else {
|
||||
throw new IllegalArgumentException("Invalid xmlSchemaObject.");
|
||||
}
|
||||
|
||||
return mappers;
|
||||
}
|
||||
|
||||
private static String builtInTypeToJavaType(String type) {
|
||||
return BUILTIN_DATATYPES_MAP.get(type);
|
||||
}
|
||||
|
||||
public static QName javaTypeToBuiltInType(String type) {
|
||||
return new QName(W3C_XML_SCHEMA_URI, BUILTIN_DATATYPES_MAP_REVERSE.get(type));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.Map;
|
||||
import javax.wsdl.Message;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
* Define the transformation between params and Message parts
|
||||
* @author rlamarche
|
||||
*/
|
||||
public interface MessageMapper {
|
||||
|
||||
/**
|
||||
* @return the targeted message
|
||||
*/
|
||||
public Message getMessage();
|
||||
|
||||
/**
|
||||
* Convert value to parts
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public Object[] convertToParams(Object value) throws LocalizedException;
|
||||
;
|
||||
|
||||
/**
|
||||
* Convert parts to value
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> convertToValue(Object[] params) throws LocalizedException;
|
||||
|
||||
public boolean isUnwrapped();
|
||||
public void setUnwrapped(boolean unwrapped);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.wsdl.Message;
|
||||
import javax.wsdl.Part;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class MessageMapperImpl implements MessageMapper {
|
||||
|
||||
/**
|
||||
* contains TypeMappers for each parts of the message
|
||||
*/
|
||||
private Map<String, TypeMapper> mappers;
|
||||
private Map<String, Integer> partsOrder;
|
||||
private Message message;
|
||||
private boolean unwrapped;
|
||||
|
||||
protected MessageMapperImpl(Map<String, TypeMapper> mappers, Message message) {
|
||||
this.mappers = mappers;
|
||||
this.message = message;
|
||||
partsOrder = new HashMap<String, Integer>(mappers.size());
|
||||
|
||||
int i = 0;
|
||||
for (Part part : (List<Part>) message.getOrderedParts(null)) {
|
||||
partsOrder.put(part.getName(), i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public Message getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public Object[] convertToParams(Object value) throws LocalizedException {
|
||||
if (value instanceof Map) {
|
||||
Map<String, Object> values = (Map<String, Object>) value;
|
||||
return convertToParams(values);
|
||||
} else if (value instanceof Object[]) {
|
||||
Object[] values = (Object[]) value;
|
||||
return convertToParams(values);
|
||||
} else {
|
||||
return convertToParams(new Object[]{value});
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] convertToParams(Map<String, Object> values) throws LocalizedException {
|
||||
if (unwrapped) {
|
||||
TypeMapper typeMapper = mappers.entrySet().iterator().next().
|
||||
getValue();
|
||||
|
||||
if (!(typeMapper instanceof ComplexTypeMapper)) {
|
||||
throw new IllegalArgumentException("This message can't be unwrapped.");
|
||||
}
|
||||
|
||||
ComplexTypeMapper complexTypeMapper = (ComplexTypeMapper) typeMapper;
|
||||
|
||||
Map.Entry<String, Object> entry = values.entrySet().iterator().next();
|
||||
if (!(entry.getValue() instanceof Map)) {
|
||||
throw new IllegalArgumentException("These params can't be unwrapped.");
|
||||
}
|
||||
return complexTypeMapper.convertToTypeUnwrapped((Map) entry.getValue());
|
||||
} else {
|
||||
Object[] params = new Object[mappers.size()];
|
||||
for (Map.Entry<String, Object> entry : values.entrySet()) {
|
||||
TypeMapper typeMapper = mappers.get(entry.getKey());
|
||||
if (typeMapper == null) {
|
||||
// TODO skip and warn ?
|
||||
} else {
|
||||
params[partsOrder.get(entry.getKey())] = typeMapper.
|
||||
convertToType(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
private Object[] convertToParams(Object[] values) throws LocalizedException {
|
||||
if (values == null) {
|
||||
return null;
|
||||
}
|
||||
if (values.length == 0) {
|
||||
return null;
|
||||
}
|
||||
if (unwrapped) {
|
||||
TypeMapper typeMapper = mappers.entrySet().iterator().next().
|
||||
getValue();
|
||||
|
||||
if (!(typeMapper instanceof ComplexTypeMapper)) {
|
||||
throw new IllegalArgumentException("This message can't be unwrapped.");
|
||||
}
|
||||
|
||||
ComplexTypeMapper complexTypeMapper = (ComplexTypeMapper) typeMapper;
|
||||
|
||||
Object value = values[0];
|
||||
if (!(value instanceof Map)) {
|
||||
throw new IllegalArgumentException("These params can't be unwrapped.");
|
||||
}
|
||||
return complexTypeMapper.convertToTypeUnwrapped((Map) value);
|
||||
} else {
|
||||
List<Part> orderedParts = message.getOrderedParts(null);
|
||||
Object[] params = new Object[orderedParts.size()];
|
||||
int i = 0;
|
||||
for (Part part : orderedParts) {
|
||||
if (i >= values.length) {
|
||||
break;
|
||||
}
|
||||
|
||||
params[i] = mappers.get(part.getName()).convertToType(values[i]);
|
||||
i++;
|
||||
}
|
||||
|
||||
return params;
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> convertToValue(Object params[]) throws LocalizedException {
|
||||
if (params == null || params != null && params.length == 0) {
|
||||
return null;
|
||||
}
|
||||
if (unwrapped) {
|
||||
Part part = (Part) message.getOrderedParts(null).get(0);
|
||||
if (part == null) {
|
||||
return null;
|
||||
}
|
||||
TypeMapper typeMapper = mappers.entrySet().iterator().next().
|
||||
getValue();
|
||||
|
||||
if (!(typeMapper instanceof ComplexTypeMapper)) {
|
||||
throw new IllegalArgumentException("This message can't be unwrapped.");
|
||||
}
|
||||
|
||||
ComplexTypeMapper complexTypeMapper = (ComplexTypeMapper) typeMapper;
|
||||
|
||||
Map<String, Object> values = complexTypeMapper.typeToValueUnwrapped(params);
|
||||
|
||||
Map<String, Object> wrappedValue = new HashMap<String, Object>(1);
|
||||
|
||||
wrappedValue.put(part.getName(), values);
|
||||
|
||||
return wrappedValue;
|
||||
} else {
|
||||
List<Part> orderedParts = message.getOrderedParts(null);
|
||||
Map<String, Object> values = new HashMap<String, Object>(params.length);
|
||||
int i = 0;
|
||||
for (Object param : params) {
|
||||
Part part = orderedParts.get(i);
|
||||
if (part == null) {
|
||||
throw new IllegalArgumentException("Too much params.");
|
||||
}
|
||||
TypeMapper typeMapper = mappers.get(part.getName());
|
||||
values.put(part.getName(), typeMapper.typeToValue(param));
|
||||
i++;
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUnwrapped() {
|
||||
return unwrapped;
|
||||
}
|
||||
|
||||
public void setUnwrapped(boolean unwrapped) {
|
||||
this.unwrapped = unwrapped;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public interface PropertyMapper {
|
||||
|
||||
public Class<?> getMappedClass();
|
||||
|
||||
public String getMappedPropertyName();
|
||||
|
||||
public void setValueTo(Object destination, Object value) throws LocalizedException;
|
||||
|
||||
public Object getValueFrom(Object source) throws LocalizedException;
|
||||
|
||||
public Object createProperty(Object value) throws LocalizedException;
|
||||
public Object createValue(Object property) throws LocalizedException;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
public class SimpleContentPropertyMapper extends SimplePropertyMapper {
|
||||
|
||||
public SimpleContentPropertyMapper(Class<?> clazz, QName typeQName, String propertyName, Map<QName, TypeMapper> schemaTypeMap)
|
||||
throws LocalizedException {
|
||||
super(clazz, typeQName, propertyName, schemaTypeMap);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import java.beans.PropertyDescriptor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.JAXBElement;
|
||||
import javax.xml.namespace.QName;
|
||||
|
||||
import org.apache.commons.beanutils.PropertyUtils;
|
||||
import org.talend.webservice.exception.IllegalPropertyAccessException;
|
||||
import org.talend.webservice.exception.InvocationTargetPropertyAccessor;
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class SimplePropertyMapper implements PropertyMapper {
|
||||
|
||||
private Map<QName, TypeMapper> schemaTypeMap;
|
||||
|
||||
private TypeMapper xmlBeanMapper;
|
||||
|
||||
private String propertyName;
|
||||
|
||||
private PropertyDescriptor propertyDescriptor;
|
||||
|
||||
private QName schemaTypeQName;
|
||||
|
||||
public SimplePropertyMapper(Class<?> clazz, QName typeQName, String propertyName, Map<QName, TypeMapper> schemaTypeMap)
|
||||
throws LocalizedException {
|
||||
this.schemaTypeMap = schemaTypeMap;
|
||||
this.schemaTypeQName = typeQName;
|
||||
PropertyDescriptor[] descriptors = PropertyUtils.getPropertyDescriptors(clazz);
|
||||
for (PropertyDescriptor descriptor : descriptors) {
|
||||
if (propertyName.equalsIgnoreCase(descriptor.getName())) {
|
||||
this.propertyName = descriptor.getName();
|
||||
propertyDescriptor = descriptor;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (propertyDescriptor == null) {
|
||||
throw new IllegalArgumentException("Unable to get propertyDescriptor for bean " + typeQName + " and property "
|
||||
+ propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public String getMappedPropertyName() {
|
||||
return propertyName;
|
||||
}
|
||||
|
||||
public void setValueTo(Object destination, Object value) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
try {
|
||||
Method method = propertyDescriptor.getWriteMethod();
|
||||
if (method == null) {
|
||||
method = propertyDescriptor.getReadMethod();
|
||||
if (method != null) {
|
||||
Object returnValue = method.invoke(destination);
|
||||
if (returnValue instanceof List) {
|
||||
List values = (List) returnValue;
|
||||
Object tempValue = xmlBeanMapper.convertToType(value);
|
||||
if (tempValue != null) {
|
||||
values.addAll((List) tempValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (method.getParameterTypes()[0].equals(JAXBElement.class)) {
|
||||
value = new JAXBElement(new QName(getMappedPropertyName()), getMappedClass(),
|
||||
xmlBeanMapper.convertToType(value));
|
||||
propertyDescriptor.getWriteMethod().invoke(destination, value);
|
||||
} else {
|
||||
propertyDescriptor.getWriteMethod().invoke(destination, xmlBeanMapper.convertToType(value));
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new IllegalPropertyAccessException(propertyDescriptor.getName(), destination.getClass().getName(), ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new InvocationTargetPropertyAccessor(propertyDescriptor.getName(), destination.getClass().getName(),
|
||||
ex.getTargetException());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public Object getValueFrom(Object source) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
try {
|
||||
Method method = propertyDescriptor.getReadMethod();
|
||||
if (method.getReturnType().equals(JAXBElement.class)) {
|
||||
JAXBElement jAXBElement = (JAXBElement) method.invoke(source);
|
||||
return xmlBeanMapper.typeToValue(jAXBElement != null ? jAXBElement.getValue() : null);
|
||||
} else {
|
||||
return xmlBeanMapper.typeToValue(propertyDescriptor.getReadMethod().invoke(source));
|
||||
}
|
||||
} catch (IllegalAccessException ex) {
|
||||
throw new IllegalPropertyAccessException(propertyDescriptor.getName(), source.getClass().getName(), ex);
|
||||
} catch (InvocationTargetException ex) {
|
||||
throw new InvocationTargetPropertyAccessor(propertyDescriptor.getName(), source.getClass().getName(),
|
||||
ex.getTargetException());
|
||||
}
|
||||
}
|
||||
|
||||
public Class<?> getMappedClass() {
|
||||
return schemaTypeMap.get(schemaTypeQName).getClazz();
|
||||
}
|
||||
|
||||
public Object createProperty(Object value) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
return xmlBeanMapper.convertToType(value);
|
||||
}
|
||||
|
||||
public Object createValue(Object property) throws LocalizedException {
|
||||
xmlBeanMapper = schemaTypeMap.get(schemaTypeQName);
|
||||
return xmlBeanMapper.typeToValue(property);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import org.talend.webservice.mapper.converter.ConvertTool;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public class SimpleTypeMapper implements TypeMapper {
|
||||
|
||||
private Class<?> clazz;
|
||||
|
||||
public SimpleTypeMapper(Class<?> clazz) {
|
||||
this.clazz = clazz;
|
||||
}
|
||||
|
||||
public Class<?> getClazz() {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
public Object convertToType(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
} else {
|
||||
// return ConvertUtils.convert(ConvertUtils.convert(value), clazz);
|
||||
return ConvertTool.convert(value, clazz);// bug13001, for date type value
|
||||
}
|
||||
}
|
||||
|
||||
public Object typeToValue(Object bean) {
|
||||
return bean;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.talend.webservice.mapper;
|
||||
|
||||
import org.talend.webservice.exception.LocalizedException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author rlamarche
|
||||
*/
|
||||
public interface TypeMapper {
|
||||
|
||||
public Class<?> getClazz();
|
||||
|
||||
public Object convertToType(Object value) throws LocalizedException;
|
||||
|
||||
public Object typeToValue(Object bean) throws LocalizedException;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package org.talend.webservice.mapper.converter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
import org.apache.commons.beanutils.converters.ByteArrayConverter;
|
||||
|
||||
public class ConvertTool {
|
||||
|
||||
static byte byteArray[] = new byte[0];
|
||||
|
||||
private static final Map<Class, Converter> converters;
|
||||
static {
|
||||
converters = new HashMap<Class, Converter>();
|
||||
converters.put(XMLGregorianCalendar.class, new XMLGregorianCalendarConverter());
|
||||
converters.put(byteArray.getClass(), new ByteArrayConverter());
|
||||
converters.put(List.class, new ListConverter());
|
||||
}
|
||||
|
||||
public static Object convert(Object value, Class clazz) {
|
||||
Converter converter = converters.get(clazz);
|
||||
if (converter != null) {
|
||||
return converter.convert(clazz, value);
|
||||
}
|
||||
|
||||
return ConvertUtils.convert(ConvertUtils.convert(value), clazz);
|
||||
}
|
||||
|
||||
private static XMLGregorianCalendar DateConverter(Object value, Class clazz) {
|
||||
if (value instanceof XMLGregorianCalendar) {
|
||||
return (XMLGregorianCalendar) value;
|
||||
} else if (value instanceof Date) {
|
||||
try {
|
||||
GregorianCalendar c = new GregorianCalendar();
|
||||
c.setTime((Date) value);
|
||||
XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
|
||||
return date;
|
||||
} catch (javax.xml.datatype.DatatypeConfigurationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
throw new ConversionException("Should be javax.xml.datatype.XMLGregorianCalendar type or java.util.Date type");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.talend.webservice.mapper.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
|
||||
public class ListConverter implements Converter {
|
||||
|
||||
public Object convert(Class type, Object value) {
|
||||
if (value == null) {
|
||||
return new ArrayList();
|
||||
}
|
||||
if (value instanceof List) {
|
||||
return value;
|
||||
} else {
|
||||
List v = new ArrayList();
|
||||
v.add(value);
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.talend.webservice.mapper.converter;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import javax.xml.datatype.DatatypeFactory;
|
||||
import javax.xml.datatype.XMLGregorianCalendar;
|
||||
|
||||
import org.apache.commons.beanutils.ConversionException;
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
|
||||
public class XMLGregorianCalendarConverter implements Converter {
|
||||
|
||||
public Object convert(Class type, Object value) {
|
||||
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (value instanceof XMLGregorianCalendar) {
|
||||
return (value);
|
||||
} else if (value instanceof Date) {
|
||||
try {
|
||||
GregorianCalendar c = new GregorianCalendar();
|
||||
c.setTime((Date) value);
|
||||
XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
|
||||
return date;
|
||||
} catch (javax.xml.datatype.DatatypeConfigurationException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
throw new ConversionException("Should be javax.xml.datatype.XMLGregorianCalendar type or java.util.Date type");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
org.talend.ws.exception.IllegalPropertyAccessException=Unable to access property {0} which is not accessible for type {1}
|
||||
org.talend.ws.exception.NoSuchPropertyException=Property {0} does not exist for type {1}
|
||||
org.talend.ws.exception.Instantiation=Unable to instantiate class of type {0}
|
||||
org.talend.ws.exception.InvocationTargetPropertyAccessor=A property accessor has thrown an exception : property {0} of class {1}
|
||||
org.talend.ws.exception.illegalAccessValueOf=Unable to call method valueOf for enum type {0}
|
||||
org.talend.ws.exception.Unknown=An unknown exception has been thrown
|
||||
org.talend.ws.exception.InvalidEnumValueException=Value {0} is not valid for enum {1}
|
||||
org.talend.ws.exception.InvalidParameterAnyType=You must specify a map like this for anyTypes : {anyType: value, anyType_type: qname} pour les anyType
|
||||
@@ -0,0 +1,7 @@
|
||||
org.talend.ws.exception.IllegalPropertyAccessException=\u0391\u03B4\u03C5\u03BD\u03B1\u03BC\u03AF\u03B1 \u03C0\u03C1\u03CC\u03C3\u03B2\u03B1\u03C3\u03B7\u03C2 \u03C3\u03C4\u03B7\u03BD \u03B9\u03B4\u03B9\u03CC\u03C4\u03B7\u03C4\u03B1 {0} \u03C0\u03BF\u03C5 \u03B4\u03B5\u03BD \u03B5\u03AF\u03BD\u03B1\u03B9 \u03C0\u03C1\u03BF\u03C3\u03B2\u03AC\u03C3\u03B9\u03BC\u03B7 \u03B3\u03B9\u03B1 \u03C4\u03CD\u03C0\u03BF {1}
|
||||
org.talend.ws.exception.NoSuchPropertyException=\u0397 \u03B9\u03B4\u03B9\u03CC\u03C4\u03B7\u03C4\u03B1 {0} \u03B4\u03B5\u03BD \u03C5\u03C0\u03AC\u03C1\u03C7\u03B5\u03B9 \u03B3\u03B9\u03B1 \u03C4\u03BF\u03BD \u03C4\u03CD\u03C0\u03BF {1}
|
||||
org.talend.ws.exception.Instantiation=\u0391\u03B4\u03C5\u03BD\u03B1\u03BC\u03AF\u03B1 \u03BD\u03B1 \u03B4\u03BF\u03B8\u03B5\u03AF \u03C5\u03C0\u03CC\u03C3\u03C4\u03B1\u03C3\u03B7 \u03C3\u03B5 \u03BA\u03BB\u03AC\u03C3\u03B7 \u03C4\u03CD\u03C0\u03BF\u03C5 {0}
|
||||
org.talend.ws.exception.illegalAccessValueOf=\u0391\u03B4\u03C5\u03BD\u03B1\u03BC\u03AF\u03B1 \u03BA\u03BB\u03AE\u03C3\u03B7\u03C2 \u03BC\u03B5\u03B8\u03CC\u03B4\u03BF\u03C5 valueOf \u03B3\u03B9\u03B1 \u03C4\u03CD\u03C0\u03BF enum {0}
|
||||
org.talend.ws.exception.Unknown=\u039C\u03B9\u03B1 \u03AC\u03B3\u03BD\u03C9\u03C3\u03C4\u03B7 \u03B5\u03BE\u03B1\u03AF\u03C1\u03B5\u03C3\u03B7 \u03C0\u03C1\u03BF\u03AD\u03BA\u03C5\u03C8\u03B5
|
||||
org.talend.ws.exception.InvalidEnumValueException=\u0397 \u03C4\u03B9\u03BC\u03AE {0} \u03B4\u03B5\u03BD \u03B5\u03AF\u03BD\u03B1\u03B9 \u03AD\u03B3\u03BA\u03C5\u03C1\u03B7 \u03B3\u03B9\u03B1 enum {1}
|
||||
org.talend.ws.exception.InvalidParameterAnyType=\u03A0\u03C1\u03AD\u03C0\u03B5\u03B9 \u03BD\u03B1 \u03C0\u03C1\u03BF\u03C3\u03B4\u03B9\u03BF\u03C1\u03AF\u03C3\u03B5\u03C4\u03B5 \u03AD\u03BD\u03B1\u03BD \u03C7\u03AC\u03C1\u03C4\u03B7 \u03C3\u03B1\u03BD \u03B1\u03C5\u03C4\u03CC\u03BD \u03B3\u03B9\u03B1 anyTypes : {anyType: value, anyType_type: qname}
|
||||
@@ -0,0 +1,8 @@
|
||||
org.talend.ws.exception.IllegalPropertyAccessException=Unable to access property {0} which is not accessible for type {1}
|
||||
org.talend.ws.exception.NoSuchPropertyException=Property {0} does not exist for type {1}
|
||||
org.talend.ws.exception.Instantiation=Unable to instantiate class of type {0}
|
||||
org.talend.ws.exception.InvocationTargetPropertyAccessor=A property accessor has thrown an exception : property {0} of class {1}
|
||||
org.talend.ws.exception.illegalAccessValueOf=Unable to call method valueOf for enum type {0}
|
||||
org.talend.ws.exception.Unknown=An unknown exception has been thrown
|
||||
org.talend.ws.exception.InvalidEnumValueException=Value {0} is not valid for enum {1}
|
||||
org.talend.ws.exception.InvalidParameterAnyType=You must specify a map like this for anyTypes : {anyType: value, anyType_type: qname} pour les anyType
|
||||
@@ -0,0 +1,6 @@
|
||||
org.talend.ws.exception.IllegalPropertyAccessException=Impossible d'acc\u00e9der \u00e0 la propri\u00e9t\u00e9 {0} qui est inaccessible pour le type {1}
|
||||
org.talend.ws.exception.NoSuchPropertyException=La propri\u00e9t\u00e9 {0} n'existe pas pour le type {1}
|
||||
org.talend.ws.exception.Instantiation=Impossible d'instancier la classe de type {0}
|
||||
org.talend.ws.exception.illegalAccessValueOf=Impossible d'appeler une m\u00e9thode valueOf pour le type enum {0}
|
||||
org.talend.ws.exception.Unknown=Une exception inconnue a \u00e9t\u00e9 rencontr\u00e9e
|
||||
org.talend.ws.exception.InvalidEnumValueException=La valeur {0} n'est pas valide pour enum {1}
|
||||
@@ -0,0 +1,8 @@
|
||||
org.talend.ws.exception.IllegalPropertyAccessException=\u30BF\u30A4\u30D7 {1} \u306B\u30A2\u30AF\u30BB\u30B9\u3067\u304D\u306A\u3044\u30D7\u30ED\u30D1\u30C6\u30A3 {0} \u306B\u30A2\u30AF\u30BB\u30B9\u3059\u308B\u3053\u3068\u306F\u3067\u304D\u307E\u305B\u3093
|
||||
org.talend.ws.exception.NoSuchPropertyException=\u30BF\u30A4\u30D7 {1} \u306E\u30D7\u30ED\u30D1\u30C6\u30A3 {0} \u306F\u5B58\u5728\u3057\u307E\u305B\u3093
|
||||
org.talend.ws.exception.Instantiation=\u30BF\u30A4\u30D7 {0} \u306E\u30AF\u30E9\u30B9\u3092\u30A4\u30F3\u30B9\u30BF\u30F3\u30B9\u5316\u3059\u308B\u3053\u3068\u306F\u3067\u304D\u307E\u305B\u3093
|
||||
org.talend.ws.exception.InvocationTargetPropertyAccessor=\u30D7\u30ED\u30D1\u30C6\u30A3\u30A2\u30AF\u30BB\u30C3\u30B5\u306F\u4F8B\u5916\u3092\u767A\u751F\u3055\u305B\u307E\u3057\u305F\uFF1A\u30AF\u30E9\u30B9 {1} \u306E\u30D7\u30ED\u30D1\u30C6\u30A3 {0}
|
||||
org.talend.ws.exception.illegalAccessValueOf=enum\u578B {0} \u306E\u30E1\u30BD\u30C3\u30C9\u3092\u547C\u3073\u51FA\u3059\u3053\u3068\u304C\u3067\u304D\u307E\u305B\u3093
|
||||
org.talend.ws.exception.Unknown=\u4F8B\u5916\u304C\u767A\u751F\u3057\u307E\u3057\u305F
|
||||
org.talend.ws.exception.InvalidEnumValueException=\u5024 {0} \u306F\u5217\u6319\u578B {1} \u3068\u3057\u3066\u6709\u52B9\u3067\u306F\u3042\u308A\u307E\u305B\u3093
|
||||
org.talend.ws.exception.InvalidParameterAnyType=\u3053\u306E\u3088\u3046\u306A anyTypes \u306E\u30DE\u30C3\u30D7\u3092\u6307\u5B9A\u3059\u308B\u5FC5\u8981\u304C\u3042\u308A\u307E\u3059 : {anyType: value, anyType_type: qname}
|
||||
@@ -0,0 +1,8 @@
|
||||
org.talend.ws.exception.IllegalPropertyAccessException=\u65E0\u6CD5\u8BBF\u95EE\u5C5E\u6027 {0}\uFF0C\u56E0\u4E3A\u5BF9\u4E8E\u7C7B\u578B {1} \u800C\u8A00\u8BE5\u5C5E\u6027\u4E0D\u53EF\u8BBF\u95EE
|
||||
org.talend.ws.exception.NoSuchPropertyException=\u5C5E\u6027 {0} \u5BF9\u4E8E\u7C7B\u578B {1} \u800C\u8A00\u4E0D\u5B58\u5728
|
||||
org.talend.ws.exception.Instantiation=\u65E0\u6CD5\u5B9E\u4F8B\u5316\u7C7B\u578B {0} \u7684\u7C7B
|
||||
org.talend.ws.exception.InvocationTargetPropertyAccessor=\u5C5E\u6027\u8BBF\u95EE\u5668\u629B\u51FA\u4E86\u4E00\u4E2A\u5F02\u5E38\uFF1A\u7C7B {1} \u7684\u5C5E\u6027 {0}
|
||||
org.talend.ws.exception.illegalAccessValueOf=\u65E0\u6CD5\u4E3A\u679A\u4E3E\u7C7B\u578B {0} \u8C03\u7528\u65B9\u6CD5valueOf
|
||||
org.talend.ws.exception.Unknown=\u4E00\u4E2A\u672A\u77E5\u7684\u5F02\u5E38\u5DF2\u88AB\u629B\u51FA
|
||||
org.talend.ws.exception.InvalidEnumValueException=\u503C {0} \u5BF9\u4E8E\u679A\u4E3E {1} \u65E0\u6548
|
||||
org.talend.ws.exception.InvalidParameterAnyType=\u60A8\u5FC5\u987B\u6309\u5982\u4E0B\u6240\u793A\u4E3A anyType \u6307\u5B9A\u6620\u5C04\uFF1A{anyType: value, anyType_type: qname}
|
||||
@@ -89,7 +89,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.7</version>
|
||||
<version>3.8.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user