I am trying to setup wiremock under an application path.
I have wiremock dockerized and running under some path https://local.wiremock/ and that works fine, so I can access the admin like this https://local.wiremock/__admin/docs
However when I deploy to aws it needs to be under a path like this:
https://aws-server.wiremock/simulator/__admin/docs
And the addition of the application path /simulator breaks everything.
So I want to set it up locally so that it runs under:
https://local.wiremock/simulator/__admin/docs
I have been going through documentation and there's nothing there for standalone server configuration.
There is a mappedUnder xml field that could be useful but it cannot be set via docker.
Any ideas how to achieve that?
I think you could do this by adding a Request Wrapper. The idea behind the Request Wrapper is that it intercepts the request and allows you to modify it before sending the request on. I think your solution would look something like...
public static class removeSimulatorPath extends StubRequestFilter {
#Override
public RequestFilterAction filter(Request request) {
Request wrappedRequest = RequestWrapper.create()
// lambda to replace the current URL with one without `/simulator`
.transformAbsoluteUrl(url -> url.replace("/simulator", "")
.wrap(request);
return RequestFilterAction.continueWith(wrappedRequest);
}
#Override
public String getName() {
return "remove-simulator-path";
}
}
Related
when I log into my app, I get a message
If you’re the app developer, make sure that these request details
comply with Google policies. redirect_uri:
http://XXXXXX/login/oauth2/code/google
I tried to add this to the Authorized redirect URIs in my google cloud
but I get an error
Invalid Redirect: You are using a sensitive scope. URI must use
https:// as the scheme
also if I add a url with
https://
then I still get a message when I log into the app
If you’re the app developer, make sure that these request details
comply with Google policies. redirect_uri:
http://XXXXXXX/login/oauth2/code/google
my technology stack:
java
spring
vaadin
properties file:
server.port=${PORT:8080}
spring.security.oauth2.client.registration.google.client-id=xxxxxx.apps.googleusercontent.com
spring.security.oauth2.client.registration.google.client-secret=xxxxxx
spring.security.oauth2.client.registration.google.scope=openid,email,profile,\
https://www.googleapis.com/auth/spreadsheets,\
https://www.googleapis.com/auth/spreadsheets.readonly,\
https://www.googleapis.com/auth/drive.file,\
https://www.googleapis.com/auth/drive,\
https://www.googleapis.com/auth/script.scriptapp
spring.security.oauth2.client.provider.google.token-uri=https://oauth2.googleapis.com/token
spring.security.oauth2.client.provider.google.authorization-uri=https://accounts.google.com/o/oauth2/auth?prompt=consent&access_type=offline
spring.security.oauth2.client.provider.google.user-info-uri=https://www.googleapis.com/oauth2/v3/userinfo
the code that gets Credential:
public void initCredential(OAuth2AuthorizedClientService authorizedClientService, Authentication authentication ) {
OAuth2AuthorizedClient authorizedClient = authorizedClientService.loadAuthorizedClient(
"google",
authentication.getName());
credential = new GoogleCredential.Builder()
.setClientSecrets(CLIENT_ID,CLIENT_SECRET)
.setJsonFactory(GsonFactory.getDefaultInstance())
.setTransport(GoogleNetHttpTransport.newTrustedTransport())
.build()
.setAccessToken(authorizedClient.getAccessToken().getTokenValue())
.setRefreshToken(authorizedClient.getRefreshToken().getTokenValue());
}
also Oauth2 configuration:
#EnableWebSecurity
#Configuration
public class WebSecurityConfig extends VaadinWebSecurityConfigurerAdapter {
private static final String LOGIN_URL = "/login";
#Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.oauth2Login()
.loginPage(LOGIN_URL).permitAll();
}
#Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
web.ignoring().antMatchers(
"/VAADIN/**",
"/favicon.ico",
"/robots.txt",
"/manifest.webmanifest",
"/sw.js",
"/offline-page.html",
"/frontend/**",
"/webjars/**",
"/frontend-es5/**", "/frontend-es6/**")
.antMatchers(HttpMethod.POST, "/notifications");
}
}
as I understand it, I need to configure the use of the https protocol in the configuration, but I don't understand a little where I can configure it
it is also worth noting that the application works locally, but when deploying it to AWS and trying to login via oauth 2, I get the message
As stated in the message You are using a sensitive scope. URI must use https:// as the scheme
Just configuring it in Google cloud console has no effect on how your application runs. It just says that this redirect uri will be supported.
Your app when it is run is still running with http and not as https. I am going to assume that you are still in development and running this locally and you have not configured our app yet to run https.
Fix your ide.
I am working on an application that uses rest webservices where a uri has been invoked from a .js file.
var invokeWS = "/resource/domain/program/tasks";
jQuery.getJSON(invokeWS ,data)
While looking at all the jar's I found out that the class corresponding to program is present in a package "com.company.project.webapps.util.rest.service" as below
package com.company.project.webapps.util.rest.service;
#Path("/program")
public class Program extends RS
{
#Path("/tasks")
#GET
public get...()
{
}
}
I do not see any mapping url in web.xml but the the webservice call made through .js would some how pick the correct path and invokes the service.
Can you please let me know if this can be achieved in a any other way as I do not see any entries in web.xml of the applicaiton.
Thanks
Awanish
In a standalone (selfhosted) application, I would like to have an httpserver that on a single base adress can either serve simple web pages (without any serverside dynamics/scripting, it just returns the content request files) or serve RESTful webservices:
when http://localhost:8070/{filePath} is requested, it should return the content of the file (html, javascript, css, images), just like a normal simple webserver
everything behind http://localhost:8070/api/ should just act as a normal RRESTful Web API
My current approach uses ASP.NET Web API to server both the html pages and the REST APIs:
var config = new HttpSelfHostConfiguration("http://localhost:8070/");
config.Formatters.Add(new WebFormatter());
config.Routes.MapHttpRoute(
name: "Default Web",
routeTemplate: "{fileName}",
defaults: new { controller = "web", fileName = RouteParameter.Optional });
config.Routes.MapHttpRoute(
name: "Default API",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional });
The WebController is the controller that serves the web pages with this naive code:
public class WebController : ApiController
{
public HttpResponseMessage Get(string fileName = null)
{
/// ...
var filePath = Path.Combine(wwwRoot, fileName);
if (File.Exists(filePath))
{
if (HasCssExtension(filePath))
{
return this.Request.CreateResponse(
HttpStatusCode.OK,
GetFileContent(filePath),
"text/css");
}
if (HasJavaScriptExtension(filePath))
{
return this.Request.CreateResponse(
HttpStatusCode.OK,
GetFileContent(filePath),
"application/javascript");
}
return this.Request.CreateResponse(
HttpStatusCode.OK,
GetFileContent(filePath),
"text/html");
}
return this.Request.CreateResponse(
HttpStatusCode.NotFound,
this.GetFileContnet(Path.Combine(wwwRoot, "404.html")),
"text/html");
}
}
And again, for everything behind /api, controllers for normal REST APIs are used.
My question now is: Am I on the right track? I kind of feel that I am rebuilding a webserver here, reinventing the wheel. And I guess that there are probably a lot of http request web browsers could make that I do not handle correctly here.
But what other option do I have if I want to self host and at the same time server REST web APIs and web pages over the same base address?
Looks like you are trying to recreate asp.net FileHandler for self host. There is a better solution though. Using Katana(an OWIN host) as the hosting layer for web API. OWIN supports hosting multiple OWIN frameworks in the same app. In your case, you can host both web API and a file handler in the same OWIN app.
Filip has a good blog post on this to get you started here. You can use configuration code like this,
public void Configuration(IAppBuilder appBuilder)
{
// configure your web api.
var config = new HttpConfiguration();
config.Routes.MapHttpRoute("default-api", "api/{controller}");
appBuilder.UseWebApi(config);
// configure your static file handler.
appBuilder.UseStaticFiles();
}
IMO there is nothing wrong with what you are doing. I use self-host for delivering files, html docs as well as being a regular API. At the core, self-host is using HTTP.SYS just as IIS is.
As RaghuRam mentioned there are Owin hosts that have some optimizations for serving static files, but WCF selfhost is quite capable of getting decent perf for serving files.
See this link which uses a more straigftforward approach
Setting app a separate Web API project and ASP.NET app
RouteTable.Routes.IgnoreRoute(".js");
RouteTable.Routes.IgnoreRoute(".html");
I have an app written using MonoTouch that relies on a Web Services URL backend. I need the ability to set the URL of this backend dynamically at run time from within the app (or from within it's settings).
I've read this article on CodeProject that describes setting URL dynamically:
http://www.codeproject.com/Articles/12317/How-to-make-your-Web-Reference-proxy-URL-dynamic#_rating
But I can't find this option in MonoDevelop.
I've tried altering the Url property of my service, but it appears there is more to it than that. (Specifically the "references.cs" file added by the web service seems to also have the URL hard coded in various attributes).
Any help much appreciated.
Thanks!
--scotru
When Mono generates C# wrapper for SOAP web-service to you, it creates 2 constructors of wrapper. Second one contains URL parameter, which you can use to set proper URL and so switch between web-services.
Example from project, which is in production (file Reference.cs):
public partial class ServicesInfoImplService : System.Web.Services.Protocols.SoapHttpClientProtocol
...
public ServicesInfoImplService() {
this.Url = "<DEFAULT_URL>";
}
public ServicesInfoImplService(string url) {
this.Url = url;
}
...
For example, I write a simple code, pack it as *.jar and deploy WebService in JBoss, evrything works..
#WebService
#Stateless
public class TestService{
static int takeMePlz = 1;
#WebMethod
public String GetAnsw(String str){
++takeMePlz;
return Integer.toString(takeMePlz);
}
}
So, when i call this web service, takeMePlz static varible increases.
My Serivce has location http://localhost:8080/test_service/TestService,
Now i Want JSP with location: http://localhost:8080/test_service/Administrating,
that has access to my web service, and this JSP should show me takeMePlz static varible in web browser
Create client for webservice
invoke webservice from servlet
catch the result as attribute of request and forward it to jsp and on jsp use JSTL to show the data
In addition, you need to make the takeMePlz field public so it is accessible.
Moreover, you should synchronize access to the field, or make it a java.util.concurrent.atomic.AtomicInteger.
It will still be a bit rough though. Once you have it working, you might want to consider reimplementing using JMX.