Use Undertwo web server to serve both static pages and web service - resteasy

I am trying to use Undertow to serve both static pages and web service (RestEasy) but couldn't get both of them working the same time. I see others asking the same questions like HTTP Handler and Resteasy Deployment with undertow and resteasy. There has to be a way to get this work, right? WildFly can handle both on the same port. But how could I do this? Thanks!

How about:
DeploymentInfo servletBuilder = deployment()
.setClassLoader(App.class.getClassLoader())
.setContextPath("/api")
.setDeploymentName("test.war")
.addServlets(
servlet("MessageServlet", MessageServlet.class)
.addInitParam("message", "Hello World")
.addMapping("/*"),
servlet("MyServlet", MessageServlet.class)
.addInitParam("message", "MyServlet")
.addMapping("/myservlet"));
DeploymentManager manager = defaultContainer().addDeployment(servletBuilder);
manager.deploy();
HttpHandler servletHandler = manager.start();
Undertow.builder().addHttpListener(8080, "0.0.0.0")
.setHandler(Handlers.path()
// REST API path
.addPrefixPath("/servlet", servletHandler)
// Serve all static files from a folder
.addPrefixPath("/static", new ResourceHandler(
new PathResourceManager(Paths.get("/path/to/www/"), 100))
.setWelcomeFiles("index.html"))
).build().start();
The servlet part is taken from Undertow's official examples, here.
You can talk to your Message servlets via:
GET /servlet/api
POST /servlet/api/myservlet

Related

Maven cxf-codegen-plugin with NTLM Authentication - fails with java.io.IOException: Server returned HTTP response code: 401 for URL

I'm trying to generate java code using cxf-codegen-plugin for a SOAP webservice that is secured over NTLM. I'm not sure how do pass on the username/pwd/domain information to maven to connect to the remote server while generating the java code. I could open the wsdl using the browser using the username/pwd/domain combination I have. However, I'm wondering how to do it via command-line by passing some extra vm args to - mvn package. Or is there any other plugin config that I can do which helps me to do this?

Using embedded jetty with camel-cxf

I have a couple of rest routes defined in my Camel project and now I'm trying to add a SOAP service to my project using the same jetty embedded server.
I have something like this:
restConfiguration()
.component("jetty")
.host("0.0.0.0")
.port(8080)
;
CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setCamelContext(getContext());
cxfEndpoint.setServiceClass(TestService.class);
cxfEndpoint.setAddress("http://0.0.0.0:8080/test");
from(cxfEndpoint)
.log(LoggingLevel.INFO, log, "test");
When I try to run the application, I get this error message:
Web server failed to start. Port 8080 was already in use.
Look like it's trying to start 2 instances of Jetty using the same port and that's why it's failing.
I would really like to make the cxf endpoint work with the embedded Jetty used for my other services. Is there any way to do that?

GAE: AssertionError: No api proxy found for service "datastore_v3"

I'm writing simple to code to access dev server. Both dev server and datastore emulated have been started locally.
from google.appengine.ext import ndb
class Account(ndb.Model):
name = ndb.StringProperty()
acc = Account(name=u"test").put()
print(acc)
Error:
AssertionError: No api proxy found for service "datastore_v3"
I tried to set: export DATASTORE_EMULATOR_HOST=localhost:8760 . It does not help.
$ dev_appserver.py ./app.yaml
WARNING 2017-02-20 06:40:23,130 application_configuration.py:176] The "python" runtime specified in "./app.yaml" is not supported - the "python27" runtime will be used instead. A description of the differences between the two can be found here:
https://developers.google.com/appengine/docs/python/python25/diff27
INFO 2017-02-20 06:40:23,131 devappserver2.py:764] Skipping SDK update check.
INFO 2017-02-20 06:40:23,508 api_server.py:268] Starting API server at: http://localhost:53755
INFO 2017-02-20 06:40:23,514 dispatcher.py:199] Starting module "default" running at: http://localhost:8080
INFO 2017-02-20 06:40:23,517 admin_server.py:116] Starting admin server at: http://localhost:8000
GAE app code cannot run as a standalone python app, it can only run inside a GAE app which runs inside your dev server. Typically as part of a handler code, triggered via http requests to the dev server.
You need to put that code inside one of your app handlers. For example inside the get() method of the MainPage handler from main.py in the Quickstart for Python App Engine Standard Environment (actually it'd be better in a post() method since your code is writing to the datastore).

Can run Angular app from local computer but not from local server

I can start and run my Angular app fine from my local computer. But I have never run it on a server before.
I have tried uploading it to the server. On the server I type the following to start it:
http-server
Then I visit http://serverip:8080/. Instead of seeing my app I see:
Index of /
(-rw-rw-r--) 847B app.js
(-rw-rw-r--) 748B index.htm
Node.js v0.10.25/ ecstatic server running # 195.189.182.160:8080
What is missing in my configuration?
ecstatic is a static file server. It's not set up to be a web server by default, even though it can work that way. When you do run it as a web server, certain standard options in most web servers - like treating a request for /path/ as a request for /path/index.htm - are disabled by default.
You need to enable opts.autoIndex. The package readme tells you how to do that. In your case, it means editing http-server or the .js file that it fires off; it's hard to say from what you have posted.

Unit testing OAuth JS with Mocha

I'm working on a JS based project that runs off GAE and part of the code gets the user's avatar using OAuth from Facebook, Twitter or Google. I'm trying to write tests in Mocha in order to test this but I'm running into some problems.
The code works when I test it in the front end, and the way I envisaged it to work would be to use ZombieJS to run the app on GAE's dev_appserver.py, fire the OAuth functions, fill in the appropriate auth stuff and then complete the test by returning the image URL.
However the first hurdle I've got is that it appears that NodeJS's server is not allowing GAE's server to run on the same IP address. For example:
exec 'dev_appserver.py .', ->
console.log arguments
This returns the error 'Address already in use'. How can I get around this apart from running it on a different machine? Is it possible to tell NodeJS to not reserve the whole IP and just a port? I'm running GAE on 8080 and it works fine when it isn't invoked by NodeJS.
The second problem is ZombieJS. I'm trying to figure out a way I can listen to when new windows are opened and, essentially, tail the console of the browser. I've started two discussions on the Google group but no one has responded yet (https://groups.google.com/forum/?hl=en#!topic/zombie-js/cJklyMbwxRE and https://groups.google.com/forum/?hl=en#!topic/zombie-js/tOhk_lZv5eA)
While the latter isn't as important as I can find ways around it (I hope), the former is the main issue, so I'd greatly appreciate any direction on how to resolve this address conflict.
Here's my NodeJS script:
exec = ( require 'child_process' ).exec
fs = require 'fs'
should = require 'should'
yaml = require 'yaml'
Zombie = require 'zombie'
common = require '../../static/assets/js/common'
url = 'ahmeds.local'
browser = new Zombie()
config = null
consoleCb = 'function consoleSuccess(){console.log("success",arguments)}function consoleFailure(){console.log("failure",arguments)}'
browser.debug = true
browser.silent = false
fs.readFile '../../config.yaml', (error, data) ->
config = yaml.eval data.toString 'ascii'
exec 'cd ../../ && dev_appserver.py -a ' + url + ' .', ->
console.log arguments
# browser.visit config.local.url, ->
browser.visit 'http://' + url + ':8080', ->
browser.evaluate consoleCb
browser.evaluate 'profileImage("facebook",consoleSuccess,consoleFailure)'
console.log browser.window.console.output
I have only limited familiarity with NodeJS, but I just tested running a NodeJS server and App Engine local dev server on the same machine — it works just fine. Without seeing your NodeJS code, I'm guessing you're also trying to run NodeJS on port 8080, and so the App Engine server complains when it's started (8080 is the default, and you noted it's the port you are using).
Try passing --port=8081 (or some other port) to your invocation of dev_appserver.py and it should resolve the conflict.
Nothing in the code you've shown (other than the invocation of dev_appserver) should even be listening on any port (unless zombie implements a "server" for remote debugging or something like that). It looks like the port conflict is coming from somewhere else.
Note that zombie's own Mocha test framework does set up an express server, so if you're using it or code lifted from it, that might be doing it.
What does netstat have to say about who's binding to what port?

Resources