Giter Site home page Giter Site logo

expath-http-client-java's Introduction

Build Status Java 8+ License Maven Central

Java implementation of EXPath HTTP Client Module

This is a Java implementation of the EXPath HTTP Client Module specification.

We provide a Java library that may be used as the basis for specific product implementations, and an RI (Reference Implementation) developed for Saxon which demonstrates how to use the library.

Building from source

Requires:

  • Java 1.8 or newer
  • Maven 3 or newer
$ git clone https://github.com/expath/expath-http-client-java.git
$ cd expath-http-client-java
$ mvn clean package

NOTE: Where .sh files are specified below, the equivalent .bat files also exist for Microsoft Windows users.

Using the Saxon RI

Compatibility with Saxon Versions

http-client-saxon Version Saxon Versions
1.5.0+ 12.0+
1.4.0+ 10.3+
1.3.0 9.9+
<= 1.2.4 9.7+

Additional Saxon specific examples can be found in http-client-saxon/README.md.

To use the RI for Saxon, you require several Jar files to be present on the classpath with Saxon: http-client-saxon-VERSION.jar, http-client-java-VERSION.jar, and the dependencies of http-client-java; to make this easier we provide an Uber Jar, whereby you can just place http-client-saxon-VERSION-uber.jar onto Saxon's classpath. If you have built from source these can be found in the respective folders: http-client-saxon/target/, and http-client-java/target/, alternatively you may download the releases from Maven Central.

Saxon also needs to have the EXPath HTTP Client Module's functions registered with it. Depending on how you are using Saxon, will depend on how this is done.

If you are using Saxon's classic API from Java, you can do something like:

import org.expath.httpclient.saxon.SendRequestFunction;

...

Configuration configuration = new Configuration();
configuration.registerExtensionFunction(new SendRequestFunction());

...

If you are using Saxon from the command line, you may specify a Saxon configuration file, to which you need to add an <extensionFunction> to the <resources> section, for example:

<configuration xmlns="http://saxon.sf.net/ns/configuration"
               edition="EE"
               licenseFileLocation="saxon-license.lic"
               label="Some label">

...

  <resources>
    <extensionFunction>org.expath.httpclient.saxon.SendRequestFunction</extensionFunction>

    ...

More information if needed about extension functions for Saxon can be found here.

expath-http-client-java's People

Contributors

adamretter avatar dependabot-preview[bot] avatar dependabot[bot] avatar fgeorges avatar thms-rmb avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

wsalesky thms-rmb

expath-http-client-java's Issues

conflicting header on multipart request

When a multipart request includes the following header element

<http:header name="Content-Type" value="multipart/form-data"/>

in addition to the required element

<http:multipart media-type="multipart/form-data" boundary="some-boundary-string-">

The multipart request is broken (boundaries are not properly set) but does not report an error.

The error may be helpfully identified via implementation of error codes in #22.

Howto use this from Saxon (or from within oXygen XML)

Hi,
I need to POST a request from a XSLT script, so it seems this is the library I need. I now spend a few days looking for information on the Web, but most of it seems to be outdated and does not work. A concise explanation on how to install this library for use with Saxon, or within oXygen would be highly appreciated!

disable chunked encoding

Using the client in eXist-db we encountered the issue that Transfer-Encoding: chunked is set automatically. When dealing with an REST service that is not able to parse chunked encoding (corpus delicti: python hug) we solved the issue by setting HTTP version to 1.0 by using an the undocumented attribute http-version within the request element. This solution is clearly a work around.

  • Is there a way to disable the usage of chunked encoding?
  • Why is this attribute not part of the documentation? Is it subject to be removed later on?

In addition it might be useful to get an overview of the rules to set the Transfer-Encoding header.

oXygen with Saxon EE 12.3 Results In Null Processor Exception

  • oXygen version: XML Editor 26.1, build 2024042206
  • Saxon version: 12.3 EE
  • EXPath HTTP Client version: 1.5.0

When running sample code from within oXygen to exercise the library (http-client-saxon-1.5.0-uber.jar) as directed in GitHub, I am getting the following error:

-- Cannot invoke "net.sf.saxon.s9api.Processor.newDocumentBuilder()" because "processor" is null. --

Oxygen run-time log captured and attached, as well as the XSL used in the test.

oxygen_run_log.txt
sample_xsl.txt

(XSL attached as txt since GitHub not supporting attachment of XSL files.)

Saxon config and uber-jar inclusion on classpath are correct as per GitHub directions for the client.

error handling

The project states that this is a Java implementation of the EXPath HTTP Client Module specification but it does not handle Errors according to the specification.

Feature Request

Implement Error Classes:

err:HC001
    An HTTP error occurred.
err:HC002
    Error parsing the entity content as XML or HTML.
err:HC003
    With a multipart response, the override-media-type must be either a multipart media type or application/octet-stream.
err:HC004
    The src attribute on the body element is mutually exclusive with all other attribute (except the media-type).
err:HC005
    The request element is not valid.
err:HC006
    A timeout occurred waiting for the response.

HTTP Client module namespace prefix doesn't match spec

The hc module namespace prefix is hardcoded in the EXPath HTTP Client implementation. However, the spec makes no mention of an hc prefix. The spec clearly defines the namespace prefix as http:

The module defined by this document does define one function in the namespace http://expath.org/ns/http-client. In this document, the http prefix, when used, is bound to this namespace URI.

This mismatch between the spec and the implementation leads to confusion. For example, eXist ships with http-client and thus should be available without an explicit module import, but invoking the http:send-request function triggers the following error:

Invalid qname http:send-request. No namespace defined for prefix http. QName is invalid: INVALID_PREFIX

This error is only triggered because the namespace prefix bound to the module is hc instead of http.

Thus, the implementation should be changed so that the hardcoded namespace prefix conforms with the spec: it should be http.

Saxon-HE 10: NoSuchMethodError: net.sf.saxon.om.NodeInfo.iterateAxis(byte)

I'm trying to use this with Saxon-HE 10.3, but I am getting a NoSuchMethodError exception:

Exception in thread "main" java.lang.NoSuchMethodError: 'net.sf.saxon.tree.iter.AxisIterator net.sf.saxon.om.NodeInfo.iterateAxis(byte)'
	at org.expath.tools.saxon.model.SaxonElement.attributes(SaxonElement.java:95)
	at org.expath.httpclient.impl.RequestParser.parse(RequestParser.java:89)
	at org.expath.httpclient.HttpClient.doSendRequest(HttpClient.java:96)
	at org.expath.httpclient.HttpClient.sendRequest(HttpClient.java:89)
	at org.expath.httpclient.saxon.SendRequestCall.call(SendRequestCall.java:65)
	at net.sf.saxon.functions.IntegratedFunctionCall.iterate(IntegratedFunctionCall.java:293)
	at net.sf.saxon.expr.parser.Evaluator$11.evaluate(Evaluator.java:290)
	at net.sf.saxon.expr.LetExpression.eval(LetExpression.java:545)
	at net.sf.saxon.expr.LetExpression.processLeavingTail(LetExpression.java:737)
	at net.sf.saxon.expr.instruct.NamedTemplate.expand(NamedTemplate.java:264)
	at net.sf.saxon.trans.XsltController.callTemplate(XsltController.java:850)
	at net.sf.saxon.s9api.Xslt30Transformer.callTemplate(Xslt30Transformer.java:480)
	at net.sf.saxon.Transform.processFile(Transform.java:1306)
	at net.sf.saxon.Transform.doTransform(Transform.java:853)
	at no.ramsen.Transform.main(Transform.java:16)
	at no.ramsen.App.main(App.java:33)

I believe the method signature for net.sf.saxon.om.NodeInfo.iterateAxis changed between Saxon 9.9 and Saxon 10, perhaps that is the cause?

Headers Fail to Get Set When Processing Http:body

Cannot invoke "org.expath.httpclient.HeaderSet.getFirstHeader(String)" because "headers" is null

...is returned by oXygen 26.1 when processing the following XSL...

                <http:request method="post" default-charset="utf-8">
                    <http:header name="Accept" value="*/*;charset=utf-8"/>
                    <http:header name="Accept-Encoding" value="utf-8"/>
                    <http:header name="Authorization" value="Bearer {$api-key}"/>
                    <http:header name="Content-Type" value="application/json;utf-8"/>
                    
                    <http:body media-type="application/json">
                        {
                        "model": "gpt-3.5-turbo-16k",
                        "messages": [
                        {
                        "role": "system",
                        "content": "You are a helpful assistant."
                        },
                        {
                        "role": "user",
                        "content": "Hello!"
                        }
                        ]
                        }
                    </http:body>
                </http:request>

This run is using Saxon-EE 12.3 and http-client-saxon-1.5.1-uber.jar.

Elimination of http:body results in a working, but uselsss, run. So body provokes headers getting set, but it seems that they can't be set because the default variable to which they need to be added isn't an empty array but rather a null.

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.