GWT - Fail to Read properties - file

When I run in hosted mode, it able to get the result.
But when I deploy it to tomcat then I cant get the result at all.
Anyone can tell me what is the problem??
public class Customwidget implements EntryPoint {
private static final SystemConfig constants = (SystemConfig)GWT.create(SystemConfig.class);
public void onModuleLoad() {
Window.alert(constants.DBServerName());
}
SystemConfig.properties :
DBServerName=guaz
SystemConfig.java :
import com.google.gwt.i18n.client.Constants;
public interface SystemConfig extends Constants {
String DBServerName();
String DB_ServerName();
String DB_PortNumber();
String DB_DatabaseName();
String DB_IntegratedSecurity();
String DB_Password();
String DB_User();
}
thanks

Your properties files must be located/copied in the /WEB-INF/classes subfolder of your web application.

Related

What's the purpose of creating another class "ExtentReports" here?

public class ExtentReportDemo {
#BeforeTest
public void config()
{
String path = System.getProperty("user.dir")+\\reports\index.html; //user.dir - it means project path in the system
ExtentSparkReporter reporter = new ExtentSparkReporter(path);
reporter.config().setReportName("Web Automation results");
reporter.config().setDocumentTitle("Test results");
ExtentReports extent =new ExtentReports();
extent.attachReporter(reporter);
}
Above code already has "ExtentSparkReporter" class in 4th line but what's the purpose of creating another class called "ExtentReports" here in last two lines?
ExtentReports extent =new ExtentReports();
extent.attachReporter(reporter);

Is there any way to Convert byte array to String in modelAttribute?

I have a model class called "Post" which has an attribute "postContent" as a byteArray.
public class Post{
byte[] postContnet;
//getters
//setters
...
}
So, I am using spring boot and spring form tag for getting the user's input using modelAttribute. The reason I am using byte array is I am using Ckeditor to get the WYSIWYG content.
<form:form ...... modelAttribute="post">
...
<form:textarea path="postContect" id="editor1">
....
</form:form>
While inserting the post to DB, I did not convert anything and it is inserted in MySQL DB where the postContent column is Blob type. However, when I am retrieving the content back for the edit purpose, I am getting byte array rather it should be a String. In a controller, I am getting and sending the data to JSP as below:
....
Post post = postService.findByPostId(postId);
if (post != null) {
mv.addObject("title", "Edit Post");
mv.addObject("post", post);
...
So, when I use JSTL in JSP, it prints the postContect as an array. I could get many references where converting the String to byte array and wise versa but here since I am using spring form and modelAttribute I am not sure where should I edit. How could I get back String in between?
Thanks.
I have found out the answer and it works for me. I am adding the comment here because someone who has a similar issue will get an idea.
I created Spring converter for a string to byte array
#Component
public class StringBase64ToByteArray implements Converter {
#Override
public byte[] convert(String source) {
byte[] byteSource = null;
System.out.println("StringBase64ToByteArray is called");
try {
byteSource = Base64.getEncoder().encode(source.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return byteSource;
}
}
Then I created another converter to byte array to string
#Component
public class ByteArrayToStringBase64 implements Converter{
#Override
public String convert(byte[] source) {
byte[] decodedString = Base64.getDecoder().decode(source);
return new String(decodedString);
}
}
I have registered both converters to spring boot configuration
#Configuration
public class WebMvcConfig implements WebMvcConfigurer{
#Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new StringBase64ToByteArray());
registry.addConverter(new ByteArrayToStringBase64());
}
}

2sxc - Use shared classes in SxcApiController

If I use that code for my ScxApiController
public class InstallController : SxcApiController
{
[HttpGet]
[AllowAnonymous]
public object Test()
{
return new MyObj();
}
}
public class MyObj
{
public int MyProperty1 { get; set; }
public int MyProperty2 { get; set; }
public int MyProperty3 { get; set; }
}
All work fine, but I want to be able to put MyObj code to separete file. If I just move this code to separate file the class is not found. How I can move this code outside the main class that still work?
==== Solution 1 ==========================================
1 - Move MyObj file to /App_Code folder
2 - Add namespace in this new file
3 - Use MyObj with namespace or add using
This is OK for custom project but don't know how to pack this file to module installer
Basically what you want to do is beyond the standard compile-on-demand setup. Usually you would put this in a visual studio project and build DLLs. This is of course more complex than what 2sxc is usually used for, but we also do this a lot when we have sophisticated business logic.

java.lang.IllegalStateException : Attempting Create Multiple Associations On Variables of Class

first post here, hoping someone could perhaps shed some light on an issue I've been trying to juggle...
As a part of a school project we're attempting to build a interface to display points on a map and paths on a map.
For our first sprint I managed to work out storing/retrieving items using Objectify - it went great!
Now we're trying to extend the functionality for our next spring. Having problems now trying to store an object of type MapPath (note MapPath and MapData, our two data types, both extend class Data). Brief code snippets as follows :
#Entity
public class Data extends JavaScriptObject
{
#Id
Long id;
private String name;
private String dataSet;
...getters and setters
}
#Subclass
public class MapData extends Data implements Serializable{
{
private String name;
private String address;
private String dataSet;
#Embedded
private Coordinate location;
....constructors, getters/setters
}
#Subclass
public class PathData extends Data implements Serializable{
private String name;
private String address;
private String dataSet;
#Embedded
private Coordinate[] path;
...etc
}
Now hopefully I haven't lost you yet. I have a DataService class that basically handles all transactions. I have the following unit test :
#Test
public void storeOnePath(){
PathData pd = new PathData();
pd.setName("hi");
DataService.storeSingleton(pd);
Data d = DataService.getSingleton("hi");
assertEquals(pd,d);
}
The implementation of getSingleton is as follows :
public static void storeSingleton(Data d){
Objectify obj = ObjectifyService.begin();
obj.put(d);
}
JUnit complains:
java.lang.ExceptionInInitializerError
at com.teamrawket.tests.DataTest.storeOnePath(DataTest.java:59)
...<taken out>
Caused by: java.lang.IllegalStateException: Attempting to create multiple associations on class com.teamrawket.server.MapData for name
at com.googlecode.objectify.impl.Transmog$Visitor.addRootSetter(Transmog.java:298)
at com.googlecode.objectify.impl.Transmog$Visitor.visitField(Transmog.java:231)
at com.googlecode.objectify.impl.Transmog$Visitor.visitClass(Transmog.java:134)
at com.googlecode.objectify.impl.Transmog.<init>(Transmog.java:319)
at com.googlecode.objectify.impl.ConcreteEntityMetadata.<init>(ConcreteEntityMetadata.java:75)
at com.googlecode.objectify.impl.Registrar.registerPolymorphicHierarchy(Registrar.java:128)
at com.googlecode.objectify.impl.Registrar.register(Registrar.java:62)
at com.googlecode.objectify.ObjectifyFactory.register(ObjectifyFactory.java:209)
at com.googlecode.objectify.ObjectifyService.register(ObjectifyService.java:38)
at com.teamrawket.server.DataService.<clinit>(DataService.java:20)
... 27 more
What exactly does "attempting to create multiple associations on class ... for name" imply?
Sorry for the long post and any formatting issues that may arise.
You have repeated field names in your subclasses. You should not declare 'name' and 'dataSet' in both superclasses and subclasses; remove these fields from MapData and PathData and you should be fine.
com.teamrawket.server.MapData refers to the fullPath name for your MapData file. The name at the end refers to the field String name in your MapData class. This whole exception tries to tell you that it already contains a reference for that specific fullPath.
I would say there is another object with the same fullPath already registered. It would be helpful to know where line 59 is exactly as that is where the error occured.

Inheritance concept in jpa

I created one table using Inheritance concept to sore data into google app engine datastore. It contained following coding but it shows error.How to user Inheritance concept.What error in my program
Program 1:
#Entity
#Inheritance(strategy = InheritanceType.JOINED)
public class calender {
#Id
private String EmailId;
#Basic
private String CalName;
#Basic
public void setEmailId(String emailId) {
EmailId = emailId;
}
public String getEmailId() {
return EmailId;
}
public void setCalName(String calName) {
CalName = calName;
}
public String getCalName() {
return CalName;
}
public calender(String EmailId, String CalName) {
this.EmailId = EmailId;
this.CalName = CalName;
}
}
Program 2:
#Entity
public class method extends calender {
#Id
private String method;
public void setMethod(String method) {
this.method = method;
}
public String getMethod() {
return method;
}
public method(String method) {
this.method = method;
}
}
My constraint is I want output like this
Calendartable contain
Emailid
calendarname
and method table contain
Emailid
method
How to achieve this?
It shows the following error in this line public method(String method)
java.lang.Error: Unresolved compilation problem:
Implicit super constructor calender() is undefined. Must explicitly invoke another constructor
According to Using JPA with App Engine, the JOINED inheritance strategy is not supported.
Your code doesn't compile, add a default constructor in Calendar.
I don't think you should annotate the method field with #Id.
The datastore of GAE/J is not an RDBMS so consequently the only "inheritance strategy" that makes any sense is TABLE_PER_CLASS. I would expect GAE/J to throw an exception if you specify that strategy, and if it doesn't then you ought to raise an issue against them
Your error "constructor calender() is undefined" is rather straightforward. You should create constructor without parameters in calendar class (you can make it private if you don't want to use it). That's because compiler can create default constructor by himself only if there aren't another constructors in the class.

Resources