Created
October 4, 2011 14:16
-
-
Save zubairov/1261744 to your computer and use it in GitHub Desktop.
REST Provider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ============================================================================ | |
// | |
// Copyright (c) 2005-2010, Talend Inc. | |
// | |
// This source code has been automatically generated by_Talend Open Studio for ESB | |
// / JobDesigner (CodeGenerator version 5.0.0.NB_r69277) | |
// You can find more information about Talend products at www.talend.com. | |
// You may distribute this code under the terms of the GNU LGPL license | |
// http://www.gnu.org/licenses/lgpl.html). | |
// | |
// ============================================================================ | |
package demo.demorest_0_1; | |
import routines.Mathematical; | |
import routines.DataOperation; | |
import routines.Relational; | |
import routines.TalendDate; | |
import routines.TalendDataGenerator; | |
import routines.Numeric; | |
import routines.TalendString; | |
import routines.StringHandling; | |
import routines.system.*; | |
import routines.system.api.*; | |
import java.text.ParseException; | |
import java.text.SimpleDateFormat; | |
import java.util.Date; | |
import java.util.List; | |
import java.math.BigDecimal; | |
import java.io.ByteArrayOutputStream; | |
import java.io.ByteArrayInputStream; | |
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.ObjectOutputStream; | |
import java.io.ObjectInputStream; | |
import java.io.IOException; | |
import java.util.Comparator; | |
/** | |
* Job: DemoREST Purpose: <br> | |
* Description: <br> | |
* | |
* @author test@talend.com | |
* @version 5.0.0.NB_r69277 | |
* @status | |
*/ | |
public class DemoREST implements TalendJob { | |
public final Object obj = new Object(); | |
// for transmiting parameters purpose | |
private Object valueObject = null; | |
public Object getValueObject() { | |
return this.valueObject; | |
} | |
public void setValueObject(Object valueObject) { | |
this.valueObject = valueObject; | |
} | |
private final static String defaultCharset = java.nio.charset.Charset | |
.defaultCharset().name(); | |
private final static String utf8Charset = "UTF-8"; | |
// create and load default properties | |
private java.util.Properties defaultProps = new java.util.Properties(); | |
// create application properties with default | |
public class ContextProperties extends java.util.Properties { | |
public ContextProperties(java.util.Properties properties) { | |
super(properties); | |
} | |
public ContextProperties() { | |
super(); | |
} | |
public void synchronizeContext() { | |
} | |
} | |
private ContextProperties context = new ContextProperties(); | |
public ContextProperties getContext() { | |
return this.context; | |
} | |
private final String jobVersion = "0.1"; | |
private final String jobName = "DemoREST"; | |
private final String projectName = "DEMO"; | |
public Integer errorCode = null; | |
private String currentComponent = ""; | |
private final java.util.Map<String, Long> start_Hash = new java.util.HashMap<String, Long>(); | |
private final java.util.Map<String, Long> end_Hash = new java.util.HashMap<String, Long>(); | |
private final java.util.Map<String, Boolean> ok_Hash = new java.util.HashMap<String, Boolean>(); | |
private final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>(); | |
public final java.util.List<String[]> globalBuffer = new java.util.ArrayList<String[]>(); | |
private RunStat runStat = new RunStat(); | |
public boolean isExportedAsOSGI = false; | |
private final java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); | |
private final java.io.PrintStream errorMessagePS = new java.io.PrintStream( | |
new java.io.BufferedOutputStream(baos)); | |
public String getExceptionStackTrace() { | |
if ("failure".equals(this.getStatus())) { | |
errorMessagePS.flush(); | |
return baos.toString(); | |
} | |
return null; | |
} | |
private Exception exception = null; | |
public Exception getException() { | |
if ("failure".equals(this.getStatus())) { | |
return this.exception; | |
} | |
return null; | |
} | |
private class TalendException extends Exception { | |
private java.util.Map<String, Object> globalMap = null; | |
private Exception e = null; | |
private String currentComponent = null; | |
private TalendException(Exception e, String errorComponent, | |
final java.util.Map<String, Object> globalMap) { | |
this.currentComponent = errorComponent; | |
this.globalMap = globalMap; | |
this.e = e; | |
} | |
@Override | |
public void printStackTrace() { | |
if (!(e instanceof TalendException || e instanceof TDieException)) { | |
globalMap.put(currentComponent + "_ERROR_MESSAGE", e | |
.getMessage()); | |
System.err | |
.println("Exception in component " + currentComponent); | |
} | |
if (!(e instanceof TDieException)) { | |
if (e instanceof TalendException) { | |
e.printStackTrace(); | |
} else { | |
e.printStackTrace(); | |
e.printStackTrace(errorMessagePS); | |
DemoREST.this.exception = e; | |
} | |
} | |
if (!(e instanceof TalendException)) { | |
try { | |
for (java.lang.reflect.Method m : this.getClass() | |
.getEnclosingClass().getMethods()) { | |
if (m.getName().compareTo(currentComponent + "_error") == 0) { | |
m.invoke(DemoREST.this, new Object[] { e, | |
currentComponent, globalMap }); | |
break; | |
} | |
} | |
if (!(e instanceof TDieException)) { | |
} | |
} catch (java.lang.SecurityException e) { | |
this.e.printStackTrace(); | |
} catch (java.lang.IllegalArgumentException e) { | |
this.e.printStackTrace(); | |
} catch (java.lang.IllegalAccessException e) { | |
this.e.printStackTrace(); | |
} catch (java.lang.reflect.InvocationTargetException e) { | |
this.e.printStackTrace(); | |
} | |
} | |
} | |
} | |
public void tRESTRequest_1_error(Exception exception, | |
String errorComponent, final java.util.Map<String, Object> globalMap) | |
throws TalendException { | |
end_Hash.put("tRESTRequest_1", System.currentTimeMillis()); | |
tRESTRequest_1_onSubJobError(exception, errorComponent, globalMap); | |
} | |
public void tLogRow_1_error(Exception exception, String errorComponent, | |
final java.util.Map<String, Object> globalMap) | |
throws TalendException { | |
end_Hash.put("tLogRow_1", System.currentTimeMillis()); | |
tRESTRequest_1_onSubJobError(exception, errorComponent, globalMap); | |
} | |
public void tXMLMap_1_error(Exception exception, String errorComponent, | |
final java.util.Map<String, Object> globalMap) | |
throws TalendException { | |
end_Hash.put("tXMLMap_1", System.currentTimeMillis()); | |
tRESTRequest_1_onSubJobError(exception, errorComponent, globalMap); | |
} | |
public void tRESTResponse_1_error(Exception exception, | |
String errorComponent, final java.util.Map<String, Object> globalMap) | |
throws TalendException { | |
end_Hash.put("tRESTResponse_1", System.currentTimeMillis()); | |
tRESTRequest_1_onSubJobError(exception, errorComponent, globalMap); | |
} | |
public void tRESTRequest_1_onSubJobError(Exception exception, | |
String errorComponent, final java.util.Map<String, Object> globalMap) | |
throws TalendException { | |
resumeUtil.addLog("SYSTEM_LOG", "NODE:" + errorComponent, "", Thread | |
.currentThread().getId() | |
+ "", "FATAL", "", exception.getMessage(), ResumeUtil | |
.getExceptionStackTrace(exception), ""); | |
} | |
/** | |
* queued message exchange | |
*/ | |
class QueuedExchangeContextImpl<T> { | |
/** | |
* Exchange timeout in seconds | |
*/ | |
private static final long EXCHANGE_TIMEOUT = 50; | |
private final java.util.concurrent.Exchanger<Exception> exceptionExchange = new java.util.concurrent.Exchanger<Exception>(); | |
private final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch( | |
1); | |
private final T input; | |
private T output = null; | |
public QueuedExchangeContextImpl(T input) { | |
this.input = input; | |
} | |
/** | |
* Don't forget to call this method when you are done with processing of | |
* the {@link QueuedExchangeContext} | |
*/ | |
public void release() throws Exception { | |
latch.countDown(); | |
Exception exception; | |
try { | |
exception = exceptionExchange.exchange(null, EXCHANGE_TIMEOUT, | |
java.util.concurrent.TimeUnit.SECONDS); | |
} catch (InterruptedException e) { | |
throw new Exception(e); | |
} catch (java.util.concurrent.TimeoutException e) { | |
throw new Exception(e); | |
} | |
if (exception != null) { | |
throw exception; | |
} | |
} | |
/** | |
* This operation have to be called on the Web Service thread to send | |
* response if required | |
* | |
* @throws InterruptedException | |
*/ | |
public void completeQueuedProcessing() throws InterruptedException { | |
exceptionExchange.exchange(null); | |
} | |
/** | |
* @throws InterruptedException | |
*/ | |
void waitForRelease(long timeout, java.util.concurrent.TimeUnit unit) | |
throws InterruptedException { | |
latch.await(timeout, unit); | |
} | |
public T getInput() { | |
return input; | |
} | |
public void serveOutput(T response) { | |
output = response; | |
} | |
public T getResponse() { | |
return output; | |
} | |
} | |
/** | |
* message exchange controller | |
*/ | |
class QueuedMessageHandlerImpl<T> implements ESBProviderCallback { | |
private final int MAX_QUEUE_SIZE = 1000; | |
private final int WAIT_TIMEOUT_SECONDS = 120; | |
private final java.util.concurrent.BlockingQueue<QueuedExchangeContextImpl<?>> queue = new java.util.concurrent.LinkedBlockingQueue<QueuedExchangeContextImpl<?>>( | |
MAX_QUEUE_SIZE); | |
/** | |
* This method add a newly created {@link QueuedExchangeContextImpl} | |
* into the internal blocking queue where consumer thread is waiting for | |
* it. Then it waits until the {@link QueuedExchangeContextImpl} will be | |
* completed for request-response operations | |
*/ | |
public QueuedExchangeContextImpl<T> invoke(T request) { | |
QueuedExchangeContextImpl<T> context = new QueuedExchangeContextImpl<T>( | |
request); | |
boolean inserted = queue.offer(context); | |
if (!inserted) { | |
try { | |
context.release(); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
throw new RuntimeException( | |
"Can't queue request, queue size of " + MAX_QUEUE_SIZE | |
+ " is exceeded"); | |
} else { | |
try { | |
context.waitForRelease(WAIT_TIMEOUT_SECONDS, | |
java.util.concurrent.TimeUnit.SECONDS); | |
} catch (InterruptedException ie) { | |
throw new RuntimeException("job execution timeout: " | |
+ ie.getMessage()); | |
} | |
} | |
return context; | |
} | |
QueuedExchangeContextImpl<T> currentExchangeContext; | |
public T getRequest() throws ESBJobInterruptedException { | |
currentExchangeContext = null; | |
try { | |
currentExchangeContext = (QueuedExchangeContextImpl<T>) queue | |
.take(); | |
} catch (InterruptedException e) { | |
throw new RuntimeException(e); | |
} | |
return currentExchangeContext.getInput(); | |
} | |
public void sendResponse(Object output) { | |
if (null == currentExchangeContext) { | |
throw new RuntimeException( | |
"sendResponse() invoked before getRequest()"); | |
} | |
currentExchangeContext.serveOutput((T) output); | |
try { | |
currentExchangeContext.release(); | |
} catch (Exception e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} | |
/** | |
* A special Dom4J provider implementation to help conversion in JAX-RS | |
* | |
* @see http://jira.talendforge.org/browse/TESB-3329 | |
*/ | |
@javax.ws.rs.Produces({ "application/xml", "application/json" }) | |
@javax.ws.rs.Consumes({ "application/xml", "application/json" }) | |
public static class DOM4JProvider implements | |
javax.ws.rs.ext.MessageBodyReader<org.dom4j.Document>, | |
javax.ws.rs.ext.MessageBodyWriter<org.dom4j.Document> { | |
private static final Class<org.w3c.dom.Document> DOM_DOC_CLS = org.w3c.dom.Document.class; | |
private javax.ws.rs.ext.Providers providers; | |
@javax.ws.rs.core.Context | |
public void setProviders(javax.ws.rs.ext.Providers providers) { | |
this.providers = providers; | |
} | |
public boolean isReadable(Class<?> cls, java.lang.reflect.Type type, | |
java.lang.annotation.Annotation[] anns, | |
javax.ws.rs.core.MediaType mt) { | |
return Document.class.isAssignableFrom(cls); | |
} | |
public org.dom4j.Document readFrom(Class<org.dom4j.Document> cls, | |
java.lang.reflect.Type type, | |
java.lang.annotation.Annotation[] anns, | |
javax.ws.rs.core.MediaType mt, | |
javax.ws.rs.core.MultivaluedMap<String, String> headers, | |
java.io.InputStream is) throws IOException, | |
javax.ws.rs.WebApplicationException { | |
javax.ws.rs.ext.MessageBodyReader<org.w3c.dom.Document> reader = providers | |
.getMessageBodyReader(DOM_DOC_CLS, DOM_DOC_CLS, anns, mt); | |
if (reader == null) { | |
throw new javax.ws.rs.WebApplicationException(415); | |
} | |
org.w3c.dom.Document domDoc = reader.readFrom(DOM_DOC_CLS, | |
DOM_DOC_CLS, anns, mt, headers, is); | |
return new org.dom4j.io.DOMReader().read(domDoc); | |
} | |
public long getSize(org.dom4j.Document doc, Class<?> cls, | |
java.lang.reflect.Type type, | |
java.lang.annotation.Annotation[] anns, | |
javax.ws.rs.core.MediaType mt) { | |
return -1; | |
} | |
public boolean isWriteable(Class<?> cls, java.lang.reflect.Type type, | |
java.lang.annotation.Annotation[] anns, | |
javax.ws.rs.core.MediaType mt) { | |
return Document.class.isAssignableFrom(cls); | |
} | |
public void writeTo(org.dom4j.Document doc, Class<?> cls, | |
java.lang.reflect.Type type, | |
java.lang.annotation.Annotation[] anns, | |
javax.ws.rs.core.MediaType mt, | |
javax.ws.rs.core.MultivaluedMap<String, Object> headers, | |
java.io.OutputStream os) throws IOException, | |
javax.ws.rs.WebApplicationException { | |
org.w3c.dom.Document domDoc = convertToDOM(doc); | |
javax.ws.rs.ext.MessageBodyWriter<org.w3c.dom.Document> writer = providers | |
.getMessageBodyWriter(DOM_DOC_CLS, DOM_DOC_CLS, anns, mt); | |
if (writer == null) { | |
throw new javax.ws.rs.WebApplicationException(406); | |
} | |
writer.writeTo(domDoc, DOM_DOC_CLS, DOM_DOC_CLS, anns, mt, headers, | |
os); | |
} | |
private org.w3c.dom.Document convertToDOM(org.dom4j.Document doc) { | |
String xml = doc.asXML(); | |
try { | |
return org.apache.cxf.helpers.DOMUtils | |
.readXml(new java.io.StringReader(xml)); | |
} catch (Exception ex) { | |
throw new javax.ws.rs.WebApplicationException(ex); | |
} | |
} | |
} | |
/** | |
* REST provider implementation | |
*/ | |
@javax.ws.rs.Path("/") | |
@javax.ws.rs.Produces({ "application/xml", "application/json" }) | |
@javax.ws.rs.Consumes({ "application/xml", "application/json" }) | |
public class RESTProvider_tRESTRequest_1 { | |
private QueuedMessageHandlerImpl<java.util.Map<String, Object>> messageHandler; | |
public RESTProvider_tRESTRequest_1( | |
QueuedMessageHandlerImpl<java.util.Map<String, Object>> messageHandler) { | |
this.messageHandler = messageHandler; | |
} | |
// private java.util.Map<String, String> | |
// getPathParameters(javax.ws.rs.core.UriInfo uriInfo) { | |
// java.util.Map<String, String> params = new java.util.HashMap<String, | |
// String>(); | |
// javax.ws.rs.core.MultivaluedMap<String, String> pathParams = | |
// uriInfo.getPathParameters(); | |
// for (String paramName : pathParams.keySet()) { | |
// params.put(paramName, pathParams.getFirst(paramName)); | |
// } | |
// return params; | |
// } | |
private javax.ws.rs.core.Response processRequest( | |
java.util.Map<String, Object> request) { | |
try { | |
QueuedExchangeContextImpl<java.util.Map<String, Object>> messageExchange = messageHandler | |
.invoke(request); | |
try { | |
java.util.Map<String, Object> responseMap = messageExchange | |
.getResponse(); | |
Object responseBody = responseMap.get("BODY"); | |
Integer status = (Integer) responseMap.get("STATUS"); | |
if (null == status) { | |
status = 200; | |
} | |
return javax.ws.rs.core.Response.status(status).entity( | |
responseBody).build(); | |
} finally { | |
messageExchange.completeQueuedProcessing(); | |
} | |
} catch (RuntimeException ex) { | |
ex.printStackTrace(); | |
throw new javax.ws.rs.WebApplicationException(ex, 500); | |
} catch (Throwable ex) { | |
ex.printStackTrace(); | |
throw new javax.ws.rs.WebApplicationException(ex, 500); | |
} finally { | |
// System.out.println(System.currentTimeMillis() + | |
// " <- handleMessage"); | |
} | |
} | |
@javax.ws.rs.GET() | |
@javax.ws.rs.Path("all/") | |
public javax.ws.rs.core.Response getAll() { | |
java.util.Map<String, Object> request = new java.util.HashMap<String, Object>(); | |
request.put("VERB", "GET"); | |
request.put("OPERATION", "getAll"); | |
// request.put("URI", uriInfo.getPath()); | |
request.put("PATTERN", "all/"); | |
request.put("BODY", body); | |
// request.put("PARAMS", getPathParameters(uriInfo)); | |
java.util.Map<String, Object> parameters = new java.util.HashMap<String, Object>(); | |
request.put("PARAMS", parameters); | |
return processRequest(request); | |
} | |
public void handleWrongRequest(String uri, int status, String error) { | |
System.out.println("wrong call [uri: " + uri + " ; status: " | |
+ status + " ; error: " + error + "]"); | |
java.util.Map<String, Object> wrongRequest = new java.util.HashMap<String, Object>(); | |
wrongRequest.put("ERROR", error); | |
wrongRequest.put("URI", uri); | |
wrongRequest.put("STATUS", status); | |
processRequest(wrongRequest); | |
} | |
} | |
class RestExceptionMapper_tRESTRequest_1 extends | |
org.apache.cxf.jaxrs.impl.WebApplicationExceptionMapper { | |
@javax.ws.rs.core.Context | |
private javax.ws.rs.core.UriInfo ui; | |
private RESTProvider_tRESTRequest_1 provider; | |
public RestExceptionMapper_tRESTRequest_1( | |
RESTProvider_tRESTRequest_1 provider) { | |
this.provider = provider; | |
} | |
public javax.ws.rs.core.Response toResponse( | |
javax.ws.rs.WebApplicationException ex) { | |
String error = null; | |
javax.ws.rs.core.Response response = ex.getResponse(); | |
if (null != response && null != response.getEntity()) { | |
error = response.getEntity().toString(); | |
} | |
response = super.toResponse(ex); | |
if (null == error) { | |
if (null != response && null != response.getEntity()) { | |
error = response.getEntity().toString(); | |
} else { | |
error = null == ex.getCause() ? ex.getMessage() : ex | |
.getCause().getMessage(); | |
} | |
} | |
provider.handleWrongRequest(ui.getPath(), response.getStatus(), | |
error); | |
return response; | |
} | |
} | |
class HandlerThread_tRESTRequest_1 extends Thread { | |
private QueuedMessageHandlerImpl<java.util.Map<String, Object>> handler; | |
private final String endpointUrl = "http://localhost:8089/"; | |
private org.apache.cxf.endpoint.Server server; | |
public HandlerThread_tRESTRequest_1( | |
QueuedMessageHandlerImpl<java.util.Map<String, Object>> handler) { | |
this.handler = handler; | |
} | |
public void run() { | |
try { | |
RESTProvider_tRESTRequest_1 provider = new RESTProvider_tRESTRequest_1( | |
handler); | |
org.apache.cxf.jaxrs.JAXRSServerFactoryBean sf = new org.apache.cxf.jaxrs.JAXRSServerFactoryBean(); | |
java.util.List<Object> providers = new java.util.ArrayList<Object>(); | |
providers.add(new RestExceptionMapper_tRESTRequest_1(provider)); | |
providers.add(new DOM4JProvider()); | |
sf.setProviders(providers); | |
sf.setTransportId("http://cxf.apache.org/transports/http"); | |
sf.setResourceClasses(RESTProvider_tRESTRequest_1.class); | |
sf.setResourceProvider( | |
RESTProvider_tRESTRequest_1.class, | |
new org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider( | |
provider)); | |
sf.setAddress(endpointUrl); | |
server = sf.create(); | |
System.out.println("rest service [endpoint: " + endpointUrl | |
+ "] published"); | |
} catch (Throwable e) { | |
e.printStackTrace(); | |
// java.io.ByteArrayOutputStream baos = new | |
// java.io.ByteArrayOutputStream(); | |
// e.printStackTrace(new java.io.PrintStream(baos)); | |
// System.out.println("error:\n" + baos.toString()); | |
} | |
} | |
public void stopEndpoint() { | |
if (null != server) { | |
server.stop(); | |
server.destroy(); | |
System.out.println("rest service [endpoint: " + endpointUrl | |
+ "] unpublished"); | |
} | |
} | |
} | |
public static class eeeStruct implements | |
routines.system.IPersistableRow<eeeStruct> { | |
final static byte[] commonByteArrayLock = new byte[0]; | |
static byte[] commonByteArray = new byte[0]; | |
public Document xml; | |
public Document getXml() { | |
return this.xml; | |
} | |
public java.util.Map<String, Object> documentLookupResult = new java.util.HashMap<String, Object>(); | |
public String string; | |
public String getString() { | |
return this.string; | |
} | |
private String readString(ObjectInputStream dis) throws IOException { | |
String strReturn = null; | |
int length = 0; | |
length = dis.readInt(); | |
if (length == -1) { | |
strReturn = null; | |
} else { | |
if (length > commonByteArray.length) { | |
if (length < 1024 && commonByteArray.length == 0) { | |
commonByteArray = new byte[1024]; | |
} else { | |
commonByteArray = new byte[2 * length]; | |
} | |
} | |
dis.readFully(commonByteArray, 0, length); | |
strReturn = new String(commonByteArray, 0, length, utf8Charset); | |
} | |
return strReturn; | |
} | |
private void writeString(String str, ObjectOutputStream dos) | |
throws IOException { | |
if (str == null) { | |
dos.writeInt(-1); | |
} else { | |
byte[] byteArray = str.getBytes(utf8Charset); | |
dos.writeInt(byteArray.length); | |
dos.write(byteArray); | |
} | |
} | |
public void readData(ObjectInputStream dis) { | |
synchronized (commonByteArrayLock) { | |
try { | |
int length = 0; | |
this.xml = (Document) dis.readObject(); | |
this.string = readString(dis); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} catch (ClassNotFoundException eCNFE) { | |
throw new RuntimeException(eCNFE); | |
} | |
} | |
} | |
public void writeData(ObjectOutputStream dos) { | |
try { | |
// Document | |
dos.writeObject(this.xml); | |
// String | |
writeString(this.string, dos); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public String toString() { | |
StringBuilder sb = new StringBuilder(); | |
sb.append(super.toString()); | |
sb.append("["); | |
sb.append("xml=" + String.valueOf(xml)); | |
sb.append(",string=" + string); | |
sb.append("]"); | |
return sb.toString(); | |
} | |
/** | |
* Compare keys | |
*/ | |
public int compareTo(eeeStruct other) { | |
int returnValue = -1; | |
return returnValue; | |
} | |
private int checkNullsAndCompare(Object object1, Object object2) { | |
int returnValue = 0; | |
if (object1 instanceof Comparable && object2 instanceof Comparable) { | |
returnValue = ((Comparable) object1).compareTo(object2); | |
} else if (object1 != null && object2 != null) { | |
returnValue = compareStrings(object1.toString(), object2 | |
.toString()); | |
} else if (object1 == null && object2 != null) { | |
returnValue = 1; | |
} else if (object1 != null && object2 == null) { | |
returnValue = -1; | |
} else { | |
returnValue = 0; | |
} | |
return returnValue; | |
} | |
private int compareStrings(String string1, String string2) { | |
return string1.compareTo(string2); | |
} | |
} | |
public static class row1Struct implements | |
routines.system.IPersistableRow<row1Struct> { | |
final static byte[] commonByteArrayLock = new byte[0]; | |
static byte[] commonByteArray = new byte[0]; | |
public String uri; | |
public String getUri() { | |
return this.uri; | |
} | |
private String readString(ObjectInputStream dis) throws IOException { | |
String strReturn = null; | |
int length = 0; | |
length = dis.readInt(); | |
if (length == -1) { | |
strReturn = null; | |
} else { | |
if (length > commonByteArray.length) { | |
if (length < 1024 && commonByteArray.length == 0) { | |
commonByteArray = new byte[1024]; | |
} else { | |
commonByteArray = new byte[2 * length]; | |
} | |
} | |
dis.readFully(commonByteArray, 0, length); | |
strReturn = new String(commonByteArray, 0, length, utf8Charset); | |
} | |
return strReturn; | |
} | |
private void writeString(String str, ObjectOutputStream dos) | |
throws IOException { | |
if (str == null) { | |
dos.writeInt(-1); | |
} else { | |
byte[] byteArray = str.getBytes(utf8Charset); | |
dos.writeInt(byteArray.length); | |
dos.write(byteArray); | |
} | |
} | |
public void readData(ObjectInputStream dis) { | |
synchronized (commonByteArrayLock) { | |
try { | |
int length = 0; | |
this.uri = readString(dis); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} | |
public void writeData(ObjectOutputStream dos) { | |
try { | |
// String | |
writeString(this.uri, dos); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public String toString() { | |
StringBuilder sb = new StringBuilder(); | |
sb.append(super.toString()); | |
sb.append("["); | |
sb.append("uri=" + uri); | |
sb.append("]"); | |
return sb.toString(); | |
} | |
/** | |
* Compare keys | |
*/ | |
public int compareTo(row1Struct other) { | |
int returnValue = -1; | |
return returnValue; | |
} | |
private int checkNullsAndCompare(Object object1, Object object2) { | |
int returnValue = 0; | |
if (object1 instanceof Comparable && object2 instanceof Comparable) { | |
returnValue = ((Comparable) object1).compareTo(object2); | |
} else if (object1 != null && object2 != null) { | |
returnValue = compareStrings(object1.toString(), object2 | |
.toString()); | |
} else if (object1 == null && object2 != null) { | |
returnValue = 1; | |
} else if (object1 != null && object2 == null) { | |
returnValue = -1; | |
} else { | |
returnValue = 0; | |
} | |
return returnValue; | |
} | |
private int compareStrings(String string1, String string2) { | |
return string1.compareTo(string2); | |
} | |
} | |
public static class getAllStruct implements | |
routines.system.IPersistableRow<getAllStruct> { | |
final static byte[] commonByteArrayLock = new byte[0]; | |
static byte[] commonByteArray = new byte[0]; | |
public String uri; | |
public String getUri() { | |
return this.uri; | |
} | |
private String readString(ObjectInputStream dis) throws IOException { | |
String strReturn = null; | |
int length = 0; | |
length = dis.readInt(); | |
if (length == -1) { | |
strReturn = null; | |
} else { | |
if (length > commonByteArray.length) { | |
if (length < 1024 && commonByteArray.length == 0) { | |
commonByteArray = new byte[1024]; | |
} else { | |
commonByteArray = new byte[2 * length]; | |
} | |
} | |
dis.readFully(commonByteArray, 0, length); | |
strReturn = new String(commonByteArray, 0, length, utf8Charset); | |
} | |
return strReturn; | |
} | |
private void writeString(String str, ObjectOutputStream dos) | |
throws IOException { | |
if (str == null) { | |
dos.writeInt(-1); | |
} else { | |
byte[] byteArray = str.getBytes(utf8Charset); | |
dos.writeInt(byteArray.length); | |
dos.write(byteArray); | |
} | |
} | |
public void readData(ObjectInputStream dis) { | |
synchronized (commonByteArrayLock) { | |
try { | |
int length = 0; | |
this.uri = readString(dis); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
} | |
public void writeData(ObjectOutputStream dos) { | |
try { | |
// String | |
writeString(this.uri, dos); | |
} catch (IOException e) { | |
throw new RuntimeException(e); | |
} | |
} | |
public String toString() { | |
StringBuilder sb = new StringBuilder(); | |
sb.append(super.toString()); | |
sb.append("["); | |
sb.append("uri=" + uri); | |
sb.append("]"); | |
return sb.toString(); | |
} | |
/** | |
* Compare keys | |
*/ | |
public int compareTo(getAllStruct other) { | |
int returnValue = -1; | |
return returnValue; | |
} | |
private int checkNullsAndCompare(Object object1, Object object2) { | |
int returnValue = 0; | |
if (object1 instanceof Comparable && object2 instanceof Comparable) { | |
returnValue = ((Comparable) object1).compareTo(object2); | |
} else if (object1 != null && object2 != null) { | |
returnValue = compareStrings(object1.toString(), object2 | |
.toString()); | |
} else if (object1 == null && object2 != null) { | |
returnValue = 1; | |
} else if (object1 != null && object2 == null) { | |
returnValue = -1; | |
} else { | |
returnValue = 0; | |
} | |
return returnValue; | |
} | |
private int compareStrings(String string1, String string2) { | |
return string1.compareTo(string2); | |
} | |
} | |
public void tRESTRequest_1Process( | |
final java.util.Map<String, Object> globalMap) | |
throws TalendException { | |
globalMap.put("tRESTRequest_1_SUBPROCESS_STATE", 0); | |
final boolean execStat = this.execStat; | |
String iterateId = ""; | |
String currentComponent = ""; | |
try { | |
String currentMethodName = new Exception().getStackTrace()[0] | |
.getMethodName(); | |
boolean resumeIt = currentMethodName.equals(resumeEntryMethodName); | |
if (resumeEntryMethodName == null || resumeIt || globalResumeTicket) {// start | |
// the | |
// resume | |
globalResumeTicket = true; | |
getAllStruct getAll = new getAllStruct(); | |
getAllStruct row1 = getAll; | |
eeeStruct eee = new eeeStruct(); | |
/** | |
* [tRESTResponse_1 begin ] start | |
*/ | |
ok_Hash.put("tRESTResponse_1", false); | |
start_Hash.put("tRESTResponse_1", System.currentTimeMillis()); | |
currentComponent = "tRESTResponse_1"; | |
if (execStat) { | |
runStat.updateStatOnConnection("eee" + iterateId, 0, 0); | |
} | |
int tos_count_tRESTResponse_1 = 0; | |
/** | |
* [tRESTResponse_1 begin ] stop | |
*/ | |
/** | |
* [tXMLMap_1 begin ] start | |
*/ | |
ok_Hash.put("tXMLMap_1", false); | |
start_Hash.put("tXMLMap_1", System.currentTimeMillis()); | |
currentComponent = "tXMLMap_1"; | |
if (execStat) { | |
runStat.updateStatOnConnection("row1" + iterateId, 0, 0); | |
} | |
int tos_count_tXMLMap_1 = 0; | |
// ===============================input xml init | |
// part=============================== | |
class NameSpaceTool_tXMLMap_1 { | |
public java.util.HashMap<String, String> xmlNameSpaceMap = new java.util.HashMap<String, String>(); | |
private java.util.List<String> defualtNSPath = new java.util.ArrayList<String>(); | |
public void countNSMap(org.dom4j.Element el) { | |
for (org.dom4j.Namespace ns : (java.util.List<org.dom4j.Namespace>) el | |
.declaredNamespaces()) { | |
if (ns.getPrefix().trim().length() == 0) { | |
xmlNameSpaceMap.put("pre" | |
+ defualtNSPath.size(), ns.getURI()); | |
String path = ""; | |
org.dom4j.Element elTmp = el; | |
while (elTmp != null) { | |
if (elTmp.getNamespacePrefix() != null | |
&& elTmp.getNamespacePrefix() | |
.length() > 0) { | |
path = "/" + elTmp.getNamespacePrefix() | |
+ ":" + elTmp.getName() + path; | |
} else { | |
path = "/" + elTmp.getName() + path; | |
} | |
elTmp = elTmp.getParent(); | |
} | |
defualtNSPath.add(path); | |
} else { | |
xmlNameSpaceMap | |
.put(ns.getPrefix(), ns.getURI()); | |
} | |
} | |
for (org.dom4j.Element e : (java.util.List<org.dom4j.Element>) el | |
.elements()) { | |
countNSMap(e); | |
} | |
} | |
public String addDefaultNSPrefix(String path, | |
String loopPath) { | |
if (defualtNSPath.size() > 0) { | |
String fullPath = loopPath; | |
if (!path.equals(fullPath)) { | |
for (String tmp : path.split("/")) { | |
if (("..").equals(tmp)) { | |
fullPath = fullPath.substring(0, | |
fullPath.lastIndexOf("/")); | |
} else { | |
fullPath += "/" + tmp; | |
} | |
} | |
} | |
int[] indexs = new int[fullPath.split("/").length - 1]; | |
java.util.Arrays.fill(indexs, -1); | |
int length = 0; | |
for (int i = 0; i < defualtNSPath.size(); i++) { | |
if (defualtNSPath.get(i).length() > length | |
&& fullPath.startsWith(defualtNSPath | |
.get(i))) { | |
java.util.Arrays.fill(indexs, defualtNSPath | |
.get(i).split("/").length - 2, | |
indexs.length, i); | |
length = defualtNSPath.get(i).length(); | |
} | |
} | |
StringBuilder newPath = new StringBuilder(); | |
String[] pathStrs = path.split("/"); | |
for (int i = 0; i < pathStrs.length; i++) { | |
String tmp = pathStrs[i]; | |
if (newPath.length() > 0) { | |
newPath.append("/"); | |
} | |
if (tmp.length() > 0 && tmp.indexOf(":") == -1 | |
&& tmp.indexOf(".") == -1 /* | |
* && | |
* tmp.indexOf | |
* ("@") == -1 | |
*/) { | |
int index = indexs[i + indexs.length | |
- pathStrs.length]; | |
if (index >= 0) { | |
// ==== add by wliu to support both | |
// filter and functions== | |
if (tmp.indexOf("[") > 0 | |
&& tmp.indexOf("]") > tmp | |
.indexOf("[")) {// include | |
// filter | |
String tmpStr = replaceElementWithNS( | |
tmp, "pre" + index + ":"); | |
newPath.append(tmpStr); | |
} else { | |
if (tmp.indexOf("@") != -1 | |
|| tmp.indexOf("(") < tmp | |
.indexOf(")")) { // include | |
// attribute | |
newPath.append(tmp); | |
} else { | |
// ==add end======= | |
newPath.append("pre").append( | |
index).append(":") | |
.append(tmp); | |
} | |
} | |
} else { | |
newPath.append(tmp); | |
} | |
} else { | |
newPath.append(tmp); | |
} | |
} | |
return newPath.toString(); | |
} | |
return path; | |
} | |
private String matches = "@*\\b[a-z|A-Z|_]+[[-]*\\w]*\\b[^'|^\\(]"; | |
private java.util.regex.Pattern pattern = java.util.regex.Pattern | |
.compile(matches); | |
private String replaceElementWithNS(String global, | |
String pre) { | |
java.util.regex.Matcher match = pattern.matcher(global); | |
StringBuffer sb = new StringBuffer(); | |
match.reset(); | |
while (match.find()) { | |
String group = match.group(); | |
String tmp = ""; | |
if (group.toLowerCase().matches( | |
"\\b(div|mod|and|or)\\b.*") | |
|| group.matches("@.*")) { | |
tmp = group; | |
} else { | |
tmp = tmp + pre + group; | |
} | |
match.appendReplacement(sb, tmp); | |
} | |
match.appendTail(sb); | |
return sb.toString(); | |
} | |
} | |
class XML_API_tXMLMap_1 { | |
public boolean isDefNull(org.dom4j.Node node) | |
throws javax.xml.transform.TransformerException { | |
if (node != null && node instanceof org.dom4j.Element) { | |
org.dom4j.Attribute attri = ((org.dom4j.Element) node) | |
.attribute("nil"); | |
if (attri != null | |
&& ("true").equals(attri.getText())) { | |
return true; | |
} | |
} | |
return false; | |
} | |
public boolean isMissing(org.dom4j.Node node) | |
throws javax.xml.transform.TransformerException { | |
return node == null ? true : false; | |
} | |
public boolean isEmpty(org.dom4j.Node node) | |
throws javax.xml.transform.TransformerException { | |
if (node != null) { | |
return node.getText().length() == 0; | |
} | |
return false; | |
} | |
} | |
class Var__tXMLMap_1__Struct { | |
} | |
Var__tXMLMap_1__Struct Var__tXMLMap_1 = new Var__tXMLMap_1__Struct(); | |
// ############################### | |
// # Outputs initialization | |
eeeStruct eee_tmp = new eeeStruct(); | |
eeeStruct eee_save = null; | |
// ############################### | |
int nb_line_tXMLMap_1 = 0; | |
XML_API_tXMLMap_1 xml_api_tXMLMap_1 = new XML_API_tXMLMap_1(); | |
class NestXMLTool_tXMLMap_1 { | |
public void parseAndAdd(org.dom4j.Element nestRoot, | |
String value) { | |
try { | |
org.dom4j.Document doc4Str = org.dom4j.DocumentHelper | |
.parseText("<root>" + value + "</root>"); | |
nestRoot.setContent(doc4Str.getRootElement() | |
.content()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
nestRoot.setText(value); | |
} | |
} | |
public void setText(org.dom4j.Element element, String value) { | |
if (value.startsWith("<![CDATA[") | |
&& value.endsWith("]]>")) { | |
String text = value | |
.substring(9, value.length() - 3); | |
element.addCDATA(text); | |
} else { | |
element.setText(value); | |
} | |
} | |
public void replaceDefaultNameSpace( | |
org.dom4j.Element nestRoot) { | |
if (nestRoot != null) { | |
for (org.dom4j.Element tmp : (java.util.List<org.dom4j.Element>) nestRoot | |
.elements()) { | |
if (("").equals(tmp.getQName().getNamespace() | |
.getURI()) | |
&& ("").equals(tmp.getQName() | |
.getNamespace().getPrefix())) { | |
tmp.setQName(org.dom4j.DocumentHelper | |
.createQName(tmp.getName(), | |
nestRoot.getQName() | |
.getNamespace())); | |
} | |
replaceDefaultNameSpace(tmp); | |
} | |
} | |
} | |
public void removeEmptyElement(org.dom4j.Element root) { | |
if (root != null) { | |
for (org.dom4j.Element tmp : (java.util.List<org.dom4j.Element>) root | |
.elements()) { | |
removeEmptyElement(tmp); | |
} | |
if (root.content().size() == 0 | |
&& root.attributes().size() == 0 | |
&& root.declaredNamespaces().size() == 0) { | |
if (root.getParent() != null) { | |
root.getParent().remove(root); | |
} | |
} | |
} | |
} | |
} | |
// NestXMLTool_tXMLMap_1 nestXMLTool_tXMLMap_1 = new | |
// NestXMLTool_tXMLMap_1(); | |
class GenerateDocument_eee { | |
org.dom4j.Document doc = null; | |
NestXMLTool_tXMLMap_1 nestXMLTool = null; | |
org.dom4j.Element root4Group = null; | |
org.dom4j.io.OutputFormat format = null; | |
java.util.List<java.util.List<String>> groupbyList = null; | |
java.util.List<org.dom4j.Element> groupElementList = null; | |
int order = 0; | |
boolean isFirst = true; | |
boolean needRoot = true; | |
public GenerateDocument_eee() { | |
// this.treeNodeAPI = treeNodeAPI; | |
nestXMLTool = new NestXMLTool_tXMLMap_1(); | |
groupbyList = new java.util.ArrayList<java.util.List<String>>(); | |
groupElementList = new java.util.ArrayList<org.dom4j.Element>(); | |
doc = org.dom4j.DocumentHelper.createDocument(); | |
format = org.dom4j.io.OutputFormat.createPrettyPrint(); | |
format.setTrimText(false); | |
} | |
public org.dom4j.Document getDocument() { | |
return this.doc; | |
} | |
// We generate the TreeNode_API object only if there is a | |
// document in the main input table. | |
void generateElements(boolean isInnerJoin, | |
getAllStruct row1, Var__tXMLMap_1__Struct Var) { | |
/* | |
* if(this.treeNodeAPI==null) { this.treeNodeAPI = | |
* treeNodeAPI; } | |
*/ | |
org.dom4j.Element subTreeRootParent = null; | |
// build root xml tree | |
if (needRoot) { | |
needRoot = false; | |
org.dom4j.Element root = doc.addElement("root"); | |
subTreeRootParent = root; | |
root4Group = subTreeRootParent; | |
} else { | |
subTreeRootParent = root4Group; | |
} | |
/* build group xml tree */ | |
boolean isNewElement = false; | |
isNewElement = false; | |
org.dom4j.Element loop = subTreeRootParent | |
.addElement("bla"); | |
subTreeRootParent = loop; | |
nestXMLTool.setText(loop, String.valueOf("Hasi!")); | |
} | |
} | |
/** | |
* [tXMLMap_1 begin ] stop | |
*/ | |
/** | |
* [tLogRow_1 begin ] start | |
*/ | |
ok_Hash.put("tLogRow_1", false); | |
start_Hash.put("tLogRow_1", System.currentTimeMillis()); | |
currentComponent = "tLogRow_1"; | |
if (execStat) { | |
runStat.updateStatOnConnection("getAll" + iterateId, 0, 0); | |
} | |
int tos_count_tLogRow_1 = 0; | |
// ///////////////////// | |
final String OUTPUT_FIELD_SEPARATOR_tLogRow_1 = "|"; | |
java.io.PrintStream consoleOut_tLogRow_1 = null; | |
StringBuilder strBuffer_tLogRow_1 = null; | |
int nb_line_tLogRow_1 = 0; | |
// ///////////////////// | |
/** | |
* [tLogRow_1 begin ] stop | |
*/ | |
/** | |
* [tRESTRequest_1 begin ] start | |
*/ | |
ok_Hash.put("tRESTRequest_1", false); | |
start_Hash.put("tRESTRequest_1", System.currentTimeMillis()); | |
currentComponent = "tRESTRequest_1"; | |
int tos_count_tRESTRequest_1 = 0; | |
getAll = null; | |
// *** external processor(s) initialization | |
// ESBProviderCallbackTalendJobInner | |
// providerCallback_tRESTRequest_1; | |
ESBProviderCallback providerCallback_tRESTRequest_1; | |
HandlerThread_tRESTRequest_1 handlerThread_tRESTRequest_1 = null; | |
// if (null == this.callback) { | |
final QueuedMessageHandlerImpl<java.util.Map<String, Object>> handler_tRESTRequest_1 = new QueuedMessageHandlerImpl<java.util.Map<String, Object>>(); | |
handlerThread_tRESTRequest_1 = new HandlerThread_tRESTRequest_1( | |
handler_tRESTRequest_1); // | |
handlerThread_tRESTRequest_1.start(); | |
// providerCallback_tRESTRequest_1 = new | |
// ESBProviderCallbackTalendJobWrapper_tRESTRequest_1(handler_tRESTRequest_1); | |
providerCallback_tRESTRequest_1 = handler_tRESTRequest_1; | |
// } else { | |
// // providerCallback_tRESTRequest_1 = new | |
// ESBProviderCallbackTalendJobWrapper_tRESTRequest_1(this.callback); | |
// providerCallback_tRESTRequest_1 = this.callback; | |
// } | |
globalMap.put("esbHandler", providerCallback_tRESTRequest_1); | |
// *** external processor(s) initialization finish | |
int nb_line_tRESTRequest_1 = 0; | |
try { | |
// This is a beginning of the ESB provider request component | |
// cycle | |
while (true) { | |
try { | |
/** | |
* [tRESTRequest_1 begin ] stop | |
*/ | |
/** | |
* [tRESTRequest_1 main ] start | |
*/ | |
currentComponent = "tRESTRequest_1"; | |
ESBProviderCallback esbHandler_tRESTRequest_1 = (ESBProviderCallback) globalMap | |
.get("esbHandler"); | |
java.util.Map<String, Object> requestMessage_tRESTRequest_1 = (java.util.Map<String, Object>) esbHandler_tRESTRequest_1 | |
.getRequest(); | |
if (requestMessage_tRESTRequest_1 | |
.containsKey("ERROR")) { | |
// wrong request received | |
esbHandler_tRESTRequest_1 | |
.sendResponse(new java.util.HashMap<String, Object>()); | |
getAll = null; | |
} else { // non-error (not wrong request) | |
String matchedUriPattern_tRESTRequest_1 = (String) requestMessage_tRESTRequest_1 | |
.get("PATTERN"); | |
String matchedFlow_tRESTRequest_1 = (String) requestMessage_tRESTRequest_1 | |
.get("OPERATION"); | |
String restWord_tRESTRequest_1 = (String) requestMessage_tRESTRequest_1 | |
.get("WORD"); | |
// String uri_tRESTRequest_1 = (String) | |
// requestMessage_tRESTRequest_1.get("URI"); | |
String body_tRESTRequest_1 = (String) requestMessage_tRESTRequest_1 | |
.get("BODY"); | |
java.util.Map<String, Object> params_tRESTRequest_1 = (java.util.Map<String, Object>) requestMessage_tRESTRequest_1 | |
.get("PARAMS"); | |
if (matchedFlow_tRESTRequest_1.equals("getAll")) { | |
getAll = new getAllStruct(); | |
if (params_tRESTRequest_1 | |
.containsKey("uri")) { | |
getAll.uri = (String) params_tRESTRequest_1 | |
.get("uri"); | |
} | |
} else { // non matched flow | |
getAll = null; | |
} | |
} | |
tos_count_tRESTRequest_1++; | |
/** | |
* [tRESTRequest_1 main ] stop | |
*/ | |
// Start of branch "getAll" | |
if (getAll != null) { | |
/** | |
* [tLogRow_1 main ] start | |
*/ | |
currentComponent = "tLogRow_1"; | |
// getAll | |
// getAll | |
if (execStat) { | |
runStat.updateStatOnConnection("getAll" | |
+ iterateId, 1, 1); | |
} | |
// ///////////////////// | |
strBuffer_tLogRow_1 = new StringBuilder(); | |
if (getAll.uri != null) { // | |
strBuffer_tLogRow_1.append(String | |
.valueOf(getAll.uri)); | |
} // | |
if (globalMap.get("tLogRow_CONSOLE") != null) { | |
consoleOut_tLogRow_1 = (java.io.PrintStream) globalMap | |
.get("tLogRow_CONSOLE"); | |
} else { | |
consoleOut_tLogRow_1 = new java.io.PrintStream( | |
new java.io.BufferedOutputStream( | |
System.out)); | |
globalMap.put("tLogRow_CONSOLE", | |
consoleOut_tLogRow_1); | |
} | |
consoleOut_tLogRow_1 | |
.println(strBuffer_tLogRow_1.toString()); | |
consoleOut_tLogRow_1.flush(); | |
nb_line_tLogRow_1++; | |
// //// | |
// //// | |
// ///////////////////// | |
row1 = getAll; | |
tos_count_tLogRow_1++; | |
/** | |
* [tLogRow_1 main ] stop | |
*/ | |
/** | |
* [tXMLMap_1 main ] start | |
*/ | |
currentComponent = "tXMLMap_1"; | |
// row1 | |
// row1 | |
if (execStat) { | |
runStat.updateStatOnConnection("row1" | |
+ iterateId, 1, 1); | |
} | |
boolean rejectedInnerJoin_tXMLMap_1 = false; | |
boolean rejectedDocInnerJoin_tXMLMap_1 = false; | |
boolean mainRowRejected_tXMLMap_1 = false; | |
boolean isMatchDocRowtXMLMap_1 = false; | |
GenerateDocument_eee gen_Doc_eee_tXMLMap_1 = new GenerateDocument_eee(); | |
eee_tmp.xml = null; | |
// ////////////////////////////////////////////////////// | |
{ | |
Var__tXMLMap_1__Struct Var = Var__tXMLMap_1; | |
// ############################### | |
// # Outputs initialization | |
boolean rejected_tXMLMap_1 = true; | |
boolean alreadyMapped_tXMLMap_1 = false; | |
eee = null; | |
// output table :'eee' | |
gen_Doc_eee_tXMLMap_1.generateElements( | |
rejectedDocInnerJoin_tXMLMap_1 | |
, row1, Var); | |
if (eee_tmp.xml == null) { | |
eee_tmp.xml = new Document(); | |
eee_tmp.xml | |
.setDocument(gen_Doc_eee_tXMLMap_1 | |
.getDocument()); | |
} | |
eee_save = eee_tmp; | |
eee_tmp.string = "Foo"; | |
eee = eee_tmp; | |
}// end var | |
tos_count_tXMLMap_1++; | |
/** | |
* [tXMLMap_1 main ] stop | |
*/ | |
// Start of branch "eee" | |
if (eee != null) { | |
/** | |
* [tRESTResponse_1 main ] start | |
*/ | |
currentComponent = "tRESTResponse_1"; | |
// eee | |
// eee | |
if (execStat) { | |
runStat.updateStatOnConnection("eee" | |
+ iterateId, 1, 1); | |
} | |
Integer restProviderStatusCode_tRESTResponse_1 = 200; | |
String restProviderResponse_tRESTResponse_1 = null; | |
ESBProviderCallback esbHandler_tRESTResponse_1 = (ESBProviderCallback) globalMap | |
.get("esbHandler"); | |
if (null != esbHandler_tRESTResponse_1) { | |
java.util.Map<String, Object> restResponse_tRESTResponse_1 = new java.util.HashMap<String, Object>(); | |
restResponse_tRESTResponse_1 | |
.put("BODY", | |
restProviderResponse_tRESTResponse_1); | |
restResponse_tRESTResponse_1 | |
.put("STATUS", | |
restProviderStatusCode_tRESTResponse_1); | |
esbHandler_tRESTResponse_1 | |
.sendResponse(restResponse_tRESTResponse_1); | |
} | |
tos_count_tRESTResponse_1++; | |
/** | |
* [tRESTResponse_1 main ] stop | |
*/ | |
} // End of branch "eee" | |
} // End of branch "getAll" | |
/** | |
* [tRESTRequest_1 end ] start | |
*/ | |
currentComponent = "tRESTRequest_1"; | |
// } catch (ESBJobInterruptedException e) { | |
// // job interrupted from outside | |
// break; | |
} catch (Throwable e) { | |
// ((ESBProviderCallbackTalendJobInner) | |
// globalMap.get("esbHandler")).sendFault(e); | |
} finally { | |
// Exit from this loop is made by the configuring | |
// "Keep listening" | |
// parameter to false. Then we will have a break | |
// before. | |
if ("false".equals("true")) { | |
break; | |
} | |
} | |
nb_line_tRESTRequest_1++; | |
globalMap.put("tRESTRequest_1_NB_LINE", | |
nb_line_tRESTRequest_1); | |
} // This is the end of the ESB Provider loop | |
} finally { | |
// for "keep listening" == false web service need a time to | |
// serve response | |
Thread.currentThread(); | |
Thread.sleep(500); | |
// unsubscribe | |
if (null != handlerThread_tRESTRequest_1) { | |
// stop endpoint in case it was opened by job | |
handlerThread_tRESTRequest_1.stopEndpoint(); | |
} | |
} | |
ok_Hash.put("tRESTRequest_1", true); | |
end_Hash.put("tRESTRequest_1", System.currentTimeMillis()); | |
/** | |
* [tRESTRequest_1 end ] stop | |
*/ | |
/** | |
* [tLogRow_1 end ] start | |
*/ | |
currentComponent = "tLogRow_1"; | |
// //// | |
// //// | |
globalMap.put("tLogRow_1_NB_LINE", nb_line_tLogRow_1); | |
// ///////////////////// | |
if (execStat) { | |
runStat.updateStatOnConnection("getAll" + iterateId, 2, 0); | |
} | |
ok_Hash.put("tLogRow_1", true); | |
end_Hash.put("tLogRow_1", System.currentTimeMillis()); | |
/** | |
* [tLogRow_1 end ] stop | |
*/ | |
/** | |
* [tXMLMap_1 end ] start | |
*/ | |
currentComponent = "tXMLMap_1"; | |
if (execStat) { | |
runStat.updateStatOnConnection("row1" + iterateId, 2, 0); | |
} | |
ok_Hash.put("tXMLMap_1", true); | |
end_Hash.put("tXMLMap_1", System.currentTimeMillis()); | |
/** | |
* [tXMLMap_1 end ] stop | |
*/ | |
/** | |
* [tRESTResponse_1 end ] start | |
*/ | |
currentComponent = "tRESTResponse_1"; | |
if (execStat) { | |
runStat.updateStatOnConnection("eee" + iterateId, 2, 0); | |
} | |
ok_Hash.put("tRESTResponse_1", true); | |
end_Hash.put("tRESTResponse_1", System.currentTimeMillis()); | |
/** | |
* [tRESTResponse_1 end ] stop | |
*/ | |
}// end the resume | |
} catch (Exception e) { | |
throw new TalendException(e, currentComponent, globalMap); | |
} catch (Error error) { | |
runStat.stopThreadStat(); | |
throw new Error(error); | |
} | |
globalMap.put("tRESTRequest_1_SUBPROCESS_STATE", 1); | |
} | |
public String resuming_logs_dir_path = null; | |
public String resuming_checkpoint_path = null; | |
public String parent_part_launcher = null; | |
private String resumeEntryMethodName = null; | |
private boolean globalResumeTicket = false; | |
public boolean watch = false; | |
// portStats is null, it means don't execute the statistics | |
public Integer portStats = null; | |
public int portTraces = 4334; | |
public String clientHost; | |
public String defaultClientHost = "localhost"; | |
public String contextStr = "Default"; | |
public boolean isDefaultContext = true; | |
public String pid = "0"; | |
public String rootPid = null; | |
public String fatherPid = null; | |
public String fatherNode = null; | |
public long startTime = 0; | |
public boolean isChildJob = false; | |
private boolean execStat = true; | |
private ThreadLocal threadLocal = new ThreadLocal(); | |
{ | |
java.util.Map threadRunResultMap = new java.util.HashMap(); | |
threadRunResultMap.put("errorCode", null); | |
threadRunResultMap.put("status", ""); | |
threadLocal.set(threadRunResultMap); | |
} | |
private java.util.Properties context_param = new java.util.Properties(); | |
public java.util.Map<String, Object> parentContextMap = new java.util.HashMap<String, Object>(); | |
public String status = ""; | |
public static void main(String[] args) { | |
final DemoREST DemoRESTClass = new DemoREST(); | |
int exitCode = DemoRESTClass.runJobInTOS(args); | |
System.exit(exitCode); | |
} | |
public String[][] runJob(String[] args) { | |
int exitCode = runJobInTOS(args); | |
String[][] bufferValue = new String[][] { { Integer.toString(exitCode) } }; | |
return bufferValue; | |
} | |
public int runJobInTOS(String[] args) { | |
String lastStr = ""; | |
for (String arg : args) { | |
if (arg.equalsIgnoreCase("--context_param")) { | |
lastStr = arg; | |
} else if (lastStr.equals("")) { | |
evalParam(arg); | |
} else { | |
evalParam(lastStr + " " + arg); | |
lastStr = ""; | |
} | |
} | |
if (clientHost == null) { | |
clientHost = defaultClientHost; | |
} | |
if (pid == null || "0".equals(pid)) { | |
pid = TalendString.getAsciiRandomString(6); | |
} | |
if (rootPid == null) { | |
rootPid = pid; | |
} | |
if (fatherPid == null) { | |
fatherPid = pid; | |
} else { | |
isChildJob = true; | |
} | |
if (portStats != null) { | |
// portStats = -1; //for testing | |
if (portStats < 0 || portStats > 65535) { | |
// issue:10869, the portStats is invalid, so this client socket | |
// can't open | |
System.err.println("The statistics socket port " + portStats | |
+ " is invalid."); | |
execStat = false; | |
} | |
} else { | |
execStat = false; | |
} | |
try { | |
// call job/subjob with an existing context, like: | |
// --context=production. if without this parameter, there will use | |
// the default context instead. | |
java.io.InputStream inContext = DemoREST.class.getClassLoader() | |
.getResourceAsStream( | |
"demo/demorest_0_1/contexts/" + contextStr | |
+ ".properties"); | |
if (isDefaultContext && inContext == null) { | |
} else { | |
if (inContext != null) { | |
// defaultProps is in order to keep the original context | |
// value | |
defaultProps.load(inContext); | |
inContext.close(); | |
context = new ContextProperties(defaultProps); | |
} else { | |
// print info and job continue to run, for case: | |
// context_param is not empty. | |
System.err.println("Could not find the context " | |
+ contextStr); | |
} | |
if (!context_param.isEmpty()) { | |
context.putAll(context_param); | |
} | |
} | |
} catch (java.io.IOException ie) { | |
System.err.println("Could not load context " + contextStr); | |
ie.printStackTrace(); | |
} | |
// get context value from parent directly | |
if (parentContextMap != null && !parentContextMap.isEmpty()) { | |
} | |
// Resume: init the resumeUtil | |
resumeEntryMethodName = ResumeUtil | |
.getResumeEntryMethodName(resuming_checkpoint_path); | |
resumeUtil = new ResumeUtil(resuming_logs_dir_path, isChildJob, rootPid); | |
resumeUtil.initCommonInfo(pid, rootPid, fatherPid, projectName, | |
jobName, contextStr, jobVersion); | |
// Resume: jobStart | |
resumeUtil.addLog("JOB_STARTED", "JOB:" + jobName, | |
parent_part_launcher, Thread.currentThread().getId() + "", "", | |
"", "", "", resumeUtil.convertToJsonText(context)); | |
if (execStat) { | |
try { | |
runStat.openSocket(!isChildJob); | |
runStat.setAllPID(rootPid, fatherPid, pid, jobName); | |
runStat.startThreadStat(clientHost, portStats); | |
runStat.updateStatOnJob(RunStat.JOBSTART, fatherNode); | |
} catch (java.io.IOException ioException) { | |
ioException.printStackTrace(); | |
} | |
} | |
long startUsedMemory = Runtime.getRuntime().totalMemory() | |
- Runtime.getRuntime().freeMemory(); | |
long endUsedMemory = 0; | |
long end = 0; | |
startTime = System.currentTimeMillis(); | |
this.globalResumeTicket = true;// to run tPreJob | |
this.globalResumeTicket = false;// to run others jobs | |
try { | |
errorCode = null; | |
tRESTRequest_1Process(globalMap); | |
if (!"failure".equals(status)) { | |
status = "end"; | |
} | |
} catch (TalendException e_tRESTRequest_1) { | |
status = "failure"; | |
e_tRESTRequest_1.printStackTrace(); | |
globalMap.put("tRESTRequest_1_SUBPROCESS_STATE", -1); | |
} finally { | |
} | |
this.globalResumeTicket = true;// to run tPostJob | |
end = System.currentTimeMillis(); | |
if (watch) { | |
System.out.println((end - startTime) + " milliseconds"); | |
} | |
endUsedMemory = Runtime.getRuntime().totalMemory() | |
- Runtime.getRuntime().freeMemory(); | |
if (false) { | |
System.out.println((endUsedMemory - startUsedMemory) | |
+ " bytes memory increase when running : DemoREST"); | |
} | |
if (execStat) { | |
runStat.updateStatOnJob(RunStat.JOBEND, fatherNode); | |
runStat.stopThreadStat(); | |
} | |
int returnCode = 0; | |
if (errorCode == null) { | |
returnCode = status != null && status.equals("failure") ? 1 : 0; | |
} else { | |
returnCode = errorCode.intValue(); | |
} | |
resumeUtil.addLog("JOB_ENDED", "JOB:" + jobName, parent_part_launcher, | |
Thread.currentThread().getId() + "", "", "" + returnCode, "", | |
"", ""); | |
return returnCode; | |
} | |
private void evalParam(String arg) { | |
if (arg.startsWith("--resuming_logs_dir_path")) { | |
resuming_logs_dir_path = arg.substring(25); | |
} else if (arg.startsWith("--resuming_checkpoint_path")) { | |
resuming_checkpoint_path = arg.substring(27); | |
} else if (arg.startsWith("--parent_part_launcher")) { | |
parent_part_launcher = arg.substring(23); | |
} else if (arg.startsWith("--watch")) { | |
watch = true; | |
} else if (arg.startsWith("--stat_port=")) { | |
String portStatsStr = arg.substring(12); | |
if (portStatsStr != null && !portStatsStr.equals("null")) { | |
portStats = Integer.parseInt(portStatsStr); | |
} | |
} else if (arg.startsWith("--trace_port=")) { | |
portTraces = Integer.parseInt(arg.substring(13)); | |
} else if (arg.startsWith("--client_host=")) { | |
clientHost = arg.substring(14); | |
} else if (arg.startsWith("--context=")) { | |
contextStr = arg.substring(10); | |
isDefaultContext = false; | |
} else if (arg.startsWith("--father_pid=")) { | |
fatherPid = arg.substring(13); | |
} else if (arg.startsWith("--root_pid=")) { | |
rootPid = arg.substring(11); | |
} else if (arg.startsWith("--father_node=")) { | |
fatherNode = arg.substring(14); | |
} else if (arg.startsWith("--pid=")) { | |
pid = arg.substring(6); | |
} else if (arg.startsWith("--context_param")) { | |
String keyValue = arg.substring(16); | |
int index = -1; | |
if (keyValue != null && (index = keyValue.indexOf('=')) > -1) { | |
context_param.put(keyValue.substring(0, index), | |
replaceEscapeChars(keyValue.substring(index + 1))); | |
} | |
} | |
} | |
private final String[][] escapeChars = { { "\\n", "\n" }, { "\\'", "\'" }, | |
{ "\\r", "\r" }, { "\\f", "\f" }, { "\\b", "\b" }, { "\\t", "\t" }, | |
{ "\\\\", "\\" } }; | |
private String replaceEscapeChars(String keyValue) { | |
if (keyValue == null || ("").equals(keyValue.trim())) { | |
return keyValue; | |
} | |
for (String[] strArray : escapeChars) { | |
keyValue = keyValue.replace(strArray[0], strArray[1]); | |
} | |
return keyValue; | |
} | |
public Integer getErrorCode() { | |
return errorCode; | |
} | |
public String getStatus() { | |
return status; | |
} | |
ResumeUtil resumeUtil = null; | |
} | |
/************************************************************************************************ | |
* 56463 characters generated by Talend Open Studio for ESB on the October 4, | |
* 2011 4:16:00 PM CEST | |
************************************************************************************************/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment