Giter VIP home page Giter VIP logo

jcabi-http's Introduction

logo

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

mvn PDD status Maven Central Hits-of-Code License

This project is just a parent POM for all other Java projects in "jcabi family".

See www.jcabi.com website for more details.

jcabi-http's People

Contributors

amihaiemil avatar andreoss avatar antonini avatar ayushwalekar avatar carlosmiranda avatar dependabot-preview[bot] avatar dependabot[bot] avatar idegtiarenko avatar ivanov-d avatar jakob-o avatar janenicholson avatar longtimeago avatar maurezen avatar methodlevelanalyzer avatar pinaf avatar piotrkot avatar pstorch avatar renovate[bot] avatar romankisilenko avatar rultor avatar simonjenga avatar valery1707 avatar yegor256 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jcabi-http's Issues

MkContainer.java:64-66: Let's introduce a utility class...

Puzzle 19-aa7a7497 in src/main/java/com/jcabi/http/mock/MkContainer.java:64-66 has to be resolved: Let's introduce a utility class MkQueryMatchers which contains convenience methods for matching MkQuery objects. This is primarily intended for use with the conditional MkContainer.next() methods. For example:

Missing Lombok dependency

Thanks for this very useful library - I was getting version conflicts with anything that uses ApacheHttp, and this gave me a very quick solution.

There does seem to be a dependency missing from your "optional dependencies" page, for the the Lombok annotations.

In Gradle speak:

compile 'org.projectlombok:lombok:1.14.8'

I'm currently using:

compile 'com.jcabi:jcabi-http:1.10.1'
compile 'javax.json:javax.json-api:1.0'
compile 'org.glassfish:javax.json:1.0.4'

JsonResponse should be able to read non-Unicode JSON

JsonResponse is now relying on a proper Unicode formatting of JSON documents (see line 95). When JSON contains non-Unicode characters, the class throws a runtime exception. For example, try this document (which is a valid JSON according to RFC 4627):

{"test": "\u0000"}

Add RestResponse.assertBinary() method

At the moment, we have a method RestResponse.assertBody(Matcher<String>), which checks if the response body String corresponds to the given matcher.

Let's add an equivalent assertBinary() method for checking binary content. After all, we have methods to obtain the response in either format (Response.body() and Response.binary() respectively); it would be great if we were able to have convenience methods for verifying the body content in binary as well.

enable conditional answers in MkContainer

Let's introduce a new utility class MkQueryMatchers, in order to enable conditional answers in MkContainer, for example:

MkContainer container = new MkGrizzlyContainer();
  .next(
    new MkAnswer.Simple("hello, world!"),
    Matchers.allOf(
      MkQueryMatchers.hasHeader(
        "Content-Type",
        Matchers.equalTo("text/plain")
      ),
      MkQueryMatchers.hasBody(
        Matchers.containsString("say hello")
      )
    )
  )
  .start();

This means that the answer will be returned only if the request contains header Content-Type, which is equals to "text/plain" and request body contains "say hello".

By default, when method next(MkAnswer) is used (with one argument only), an everything-matching instance of Matcher<MkQuery> is used.

Besides that, let's add methods take(Matcher<MkAnswer>) and takeAll(Matcher<MkAnswer>), and an utility class MkAnswerMatchers:

MatcherAssert.assertThat(
  container.takeAll(
    MkAnswerMatchers.hasHeader(
      "Content-Type",
      Matchers.equalTo("application/json")
    )
  ),
  Matchers.allOf(
    Matchers.hasSize(5),
    Matchers.hasItem(
      Matchers.allOf(
        MkQueryMatchers.hasHeader("User-Agent"),
        MkQueryMatchers.hasBody(
          Matchers.containsString("say hello")
        )
      )
    )
  )
);

This means that we're taking all requests received by the container, which were answered with responses that had a header "content-type" with a value "application/json". We're asserting that there were 5 those answers. And all of them had body "say hello" and a header "User-Agent".

FakeRequest incorrectly uses request body as response body

When the RequestBody of a FakeRequest is set, it incorrectly uses it in the body of the ResponseBody instead of using the response body content that was specified.

For example, the following test will fail:

@Test
public void fakeRequestReturnsRequestBody() throws Exception {
    MatcherAssert.assertThat(
        new FakeRequest()
            .withBody("foo")  // Response body - should be returned
            .body().set("bar").back() // Request body
            .fetch().body(),
        Matchers.is("foo")
    );
}

Error:

java.lang.AssertionError: 
Expected: is "foo"
     but: was "bar"

Note that the following test - if the RequestBody is not set - works fine:

@Test
public void fakeRequestReturnsRequestBody() throws Exception {
    MatcherAssert.assertThat(
        new FakeRequest()
            .withBody("foo")
            .fetch().body(),
        Matchers.is("foo")
    );
}

Javadoc links on Maven Site are broken

For example, in http://http.jcabi.com/example-request.html, the first link to Request refers to http://http.jcabi.com/apidocs-1.5.2/com/rexsl/test/Request.html. This will result in a HTTP 404 error, since we've migrated the classes from com.rexsl.test to com.jcabi.http. The link http://http.jcabi.com/apidocs-1.5.2/com/jcabi/http/Request.html works properly as expected.

Let's update the links on this page, and all our other pages, to suit the new package structure.

jcabi-matchers

Let's use jcabi-matchers 1.0 instead of rexsl-test 0.13

Build fails under Windows 7

mvn clean install -Pqulice fails with following message:

[INFO] No Checkstyle violations found in 84 files
[INFO] No PMD violations found in 71 files
[INFO] \src\changes\changes.xml: to be validated
[INFO] jcabi-aspects 0.17.1/8b0e260 started new daemon thread jcabi-loggable for
 watching of @Loggable annotated methods
[ERROR] JSR-303 validator failed to initialize: Unable to create a Configuration
, because no Bean Validation provider could be found. Add a provider like Hibern
ate Validator (RI) to your classpath. (see http://www.jcabi.com/jcabi-aspects/js
r-303.html)
[INFO] \src\site\site.xml: to be validated
[INFO] CodeNarc not required since no groovy files in d:\dev\teamed.io\jcabi-htt
p\src
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 06:40 min
[INFO] Finished at: 2015-01-25T22:54:57+04:00
[INFO] Final Memory: 37M/154M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.qulice:qulice-maven-plugin:0.10:check (jcabi-
check) on project jcabi-http: Execution jcabi-check of goal com.qulice:qulice-ma
ven-plugin:0.10:check failed: Non-zero exit code 1: -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutio
nException

AutoRedirectingWire

Let's add a new class AutoRedirectingWire. It should retry a request when HTTP response code is between 300 and 399. It has to have two constructors: no-args and one-arg. The argument is the maximum number of retries. By default (with no-arg ctor) the maximum is 5.

mvm clean verify fails

During test compilation, maven build fails with errors like

[ERROR] /Users/roman/Desktop/project/teamio/jcabi-http/src/test/java/com/jcabi/http/wire/CookieOptimizingWireTest.java:[84,25] <U>everyItem(org.hamcrest.Matcher<U>) in org.hamcrest.Matchers cannot be applied to <java.lang.String>(org.hamcrest.Matcher<java.lang.Object>)

Optional dependencies are not documented

The documentation claims that the only dependency required is jcabi-http itself, but that seems to be true only for a very limited used. In my project I ended up needing the following in my POM:

    <dependency>
        <groupId>com.jcabi</groupId>
        <artifactId>jcabi-http</artifactId>
        <version>1.5.2</version>
    </dependency>
    <dependency>
        <groupId>org.glassfish</groupId>
        <artifactId>javax.json</artifactId>
        <version>1.0.4</version>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
    </dependency>

I think these requirements should be at least documented -- I had to find them in your POM to identify the group and artifact IDs I wanted to add. And from what I can tell there are other cases where more dependencies are required.

maven dependency error for 2.0-SNAPSHOT

I am using the below dependency and putting it in pom of a simple maven web project created using archetype-generate

<dependency>
      <groupId>com.jcabi</groupId>
      <artifactId>jcabi-http</artifactId>
      <version>2.0-SNAPSHOT</version>
    </dependency>

<repositories>
      <repository>
        <id>oss.sonatype.org</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
      </repository>
    </repositories> 

Then I have a class with the below code

public static void main(String[] args) throws IOException {
        JdkRequest jdkRequest = new JdkRequest("https://www.google.com");
        System.out.println(jdkRequest);
        String html;

        html = new JdkRequest("https://www.google.com")
          .uri().path("/users").queryParam("id", 333).back()
          .method(Request.GET)
          .header("Accept", "text/html")
          .fetch()
          .as(RestResponse.class)
          .assertStatus(HttpURLConnection.HTTP_OK)
          .body();

        System.out.println(html);
    }

It blows up on the very first line with error

Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/core/UriBuilder
    at com.jcabi.http.request.BaseRequest.<init>(BaseRequest.java:148)
    at com.jcabi.http.request.BaseRequest.<init>(BaseRequest.java:126)
    at com.jcabi.http.request.JdkRequest.<init>(JdkRequest.java:231)
    at com.shashank.testJcabi.TestJcabiRequest.main(TestJcabiRequest.java:14)
Caused by: java.lang.ClassNotFoundException: javax.ws.rs.core.UriBuilder
    at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 4 more

Please suggest.

Thanks in advance !
Shashank

Documentation missing as to what optional dependencies are required for which feature

The page http://http.jcabi.com/optional-dependencies.html provides a full list of dependencies one can use, but this can exceed the required set for a particular use case. For example: org.jsoup:jsoup is required only if the JSoup parser is used. Adding the dependency is not needed for other use cases and unnecessarily bloats the resulting artifacts.

The ideal solution for me would be to actually have one dependency per feature, i.e. have something like com.jcabi:jcabi-http-jsoup to depend on if I want the JSoup feature. That would also avoid having to update version numbers outside of POMs (as on the page linked above).

CachingWire.get() should have private visibility

Currently, CachingWire.get() has public visibility. I don't see why it shouldn't be private instead, since the Wire API is actually obtaining the Response through Wire.send(), and CachingWire.send() delegates to get() for its caching behavior.

get rid of commons-io

Let's get rid of commons-io. It's a small library, and would be much better to work without big dependencies

How to generate javadocs?

Working on #32, I build the site using "site" maven goal to check my corrections in *.md.vm files. This way I get HTMLs for the site in target/site folder. The HTMLs contain links to javadocs, like:

./apidocs-${project.version}/com/jcabi/http/response/XmlResponse.html

These links are not valid, because there are no javadocs in ./apidocs-${project.version} folder.

How should I generate the javadocs? I tried all other maven goals, none of them made javadocs.

Maybe we need such maven goal?

Uploads should allow using streams

The current API does not seem to have any efficient way of uploading the contents of a file or other local resource.

There is RequestBody#set(byte[]), but that requires loading the full file contents into memory. The array is then cloned in the BaseBody(BaseRequest, byte[]) constructor, doubling the memory need.

While this is currently feasible for what we do, we would prefer having something like RequestBody#set(InputStream), allowing us to stream the contents of a resource directly to a HTTP server.

README contains outdated usage

    String html = new JdkRequest("https://www.google.com")
      .uri().path("/users").queryParam("id", 333).back()
      .method(Request.GET)
      .header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML)
      .fetch()
      .as(HttpResponse.class)
      .assertStatus(HttpURLConnection.HTTP_OK)
      .body();
  }

But there is no HttpResponse class anymore.
There should be RestResponse

TrustedWire

Let's create TrustedWire which will ignore SSL keys

ConnectionException is not descriptive

I'm getting this exception sometimes:

Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at java.net.Socket.connect(Socket.java:528)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
    at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
    at sun.net.www.http.HttpClient.New(HttpClient.java:308)
    at sun.net.www.http.HttpClient.New(HttpClient.java:326)
    at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:996)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:932)
    at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:850)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1300)
    at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
    at com.jcabi.http.request.JdkRequest$1.send(JdkRequest.java:117)
    at com.jcabi.http.wire.BasicAuthWire.send(BasicAuthWire.java:138)
    at com.jcabi.http.request.BaseRequest.fetch_aroundBody10(BaseRequest.java:197)
    at com.jcabi.http.request.BaseRequest$AjcClosure11.run(BaseRequest.java:1)

"Connection refused" is not descriptive at all to me. I'd like to see where the connection was trying to be established to, with what HTTP method, etc. Would be nice to wrap all runtime exceptions flying out of JdkRequest$1.send() in IOException and add a message there, like:

failed to POST to http://example.com

Qulice configuration - no license specified.

  1. Checkout master branch
  2. run mvn qulice:check -Pqulice
  3. There are multiple Line does not match expected header line of ' * BSD License'. (HeaderCheck) messages.

This is a known bug of qulice configuration in parent-0.31 (jcabi/jcabi-parent#19), accessed via jcabi-0.16. Suggested action is waiting until jcabi/jcabi#297 fix is released and upgrading jcabi version.

Dependency issue

First of all, great job! This is something i was searching for long time.
Just one question. I have a problem with missing dependency. At the moment when I execute queryParam i have:

java.lang.NoClassDefFoundError: javax/ws/rs/core/UriBuilder

Do i need anything else beside compile('com.jcabi:jcabi-http:1.9.1') ?

My code:

String body = new JdkRequest(tagsPopularityUrl)
.uri().queryParam('timestamp', (new Date() - dateOffset).time).back()
.method(Request.GET)
.fetch().body()

JsoupResponseTest.java:50-53: Saxon complains about HTML 1.0,...

Puzzle 1-5ecf8bb2 in src/test/java/com/jcabi/http/response/JsoupResponseTest.java:50-53 has to be resolved: Saxon complains about HTML 1.0, and I'm not sure how this is possible to fix. All we need to check in this test is that the output is a clean HTML document. Aparently JSOUP produces a broken HTML? Let's investigate and fix.

escaping of JSON breaks normal parsing

after #1 we have a broken logic. normally formatted JSON can't be parsed, for example:

{
  "test": "hello"
}

Leads to runtime exception:

javax.json.stream.JsonParsingException: Unexpected char 92 at (line no=1, column no=21, offset=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.