GWT upload error FileNotFoundException - gwt

I'm uploading the files on the server like this: I create folder on the server and then I put all my uploading files in this folder
#Override
public String executeAction(HttpServletRequest request,
List<FileItem> sessionFiles) throws UploadActionException {
String response = "";
int cont = 0;
userNumber = request.getParameter("userNumber");
File f = new File(ConfAppServer.getRealContextPath() + "/edoc/"
+ userNumber);
for (FileItem item : sessionFiles) {
if (false == item.isFormField()) {
cont++;
try {
String extension = item.getName().substring(
item.getName().length() - 3);
File file = null;
file = new File(ConfAppServer.getRealContextPath()
+ "/edoc/"
+ userNumber
+ System.getProperty("file.separator")
+ item.getName().substring(0,
item.getName().length() - 4) + "."
+ extension);
item.write(file);
receivedFiles.put(item.getFieldName(), file);
receivedContentTypes.put(item.getFieldName(),
item.getContentType());
response += "<file-" + cont + "-field>"
+ item.getFieldName() + "</file-" + cont
+ "-field>\n";
response += "<file-" + cont + "-name>" + item.getName()
+ "</file-" + cont + "-name>\n";
response += "<file-" + cont + "-size>" + item.getSize()
+ "</file-" + cont + "-size>\n";
response += "<file-" + cont + "-type>"
+ item.getContentType() + "</file-" + cont
+ "type>\n";
} catch (Exception e) {
throw new UploadActionException(e);
}
}
}
removeSessionFileItems(request);
return "<response>\n" + response + "</response>\n";
}
It works ver well on my colleague computer, but on my computer I get an error
There is an error in file name. Help me please fix my problem. Thanks.

As you can see the file name is not displaying correcly. So the problem is the encoding of the Request/Response. You need to add a filter servlet. Here is a tutorial.

Related

android display arraylist items in dialog

I am having an arraylist fetching name and status of a person. Arraylist is storing the status and name. Its displaying one name at a time. How can I be able to display multiple names at once in alert dialog?
private ArrayList getunfiledRogspDoctorList() {
SqlDataStore sd = new SqlDataStore(this);
sd.open();
String gspQuery = " SELECT * FROM "+ TABLE_DOCTOR + " WHERE " + Queryclass.DOCTOR_ROGSP_STATUS + " == " + 0 + " AND " + Queryclass.DOCTOR_DATE_ID + " = '" + selectionID + "'";
Cursor gspCu = sd.getData(gspQuery);
if(gspCu.moveToFirst()){
do {
rogspname = gspCu.getString(gspCu.getColumnIndex(Queryclass.DOCTOR_CONTACTNAME));
unfiledrogspDoctorList.add(gspCu.getString(gspCu.getColumnIndex(Queryclass.DOCTOR_ROGSP_STATUS)) + rogspname);
}while (gspCu.moveToNext());
}
gspCu.close();
sd.close();
System.out.println("unfiledrogspDoctorList "+unfiledrogspDoctorList);
return unfiledrogspDoctorList;
}
From the code, you are having an ArrayList of your target display String in unfiledrogspDoctorList:
// Suggest to also define the type of your returning ArrayList
private ArrayList<String> getunfiledRogspDoctorList() {
// Define a local ArrayList
ArrayList<String> unfiledrogspDoctorList = new ArrayList<>();
SqlDataStore sd = new SqlDataStore(this);
sd.open();
String gspQuery = " SELECT * FROM "+ TABLE_DOCTOR + " WHERE " + Queryclass.DOCTOR_ROGSP_STATUS + " == " + 0 + " AND " + Queryclass.DOCTOR_DATE_ID + " = '" + selectionID + "'";
Cursor gspCu = sd.getData(gspQuery);
if(gspCu.moveToFirst()){
do {
rogspname = gspCu.getString(gspCu.getColumnIndex(Queryclass.DOCTOR_CONTACTNAME));
unfiledrogspDoctorList.add(gspCu.getString(gspCu.getColumnIndex(Queryclass.DOCTOR_ROGSP_STATUS)) + rogspname);
}while (gspCu.moveToNext());
}
gspCu.close();
sd.close();
System.out.println("unfiledrogspDoctorList "+unfiledrogspDoctorList);
return unfiledrogspDoctorList;
}
You can consider to convert your ArrayList of String into just a String.
private String concat(ArrayList<String> unfiledrogspDoctorList) {
StringBuilder sb = new StringBuilder();
for (String item : unfiledrogspDoctorList) {
sb.append(item);
sb.append(","); // Or change into other separate you would like to display
}
sb.setLength(Math.max(0, sb.length() - 1)); // Remove the appending character
return sb.toString();
}
Then you can make use of an AlertDialog to display that concatenated String.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder
.setMessage(concat(getunfiledRogspDoctorList()))
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Do anything upon pressing OK button
}
);
AlertDialog alert = builder.create();
alert.show();
You could use :-
SELECT group_concat(name) FROM ....
or to place each on a line you could change the default comma separator to a line feed using
SELECT group_concat(name,'\n') FROM ....
.... representing the rest of the SQL in the question
See https://www.sqlite.org/lang_aggfunc.html#group_concat
note that the GROUP as no GROUP BY clause is provided is a single group (and therefore output row) made up of ALL extracted rows.

apache beam: accessing metrics during pipeline processing

Using the WordCount.java example to test metrics. The PrintMetricsFn function (see below) prints the metrics correctly once the pipeline is finished, but fails when called while the pipeline is processing. DirectRunner and FlinkRunner both throw exceptions (null input), while SparkRunner prints only the header line (similar to "* Metric Values *").
private static void PrintMetricsFn(final MetricsFilter inputFilter) {
final MetricResults metrics = result.metrics();
final MetricQueryResults returns = metrics.queryMetrics(inputFilter);
final Iterable<MetricResult<Long>> counters = returns.getCounters();
System.out.println("*** Metric Values ***");
for(final MetricResult<Long> s: counters){
System.out.println(s.getName().getNamespace() + ":" +
s.getName().getName() + ":" + s.getStep() + ": count=" +
s.getAttempted()) ;
}
final Iterable<MetricResult<DistributionResult>> dist = returns.getDistributions();
for (final MetricResult<DistributionResult> d: dist) {
System.out.println(d.getName().getNamespace() + ":" +
d.getName().getName() + ":" + d.getStep() + ": sum=" +
d.getAttempted().getSum() + ", count=" +
d.getAttempted().getCount() + ", min=" +
d.getAttempted().getMin() + ", max=" +
d.getAttempted().getMax() + ", mean=" +
d.getAttempted().getMean());
}
final Iterable<MetricResult<GaugeResult>> gauge = returns.getGauges();
for (final MetricResult<GaugeResult> g: gauge) {
System.out.println(g.getName().getNamespace() + ":" +
g.getName().getName() + ":" + g.getStep() + ": gauge=" +
g.getAttempted().getValue());
}
return;
}
Here are the declarations for the external variables:
private static PipelineResult result;
private static MetricQueryResults returns;
private static MetricsFilter mFilter;
And here's where the mFilter and result variables are set:
mFilter = MetricsFilter.builder()
.addNameFilter(MetricNameFilter.named("ExtractWordsFn", "emptyLines"))
.addNameFilter(MetricNameFilter.named("ExtractWordsFn", "lineLenDistro"))
.addNameFilter(MetricNameFilter.named("ExtractWordsFn", "maxLineLen"))
.build();
result = p.run();
Finally, here's the function that calls PrintMetricsFN without success:
#ProcessElement
public void processElement(#Element final String element, final OutputReceiver<String> receiver) {
lineLen = element.length();
lineLenDist.update(lineLen);
if (element.trim().isEmpty()) {
emptyLines.inc();
}
if (lineLen > localMax) {
localMax = lineLen;
maxLineLen.set(localMax);
}
if((lineCnt++ % 10) == 0) {
PrintMetricsFn(mFilter);
}
// Split the line into words.
final String[] words = element.split(ExampleUtils.TOKENIZER_PATTERN, -1);
// Output each word encountered into the output PCollection.
for (final String word : words) {
if (!word.isEmpty()) {
receiver.output(word);
}
}
}
And for completeness, here's the error I get from DirectRunner:
Caused by: java.lang.NullPointerException
at org.apache.beam.examples.WordCount.PrintMetricsFn(WordCount.java:158)
at org.apache.beam.examples.WordCount.access$1(WordCount.java:157)
at org.apache.beam.examples.WordCount$ExtractWordsFn.processElement(WordCount.java:132)

#AspectJ pointcut for execute methods of a package that contains keyword service

I'm trying to intercept all classes that contains a specific word in their package name... something as below:
#Pointcut("execution(* *..service..*.*(..))")
I have all the classes in the packages to intercept:
com.domain.model.user.service.save(User user);
com.domain.model.user.service.impl.save(XPTO xpto);
com.domain.model.foo.service.HelloWorld.getMessage(Foo foo);
In short, i would like to intercept all the methods in the classes that belong to the
package *service*
I am trying to get this working from past many days.
Try this. Perhaps you have to exclude your aspect classes to avoid endless loops. This example catch all methods with com..login..* in package
#Aspect
#SuppressAjWarnings({ "adviceDidNotMatch" })
public class AllMethodsAspect {
private static Map<String, Long> beforeTimestamps = new HashMap<>();
#Pointcut("!within(aspects..*)"
+ " && (!execution(* org..* (..)) && !within(org..*) && !call(* org..* (..)) )"
+ " && (!execution(* java..* (..)) && !within(java..*) && !call(* java..* (..)) )"
+ " && (!execution(* javax..* (..)) && !within(javax..*) && !call(* javax..* (..)) )"
+ " && (!execution(* sun..* (..)) && !within(sun..*) && !call(* sun..* (..)) )"
+ " && execution(* com..login..*(..))")
public void methodCall() {
}
#Before("methodCall()")
public void before(JoinPoint joinPoint) {
beforeMethodCall(joinPoint);
}
#AfterReturning(pointcut = "methodCall()", returning = "returnObject")
public void after(JoinPoint joinPoint, Object returnObject) {
afterMethodCall(joinPoint, returnObject);
}
#AfterThrowing(pointcut = "methodCall()", throwing = "throwable")
public void throwing(JoinPoint joinPoint, Throwable throwable) {
afterThrowingMethodCall(joinPoint, throwable);
}
void beforeMethodCall(JoinPoint joinPoint) {
try {
long start = System.currentTimeMillis();
beforeTimestamps.put(joinPoint.toString() + " - " + Thread.currentThread().getName(), Long.valueOf(start));
LOG.info(".before " + joinPoint);
} catch (Exception e) {
LOG.error(".before Exception " + e);
}
}
void afterMethodCall(JoinPoint joinPoint, Object returnObject) {
afterMethodCall(joinPoint, returnObject, 0);
}
void afterMethodCall(JoinPoint joinPoint, Object returnObject, int depth) {
try {
long start = beforeTimestamps.get(joinPoint.toString() + " - " + Thread.currentThread().getName()).longValue();
beforeTimestamps.remove(joinPoint.toString() + " - " + Thread.currentThread().getName());
long duration = System.currentTimeMillis() - start;
Signature signature = joinPoint.getSignature();
if (signature instanceof MethodSignature) {
Class<?> returnType = ((MethodSignature) signature).getReturnType();
LOG.info(".after " + joinPoint + " " + duration + "ms" + (void.class == returnType ? "" : " [" + returnObject + "]"));
} else if (signature instanceof ConstructorSignature) {
LOG.info(".after " + joinPoint + " " + duration + "ms Constructor");
} else if (signature instanceof FieldSignature) {
LOG.info(".after " + joinPoint + " " + duration + "ms Field");
} else {
LOG.info(".after " + joinPoint + " " + duration + "ms unknown");
}
} catch (Exception e) {
LOG.error(".after Exception " + e);
}
}
void afterThrowingMethodCall(JoinPoint joinPoint, Throwable throwable) {
try {
Long startAsLong = beforeTimestamps.get(joinPoint.toString() + " - " + Thread.currentThread().getName());
long start = startAsLong == null ? 0 : startAsLong.longValue();
beforeTimestamps.remove(joinPoint.toString() + " - " + Thread.currentThread().getName());
long duration = System.currentTimeMillis() - start;
LOG.info(".fail " + joinPoint.toString() + " " + duration + " ms - " + throwable.getMessage());
} catch (NullPointerException e) {
LOG.info(".fail NullPointerException " + "unknown - " + throwable.getMessage());
}
}
static final class LOG {
static void info(String loggingData) {
System.err.println(new Date() + " " + loggingData);
}
static void error(String loggingData) {
System.err.println(new Date() + " " + loggingData);
}
}
}
I think you can capture what you need with a pointcut like this:
before(): execution(* *(..)) &&
(within(*..service..*.*) || within(service..*.*) || within(*..service.*)) {}
The three within clauses capture the three alternatives:
within(*..service..*.*): 'service' is somewhere in the package name but not at the start or end
within(service..*.*): 'service' is at the start of the package name (maybe this can't happen in your scenario)
within(*..service.*)): 'service' is at the end of the package name
If you need to capture serviceFoo variants you could add further wildcards around service (I think): within(*..*service*.*)
You should use a pointcut expression like this:
within(your.base.package..service..*)
restrict to at least your base package (typically this is not an issue)
match 'service' keyword in your package name at any level
for example, this will match those classes :
your.base.package.service.ServiceClass
your.base.package.service.customer.ServiceClass
your.base.package.internal.service.ServiceClass
your.base.package.internal.service.customer.ServiceClass

On Maintaining Unique Scope between server and client. Still it reflect same data on sync with another client as i syn with first one. Why?

I have create Scope different between each client and one server in scope_info table in DB. Once i sync with first client on filter condition it work correct but on changing filter condition with another client still it sync same data as i get previously. My code as given below :
Here Value is Unique Identity of Client.
Code:
ArrayList UnSyncTable = new ArrayList();
SqlConnection clientConn = new SqlConnection(ClientString);
SqlConnection serverConn = new SqlConnection(ServerString);
for (int i = 0; i < ClientDs.Tables[0].Rows.Count; i++)
{
#region Start Sync
//////////////////////////////////////////////////////////////////////////////////
if (serverConn.State == ConnectionState.Closed)
{
serverConn.Open();
}
if (clientConn.State == ConnectionState.Closed)
{
clientConn.Open();
}
try
{
#region Step1 for ServerSide
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription(ClientDs.Tables[0].Rows[i][0].ToString() + "_SyncScope" + Value);
DbSyncTableDescription tableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable(ClientDs.Tables[0].Rows[i][0].ToString(), serverConn);
scopeDesc.Tables.Add(tableDesc);
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
#region Filter Condition
if (DBFilteredTables.Contains(ClientDs.Tables[0].Rows[i][0].ToString()))
{
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
serverProvision.Tables[ClientDs.Tables[0].Rows[i][0].ToString()].AddFilterColumn(AttributeName);
serverProvision.Tables[ClientDs.Tables[0].Rows[i][0].ToString()].FilterClause = "[side].[" + AttributeName + "] =" + Value;
}
#endregion
// start the provisioning process
serverProvision.Apply();
#endregion
}
catch
{
}
try
{
#region Step2 for ClientSide
DbSyncScopeDescription scopeDesc1 = SqlSyncDescriptionBuilder.GetDescriptionForScope(ClientDs.Tables[0].Rows[i][0].ToString() + "_SyncScope" + Value, serverConn);
SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc1);
clientProvision.Apply();
#endregion
}
catch
{
}
try
{
#region Step3
SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
syncOrchestrator.LocalProvider = new SqlSyncProvider(ClientDs.Tables[0].Rows[i][0].ToString() + "_SyncScope" + Value, clientConn);
syncOrchestrator.RemoteProvider = new SqlSyncProvider(ClientDs.Tables[0].Rows[i][0].ToString() + "_SyncScope" + Value, serverConn);
if (SyncCondition == 1)
syncOrchestrator.Direction = SyncDirectionOrder.Download;
else if (SyncCondition == 2)
syncOrchestrator.Direction = SyncDirectionOrder.DownloadAndUpload;
else if (SyncCondition == 3)
syncOrchestrator.Direction = SyncDirectionOrder.Upload;
else if (SyncCondition == 4)
syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload;
((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
//print statistics
string Msg = "Start Time : " + syncStats.SyncStartTime + "\n";
Msg += "Table Name : " + ClientDs.Tables[0].Rows[i][0].ToString() + "\n";
Msg += "Total Changes Uploaded : " + syncStats.UploadChangesTotal + "\n";
Msg += "Total Changes Downloaded : " + syncStats.DownloadChangesTotal + "\n";
Msg += "Complete Time : " + syncStats.SyncEndTime + "\n";
#endregion
}
catch
{
UnSyncTable.Add(ClientDs.Tables[0].Rows[i][0].ToString());
}
#endregion
}

suppose there is a class which contains 4 data fields.i have to read these value from xml file and set that value to data fields

suppose there is a class which contains 4 fields.i have to read these value from xml file and set that value to fields
the xml file is like that
<Root>
<Application >
<AppName>somevalue</AppName>
<IdMark>somevalue</IdMark>
<ClassName>ABC</ClassName>
<ExecName>XYZ</ExecName>
</Application>
<Application>
<AppName>somevalue</AppName>
<IdMark>somevalue</IdMark>
<ClassName>abc</ClassName>
<ExecName>xyz</ExecName>
</Application>
</Root>
now i have to read all the values from xml file and set each value to particular fields.
i hav done reading of the xml file
and i saved the retrieved value in arraylist.
the code is like that
public class CXmlFileHook
{
string appname;
string classname;
string idmark;
string execname;
string ctor;
public CXmlFileHook()
{
this.appname = "Not Set";
this.idmark = "Not Set";
this.classname = "Not Set";
this.execname = "Not Set";
this.ctor = "CXmlFileHook()";
}
public void readFromXmlFile(string path)
{
XmlTextReader oRreader = new XmlTextReader(#"D:\\Documents and Settings\\sunilr\\Desktop\\MLPACK.xml");
//string[] strNodeValues = new string[4] { "?","?","?","?"};
ArrayList oArrayList = new ArrayList();
while (oRreader.Read())
{
if (oRreader.NodeType == XmlNodeType.Element)
{
switch (oRreader.Name)
{
case "AppName":
oRreader.Read();
//strNodeValues[0] =oRreader.Value;
oArrayList.Add(oRreader.Value);
break;
case "IdMark":
oRreader.Read();
//strNodeValues[1] = oRreader.Value;
oArrayList.Add(oRreader.Value);
break;
case "ClassName":
oRreader.Read();
//strNodeValues[2] = oRreader.Value;
oArrayList.Add(oRreader.Value);
break;
case "ExecName":
oRreader.Read();
//strNodeValues[3] = oRreader.Value;
oArrayList.Add(oRreader.Value);
break;
}
}
}
Console.WriteLine("Reading from arraylist");
Console.WriteLine("-------------------------");
for (int i = 0; i < oArrayList.Count; i++)
{
//Console.WriteLine("Reading from Sting[]"+ strNodeValues[i]);
Console.WriteLine(oArrayList[i]);
}
//this.appname = strNodeValues[0];
//this.idmark = strNodeValues[1];
//this.classname = strNodeValues[2];
//this.execname = strNodeValues[3];
this.appname = oArrayList[0].ToString();
this.idmark = oArrayList[1].ToString();
this.classname = oArrayList[2].ToString();
this.execname = oArrayList[3].ToString();
}
static string vInformation;
public void showCurrentState(string path)
{
FileStream oFileStream = new FileStream(path, FileMode.Append, FileAccess.Write);
StreamWriter oStreamWriter = new StreamWriter(oFileStream);
oStreamWriter.WriteLine("****************************************************************");
oStreamWriter.WriteLine(" Log File ");
oStreamWriter.WriteLine("****************************************************************");
CXmlFileHook oFilehook = new CXmlFileHook();
//Type t = Type.GetType(this._classname);
//Type t = typeof(CConfigFileHook);
DateTime oToday = DateTime.Now;
vInformation += "Logfile created on : ";
vInformation += oToday + Environment.NewLine;
vInformation += "Public " + Environment.NewLine;
vInformation += "----------------------------------------------" + Environment.NewLine;
vInformation += "Private " + Environment.NewLine;
vInformation += "-----------------------------------------------" + Environment.NewLine;
vInformation += "ctor = " + this.ctor + Environment.NewLine;
vInformation += "appname = " + this.appname + Environment.NewLine;
vInformation += "idmark = " + this.idmark + Environment.NewLine;
vInformation += "classname = " + this.classname + Environment.NewLine;
vInformation += "execname = " + this.execname + Environment.NewLine;
vInformation += "------------------------------------------------" + Environment.NewLine;
vInformation += "Protected" + Environment.NewLine;
vInformation += "------------------------------------------------" + Environment.NewLine;
oStreamWriter.WriteLine(vInformation);
oStreamWriter.Flush();
oStreamWriter.Close();
oFileStream.Close();
}
}
here i set set the fields according to arraylist index but i dont want
is there any another solution for this....
Since there are libraries like Commons Digester why should one write such raw code to achieve this.