import projects in build path for web service: server or client? - web-services

I have created a little example app to test out the CN1 web service functionalities. Following the web service tutorial from CN1 (https://www.codenameone.com/how-do-i---access-remote-webservices-perform-operations-on-the-server.html), I have my Codename one project as client and a dynamic web project running on my Eclipse tomcat server hosting the servlet.
As I have objects that I pass back and forth between client and server, I want both projects to know about these java files. The way to do that is to put the file in one project, and modify the build path of the other to include the first project. This way, the import can resolve the file name just fine.
Question now is: is it better to put the files in one project or the other? Does either way affect the size of the resulting app file that I want to publish in a store? I want to keep the size as small as possible.
Thanks for any tips.
UPDATE: on the preliminary information provided by Shai, files that are to be shared among different projects (either client or server side), do not put your code in either but INSTEAD create a CN1 library for that. This library can then be added to the CN1 buildpath configuration (not the Java build path!) to all required projects.
Here are the details on how and why: https://www.codenameone.com/blog/new-preliminary-library-support.html
Just need to figure out how to do this on Eclipse, as it does not seem to be supported now.

You can use shared code with a cn1lib whose source you can include into the server project manually. In some cases we just copy the shared source files in the build script from one project to the other as it makes the process simpler.

Related

Codename One: Webservice not available

I used the CN1 Webservice Wizard to add a the webservice proxy to my mobile app and to generate all the server side code. I have a local XAMPP installation with a tomcat linked within my Eclipse IDE. Also, I imported the server generated code as a new Java Project and added the "Dynamic Web Module" project facet to it so that I could launch it not as a local Java application but rather on the Tomcat server.
When starting my client, I noted that I get HTTP 404, resource not found errors. I traced the error back to the URL, where the server is hosted to.
I know I have to adapt the urlPatterns parameter in the generated class CN1WebServiceServlet, which I did. Also, I checked the context of my app in the Web project settings and defined the value for context root. So, in my client app, the URL to call the service should be
http://localhost:8080/< context root>/< urlPattern>
However, even when calling that in the browser, I should get the result of the doGet method of the server generated code, showing the message "Webservice access only". Instead, I get 404 errors all the time.
Is there some problem to importing the server generated code as a plain Java project and adding the web parts to it afterwards? How would that be done in the ideal case?
And what other problems might be hindering the URL from properly being published on the server side?
Thanks and best regards
EDIT
I stripped everything from the project to limit the options and I found the cause: when using the web service wizard to dump the source files into a new directory, adding that with the Eclipse import wizard, it will be looked at as a plain java project without any web components. Using the project settings to add the dynamic web piece to it (Eclipse calls those project facets), the CN1 webservice will NOT work.
If instead you create a "Dynamic Web Project" first and then use the CN1 Webservice Wizard to dump the server source files into the "src" folder of that project, it works without any issues.

drop wizard - web app directory & edit static files

I started app development with drop-wizard recently and a bit confusing how the whole thing works.
Where is the web app directory?
Is it possible to edit static files (JS, CSS) without needing to have a redeployment?
Thanks.
I have looked into this a bit more and will attempt to answer your questions:
Where is the web app directory
DW applications are not (meant as) web applications. They are deployed as an embedded system running a jetty embedded server and listening on some port(s). Having said that, there are certainly ways of packaging the application as a web application. (see link in comment)
Is it possible to edit static files (JS, CSS) without needing to have a redeployment? - Yes(ish)
This depends on you, really. There is a thing called an AssetBundle. These can be used to server static resources (from the classpath usually). This however is a mechanism you could use to implement your own AssetBundle that instead of serving files off the classpath, will serve files off the regular path.
Or, you could add your regular path to the classpath on startup so that the AssetBundle works.
Or, you could implement a ServletFilter for the AssetBundle (assets are not part of the jersey ecosystem) and implement your dynamic changes in the Filter.
Most of these will require restart for a reason or another. E.g.a custom implementation of a Filter obviously requires a redeploy. The Servlet returning assets also (I believe) employs a caching strategy that might require a restart (subject to your implementation).
For your UI: There is also a DW-views project that adds the ability to create views (with by default mustache templates) that can be powered from your application and served by the same REST endpoints.
Hope that helps,
After some more checking:
You can serve static resources from the file system and modify them as you go. They will be served correctly. How to do this:
Add an asset bundle with the resource path:
bootstrap.addBundle(new AssetsBundle("/assets2/", "/assets"));
This adds the root classpath resource assets2 and has it served statically from the endpoint assets.
The trick is that you have to add your file system location as a classpath resource. This can be done via arguments (or the classpath tab in the eclipse run configuration). You can google that relatively easy. However, you will have to remember that classpath resources behave differently from file system resources:
In my case I added to the classpath:
/home/artur/tmp/assets/
However, my Asset bundle serves from "assets2". Let's have a look at the file system:
artur#pandaadb:~/tmp/assets$ pwd
/home/artur/tmp/assets
artur#pandaadb:~/tmp/assets$ find .
.
./assets2
./assets2/test.txt
artur#pandaadb:~/tmp/assets$
So, in my file system location has been added as root, but assets are only served from the subfolder assets2
Now, all the resources that are located in assets2 can be modified at runtime and will be served by DW as a static resource.
Have fun playing around,
Artur

How to "Run" a .svc WCF Web Service

I am working on a project that was last worked on by someone who hasn't been on the team in some time. Having gotten a hold of him to ask him questions about the project and next steps in general, I was told I need to run a Java web service. After not being able to find any .jws files in our network, I asked if a particular .svc (WCF Web Service) file was the right service and was told to "run [filename]" which is the .svc file. This file is in a directory with some relevant Java class files that appear to have been part of an eclipse project (which I am unable to open).
Now I've looked around and all tutorials I can find about running a .svc file involve a visual studio project and creating the project from scratch, not just running a single .svc file as a web service. I'm new to Windows in general and haven't seen a .svc file. Does it make since to say to simply "run" a .svc WCF Web Service? And does it make since that a .svc file would be created from a Java project? If so, how would I simply run that service?
I hope this question made sense. Thanks for any help!

Build application with client custom theme

I've an application with a default theme (less files defined in app/sytles and included in app.less) and reachable at my main website (for example http://www.example.com)
Now I need to build the same application for different clients. Each client has its own style customization (client.less file) and its own assets (images, fonts, ...). This site will be deployed at, for example, http://client1.example.com.
My idea was to customize the build process passing an additional flag to the ember build --environment production command and customize the build process adding the client.less file when needed.
Something like ember build --environment production --theme client1 but as far as I can see there isn't the possibility to pass extra flags to build command.
Am I missing something? There is a better way to achieve that? Any help is really appreciate, I wouldn't maintain one project for each client.

Is there a way to bind my flex builder to my django application

I am trying to create simple flex application, which uses django as a back-end part. Have a question:
Usually when I run my application Flex Builder creates a file in a directory on my local PC and then opens a browser and points to it. Everything was fine, but when I decided to link django server to flex applications via xml data providers I started to get security errors. (Related to absence of crossdomain.xml). When I created the file and put it on the server:
<?xml version="1.0"?>
<!-- http://www.foo.com/crossdomain.xml -->
<cross-domain-policy>
<allow-access-from domain="http://127.0.0.1:8000"/>
<allow-access-from domain="127.0.0.1"/>
</cross-domain-policy>
Then tried the application again, I got error in console of my FB Error: Request for resource at http://127.0.0.1:8000/go/active/ by requestor from file:///Users/oleg/Documents/FB3/usersList/bin-debug/usersList.swf is denied due to lack of policy file permissions.
I don't know how to fix the error. But also the question is there a way to configure FB3 to put my swf files to the server directly, so I will not need any crossdomain?
Thanks
Oleg
We struggled with this a lot. The Flex security stuff didn't strike me as well built, but perhaps we just had different approaches in mind than Adobe's developers. The solution that worked for us was to serve both the SWF and the dynamic data from the same host and port.
On our development boxes, we tell Apache to serve the SWF from a directory in the workspace, and the dynamic data from a local copy of the app. When we push to production, SWF and app get pushed simultaneously to the same virtual host.
If that's inconvenient for you, the Apache ProxyPass directive can be used to make Apache front for other servers. I've not used that in production, but it's been very handy for developer setups.
I don't know a way to get FlexBuilder to automatically deploy your changed SWF; you could certainly look into an automation approach (like Maven and Flex-Mojos) to make that happen.
That said, getting rid of that error is usually just a matter of adding a policy file to the server.
The second error is caused because you're trying to fetch http resources from a "file" location. My recommendation is that you change your Flex Builder project so it outputs to a location within the Django web site, rather than to the flex-bin directory. This setting can be changed in the properties dialog of the project. Then, you should be able to have your front-end and back-end share the same protocol and domain.