Comments (18)
I'm lacking access to a computer at the moment so I can't test this but it could be because your stub definition has a trailing slash but your http post doesn't
BTW, your @before block is unnecessary as reset() is called by the rule.
from wiremock.
I've added the trailing slash to the HttpPost
HttpPost httpPost = new HttpPost("http://localhost:9999/");
Unfortunately this does not solve the problem.
from wiremock.
If you add a log4j notifier to the options passed to the rule and set it to verbose it'll log out why it didn't match at INFO.
from wiremock.
After adding the log4j Notifier as follows
@Rule
public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().port(testPort).notifier(
new Log4jNotifier()));
I got no more information, but several NullPointerExceptions :) Perhaps a bug?
[D: 2013-07-04 10:50:26,883] [P: INFO ] [T: 15087110@qtp-26116262-0] [L: /__admin] - [M: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler]
[D: 2013-07-04 10:50:27,367] [P: INFO ] [T: 31003492@qtp-26116262-2] [L: /] - [M: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler]
[D: 2013-07-04 10:50:27,508] [P: ERROR] [T: main] [L: org.mortbay.log] - [M: EXCEPTION ]
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
at javax.servlet.GenericServlet.log(GenericServlet.java:300)
at javax.servlet.GenericServlet.destroy(GenericServlet.java:122)
at org.mortbay.jetty.servlet.ServletHolder.destroyInstance(ServletHolder.java:318)
at org.mortbay.jetty.servlet.ServletHolder.doStop(ServletHolder.java:289)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.servlet.ServletHandler.doStop(ServletHandler.java:185)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
at org.mortbay.jetty.handler.ContextHandler.doStop(ContextHandler.java:592)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerCollection.doStop(HandlerCollection.java:169)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
at org.mortbay.jetty.Server.doStop(Server.java:283)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at com.github.tomakehurst.wiremock.WireMockServer.stop(WireMockServer.java:148)
at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:66)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
[D: 2013-07-04 10:50:27,508] [P: ERROR] [T: main] [L: org.mortbay.log] - [M: EXCEPTION ]
java.lang.NullPointerException
at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:205)
at javax.servlet.GenericServlet.log(GenericServlet.java:300)
at javax.servlet.GenericServlet.destroy(GenericServlet.java:122)
at org.mortbay.jetty.servlet.ServletHolder.destroyInstance(ServletHolder.java:318)
at org.mortbay.jetty.servlet.ServletHolder.doStop(ServletHolder.java:289)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.servlet.ServletHandler.doStop(ServletHandler.java:185)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
at org.mortbay.jetty.handler.ContextHandler.doStop(ContextHandler.java:592)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerCollection.doStop(HandlerCollection.java:169)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at org.mortbay.jetty.handler.HandlerWrapper.doStop(HandlerWrapper.java:142)
at org.mortbay.jetty.Server.doStop(Server.java:283)
at org.mortbay.component.AbstractLifeCycle.stop(AbstractLifeCycle.java:76)
at com.github.tomakehurst.wiremock.WireMockServer.stop(WireMockServer.java:148)
at com.github.tomakehurst.wiremock.junit.WireMockRule$1.evaluate(WireMockRule.java:66)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
from wiremock.
I think that exception is probably because you've got an additional, different version of the servlet API on your classpath. If you try excluding this (temporarily at least) so that only the Servlet API version pulled in via WireMock is present, this should go away.
from wiremock.
Looks like the same exception as in this issue (for which excluding the other Servlet API solved the issue):
#37
from wiremock.
Ok. the servlet issue solved the problem for debugging.
Now I get
[D: 2013-07-04 14:28:08,772] [P: INFO ] [T: 26116262@qtp-32879825-0] [L: /__admin] - [M: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler]
[D: 2013-07-04 14:28:09,232] [P: INFO ] [T: 17621911@qtp-32879825-2] [L: /] - [M: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler]
thats all.... no additional information.
Remember, "verify" verifies the request done by the tested code snippet as follows
verify(postRequestedFor(urlEqualTo("/"))
.withHeader("Content-Type", equalTo("text/xml; charset=UTF-8"))
.withHeader("SOAPAction", equalTo("")).withRequestBody(equalTo(request)));
from wiremock.
Probably because you're running with log4j defaults. Try calling Log4jConfigurer.configure (true); in your @before
from wiremock.
I do not use the default log4j properties, but I saw there is a restriction for com.* packages set to WARN :) So I changed this and get the following:
[D: 2013-07-04 14:49:28,252] [P: WARN ] [T: main] [L: org.dozer.config.GlobalSettings] - [M: Dozer configuration file not found: dozer.properties. Using defaults for all Dozer global properties.]
[D: 2013-07-04 14:49:29,003] [P: INFO ] [T: 15087110@qtp-26116262-0] [L: /__admin] - [M: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.AdminRequestHandler]
[D: 2013-07-04 14:49:29,013] [P: INFO ] [T: 15087110@qtp-26116262-0] [L: com.github.tomakehurst.wiremock.common.Log4jNotifier] - [M: Received request to /mappings/new with body {
"request" : {
"url" : "/",
"method" : "GET"
},
"response" : {
"status" : 200,
"base64Body" : "QW55IFJlc3BvbnNlIDA="
}
}]
[D: 2013-07-04 14:49:29,433] [P: INFO ] [T: 31003492@qtp-26116262-2] [L: /] - [M: RequestHandlerClass from context returned com.github.tomakehurst.wiremock.http.StubRequestHandler]
[D: 2013-07-04 14:49:29,433] [P: INFO ] [T: 31003492@qtp-26116262-2] [L: com.github.tomakehurst.wiremock.common.Log4jNotifier] - [M: Received request to /]
[D: 2013-07-04 14:49:29,433] [P: INFO ] [T: 31003492@qtp-26116262-2] [L: com.github.tomakehurst.wiremock.common.Log4jNotifier] - [M: URL / is match, but method POST is not]
[D: 2013-07-04 14:49:29,433] [P: INFO ] [T: 31003492@qtp-26116262-2] [L: com.github.tomakehurst.wiremock.common.Log4jNotifier] - [M: No mapping found matching URL /]
[D: 2013-07-04 14:49:29,504] [P: INFO ] [T: 15087110@qtp-26116262-0] [L: com.github.tomakehurst.wiremock.common.Log4jNotifier] - [M: Received request to /requests/count with body {
"url" : "/",
"method" : "POST",
"bodyPatterns" : [ {
"equalTo" : "Any Request 0"
} ],
"headers" : {
"Content-Type" : {
"equalTo" : "text/xml; charset=UTF-8"
},
"SOAPAction" : {
"equalTo" : ""
}
}
}]
from wiremock.
Ok, it looks like you've configured your stub for a GET only but are hitting it with a POST.
from wiremock.
Which version are you running?
from wiremock.
I am running v1.33 of WireMock. Where do I can configure the stub for POST requests?
from wiremock.
Wow, some hours of sleep make the job :)
It is the post before the url matcher which does this job...
post(urlEqualTo("/")
As the term 'get', which is used in each example in the documentation, is some kind of overloaded in this case, in my opinion, the documentation should be a little bit clearer here :)
Nevertheless, thanks for you quick and helpful feedback and also thanks for WireMock! I love it! 👍
from wiremock.
Hello, @tomakehurst !
Looks like I have the same problem - conflicted Http Client dependency.
As I understand from documentation this:
<classifier>standalone</classifier>
should solve the problem, but it is not.
How can I fix it?
from wiremock.
Yes, the docs aren't great in this regard.
The POM with the standalone version still (currently) pulls in the transitive dependencies, so you need to explicitly exclude the ones that are causing you problems e.g.
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
from wiremock.
No, this doesn't help.
I'm still getting ERROR 404
from wiremock.
Sorry, I was thoughtless :)
Found the bug - it's the same as @may-bee had - get
instead post
Thank you!
from wiremock.
@tomakehurst Is it possible to exclude certain query parameter while running wiremock standalone?
tobe more precise while invoking an url e.g. http:\search.twitter.com?userid=1236524&name=stella&date=....
Can I do it in a way so that for all the urls invoked "userid" would not be considered while recording the response. So that if userid changes and rest of the url remains same, wiremock wont record the response again.
from wiremock.
Related Issues (20)
- Update org.xmlutil:xmlunit-core to Version 2.10.0 HOT 2
- Introduce a GUI for open source HOT 1
- NPE on WireMockServer.getServeEvents when using a StubRequestFilter HOT 1
- Adding more jettyAcceptors seems to do nothing besides cause thread contention. HOT 1
- align new join handlebar helper with features present in the join provided in the library, but not covered yet
- Expose args in Options so extensions can read it
- Possible memory leak ? HOT 15
- Prevent creating multiple stub mappings with the same ID HOT 1
- Support virtual threads in Jetty server for standalone deploy
- Error when proxying to a host that is only accessible via IPv6 HOT 1
- Formatted dates not in UTC
- __files created by default since v3.6.0 HOT 1
- absent operand must be a non-null string
- Array and data manipulation in handlebars template when using docker
- FileItemPartAdapter returning multipart's field name instead of a filename
- Avoiding reading zipfile entries repeatedly in ClasspathFileSource
- Support disabled state for stub mappings HOT 1
- Add a unique id to the template request model
- Add self-description callback(s) to MatchResult for use in Diff
- Report webhook errors and results as sub-events
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wiremock.