Giter Club home page Giter Club logo

Comments (18)

tomakehurst avatar tomakehurst commented on May 18, 2024 1

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.

maybeec avatar maybeec commented on May 18, 2024

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.

tomakehurst avatar tomakehurst commented on May 18, 2024

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.

maybeec avatar maybeec commented on May 18, 2024

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.

tomakehurst avatar tomakehurst commented on May 18, 2024

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.

tomakehurst avatar tomakehurst commented on May 18, 2024

Looks like the same exception as in this issue (for which excluding the other Servlet API solved the issue):
https://github.com/tomakehurst/wiremock/issues/37

from wiremock.

maybeec avatar maybeec commented on May 18, 2024

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.

tomakehurst avatar tomakehurst commented on May 18, 2024

Probably because you're running with log4j defaults. Try calling Log4jConfigurer.configure (true); in your @before

from wiremock.

maybeec avatar maybeec commented on May 18, 2024

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.

tomakehurst avatar tomakehurst commented on May 18, 2024

Ok, it looks like you've configured your stub for a GET only but are hitting it with a POST.

from wiremock.

tomakehurst avatar tomakehurst commented on May 18, 2024

Which version are you running?

from wiremock.

maybeec avatar maybeec commented on May 18, 2024

I am running v1.33 of WireMock. Where do I can configure the stub for POST requests?

from wiremock.

maybeec avatar maybeec commented on May 18, 2024

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.

JuliaIskra avatar JuliaIskra commented on May 18, 2024

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.

tomakehurst avatar tomakehurst commented on May 18, 2024

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.

JuliaIskra avatar JuliaIskra commented on May 18, 2024

No, this doesn't help.

I'm still getting ERROR 404

from wiremock.

JuliaIskra avatar JuliaIskra commented on May 18, 2024

Sorry, I was thoughtless :)
Found the bug - it's the same as @may-bee had - get instead post

Thank you!

from wiremock.

sensoryorgan avatar sensoryorgan commented on May 18, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.