[basex-talk] Stopping BaseX HTTP server

2019-08-01 Thread Markus Wittenberg

Hi all,

we have a problem trying to stop a BaseX HTTP server with the Windows 
task scheduler. The server ist started with a maven profile, calling


mvn exec:java -Pstart

pom.xml extract see below, and can also be stopped directly with the 
corresponding stop profile by a batch file:


cd /D "%~dp0"
mvn exec:java -Pstop

But calling this batch profile in task scheduler works fine on our local 
computers, but does not work on the server (Windows Server 2012). On 
this machine, executing the stop profile by the task scheduler results 
in a message


HTTP server was started (port: 8985).

in the console window of the process to be stopped, but it continues 
running anyway.


Any ideas regarding this strange behavior?

Can we stop the server with a simple HTTP request? Calling 
localhost:8985 in the browser also results only in the message above.


Thanks in advance for any hints.

Best regards,

  Markus


Extract from pom.xml:


    
  start
  
    
  
org.codehaus.mojo
exec-maven-plugin
    1.4.0
    
org.basex.BaseXHTTP
  
    -h9894
    -s8985
    -p1985
    -Urestxq
  
  
src/main/resources
  
    
  
    
  
    
    
  stop
  
    
  
org.codehaus.mojo
exec-maven-plugin
    1.4.0
    
org.basex.BaseXHTTP
  
    -s8985
    stop
  
    
  
    
  
    
    


--
Markus Wittenberg

Tel +49 (0)341 248 475 36
Mail wittenb...@axxepta.de



axxepta solutions GmbH
Lehmgrubenweg 17, 88131 Lindau

Amtsgericht Berlin HRB 97544B
Geschäftsführer: Karsten Becke, Maximilian Gärber



Re: [basex-talk] Forcing download of JSON doc

2019-08-01 Thread Tim Thompson
Thanks for the tip! By declaring the %output:method("json") annotation AND
calling the serialize function, I was basically reserializing the data.

--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library

On Thu, Aug 1, 2019 at 8:55 AM Marco Lettere  wrote:

> Maybe using json:serialize() rather than serialize?
>
> In general if output:method is set to Json it should be sufficient to
> return map{} or array{} or alternatively the XML version of a json document
> without having to explicitly serialize ...
>
> M.
>
> On 01/08/19 14:36, Tim Thompson wrote:
>
> Thank you, Marco. So, the download issue seems to be with XForms
> (XSLTForms) rather than BaseX. If I do a file upload from a plain HTML
> form, the file download is triggered correctly. However, even though I have
> set "application/json" as the Content-Type, the contents of the downloaded
> file are an escaped string rather than a serialized JSON object: e.g.,
>
> "{\n  \"key\": \"value\"\n}"
>
> Is there a way to produce a properly serialized JSON file for download?
>
> --
> Tim A. Thompson
> Discovery Metadata Librarian
> Yale University Library
>
> On Thu, Aug 1, 2019 at 3:03 AM Marco Lettere  wrote:
>
>> Hi Tim,
>> downloading from a browser when posting a form is usually a bit tricky.
>> For me it always ended up with the creation of an artificial 
>> element with an href crafted from the form parameters and with an attribute
>> download="filename.ext" added to it.
>> Anyway you could try with returning a "forced" application/octet-stream
>> Content-Type header 
>>
>> M.
>>
>> On 01/08/19 05:00, Tim Thompson wrote:
>>
>> Hello,
>>
>> I am posting a JSON doc to a RESTXQ function from XForms and trying to
>> set a Content-Disposition header to trigger a file download. Is this
>> possible to do without first saving the JSON doc as a file? Right now, the
>> RESTXQ function returns the correct headers, but does not force a file
>> download dialog.
>>
>> Thanks in advance!
>> Tim
>>
>> --
>> Query:
>>
>> xquery version "3.1";
>>
>> module namespace wrap = "http://example.org/wrap";;
>>
>> declare
>>   %rest:path("/wrap")
>>   %rest:POST("{$data}")
>>   %output:method("json")
>> function wrap:process(
>>   $data as node()
>> ) as item()* {
>>   let $name := data($data/data/upload/file/@name)
>>   let $json := json-to-xml($data/data/upload/file)
>>   let $header :=
>> ``[attachment; filename="`{$name}`";]``
>>   return
>> (
>> 
>>   > status="200" message="OK">
>> >   name="Content-Type"
>>   value="application/json"/>
>> >   name="Content-Disposition"
>>   value="{$header}"/>
>>   
>> ,
>>
>> http://www.w3.org/2005/xpath-functions";>
>> >   key="Profile">
>>   > key="resourceTemplates">{$json}
>>   > key="title">Wrapper_Profile
>>   > key="id">Wrapper:Profile:BF2
>>   > key="description">Profile wrapper for resource
>> templates
>>   > key="author">Wrapper
>>   > key="schema">
>> https://ld4p.github.io/sinopia/schemas/0.0.9/profile.json
>>   > key="date">{current-dateTime()}
>> 
>>  => xml-to-json() => parse-json() => serialize(map {'method':
>> 'json', 'use-character-maps' : map {'/' : '/'}})
>> )
>> };
>>
>>
>> --
>> Tim A. Thompson
>> Discovery Metadata Librarian
>> Yale University Library
>>
>>
>>
>


Re: [basex-talk] Forcing download of JSON doc

2019-08-01 Thread Marco Lettere

Maybe using json:serialize() rather than serialize?

In general if output:method is set to Json it should be sufficient to 
return map{} or array{} or alternatively the XML version of a json 
document without having to explicitly serialize ...


M.

On 01/08/19 14:36, Tim Thompson wrote:
Thank you, Marco. So, the download issue seems to be with XForms 
(XSLTForms) rather than BaseX. If I do a file upload from a plain HTML 
form, the file download is triggered correctly. However, even though I 
have set "application/json" as the Content-Type, the contents of the 
downloaded file are an escaped string rather than a serialized JSON 
object: e.g.,


"{\n  \"key\": \"value\"\n}"
Is there a way to produce a properly serialized JSON file for download?

--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library

On Thu, Aug 1, 2019 at 3:03 AM Marco Lettere > wrote:


Hi Tim,
downloading from a browser when posting a form is usually a bit
tricky. For me it always ended up with the creation of an
artificial  element with an href crafted from the form
parameters and with an attribute download="filename.ext" added to it.
Anyway you could try with returning a "forced"
application/octet-stream Content-Type header 

M.

On 01/08/19 05:00, Tim Thompson wrote:

Hello,

I am posting a JSON doc to a RESTXQ function from XForms and
trying to set a Content-Disposition header to trigger a file
download. Is this possible to do without first saving the JSON
doc as a file? Right now, the RESTXQ function returns the correct
headers, but does not force a file download dialog.

Thanks in advance!
Tim

--
Query:

xquery version "3.1";

module namespace wrap = "http://example.org/wrap";;

declare
  %rest:path("/wrap")
  %rest:POST("{$data}")
  %output:method("json")
function wrap:process(
  $data as node()
) as item()* {
  let $name := data($data/data/upload/file/@name)
  let $json := json-to-xml($data/data/upload/file)
  let $header :=
    ``[attachment; filename="`{$name}`";]``
  return
    (
    
      
        
        
      
    ,

    http://www.w3.org/2005/xpath-functions";>
        
          {$json}
          Wrapper_Profile
          Wrapper:Profile:BF2
          Profile wrapper for resource
templates
          Wrapper
          https://ld4p.github.io/sinopia/schemas/0.0.9/profile.json
          {current-dateTime()}
        
     => xml-to-json() => parse-json() => serialize(map
{'method': 'json', 'use-character-maps' : map {'/' : '/'}})
    )
};


--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library







Re: [basex-talk] Forcing download of JSON doc

2019-08-01 Thread Tim Thompson
Thank you, Marco. So, the download issue seems to be with XForms
(XSLTForms) rather than BaseX. If I do a file upload from a plain HTML
form, the file download is triggered correctly. However, even though I have
set "application/json" as the Content-Type, the contents of the downloaded
file are an escaped string rather than a serialized JSON object: e.g.,

"{\n  \"key\": \"value\"\n}"

Is there a way to produce a properly serialized JSON file for download?

--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library

On Thu, Aug 1, 2019 at 3:03 AM Marco Lettere  wrote:

> Hi Tim,
> downloading from a browser when posting a form is usually a bit tricky.
> For me it always ended up with the creation of an artificial 
> element with an href crafted from the form parameters and with an attribute
> download="filename.ext" added to it.
> Anyway you could try with returning a "forced" application/octet-stream
> Content-Type header 
>
> M.
>
> On 01/08/19 05:00, Tim Thompson wrote:
>
> Hello,
>
> I am posting a JSON doc to a RESTXQ function from XForms and trying to set
> a Content-Disposition header to trigger a file download. Is this possible
> to do without first saving the JSON doc as a file? Right now, the RESTXQ
> function returns the correct headers, but does not force a file download
> dialog.
>
> Thanks in advance!
> Tim
>
> --
> Query:
>
> xquery version "3.1";
>
> module namespace wrap = "http://example.org/wrap";;
>
> declare
>   %rest:path("/wrap")
>   %rest:POST("{$data}")
>   %output:method("json")
> function wrap:process(
>   $data as node()
> ) as item()* {
>   let $name := data($data/data/upload/file/@name)
>   let $json := json-to-xml($data/data/upload/file)
>   let $header :=
> ``[attachment; filename="`{$name}`";]``
>   return
> (
> 
>status="200" message="OK">
>name="Content-Type"
>   value="application/json"/>
>name="Content-Disposition"
>   value="{$header}"/>
>   
> ,
>
> http://www.w3.org/2005/xpath-functions";>
>key="Profile">
>key="resourceTemplates">{$json}
>key="title">Wrapper_Profile
>key="id">Wrapper:Profile:BF2
>key="description">Profile wrapper for resource
> templates
>key="author">Wrapper
>key="schema">
> https://ld4p.github.io/sinopia/schemas/0.0.9/profile.json
>key="date">{current-dateTime()}
> 
>  => xml-to-json() => parse-json() => serialize(map {'method':
> 'json', 'use-character-maps' : map {'/' : '/'}})
> )
> };
>
>
> --
> Tim A. Thompson
> Discovery Metadata Librarian
> Yale University Library
>
>
>


Re: [basex-talk] Forcing download of JSON doc

2019-08-01 Thread Marco Lettere

Hi Tim,
downloading from a browser when posting a form is usually a bit tricky. 
For me it always ended up with the creation of an artificial  
element with an href crafted from the form parameters and with an 
attribute download="filename.ext" added to it.
Anyway you could try with returning a "forced" application/octet-stream 
Content-Type header 


M.

On 01/08/19 05:00, Tim Thompson wrote:

Hello,

I am posting a JSON doc to a RESTXQ function from XForms and trying to 
set a Content-Disposition header to trigger a file download. Is this 
possible to do without first saving the JSON doc as a file? Right now, 
the RESTXQ function returns the correct headers, but does not force a 
file download dialog.


Thanks in advance!
Tim

--
Query:

xquery version "3.1";

module namespace wrap = "http://example.org/wrap";;

declare
  %rest:path("/wrap")
  %rest:POST("{$data}")
  %output:method("json")
function wrap:process(
  $data as node()
) as item()* {
  let $name := data($data/data/upload/file/@name)
  let $json := json-to-xml($data/data/upload/file)
  let $header :=
    ``[attachment; filename="`{$name}`";]``
  return
    (
    
      
        
        
      
    ,

    http://www.w3.org/2005/xpath-functions";>
        
          {$json}
          Wrapper_Profile
          Wrapper:Profile:BF2
                      key="description">Profile wrapper for resource 
templates

          Wrapper
                      
key="schema">https://ld4p.github.io/sinopia/schemas/0.0.9/profile.json

          {current-dateTime()}
        
     => xml-to-json() => parse-json() => serialize(map 
{'method': 'json', 'use-character-maps' : map {'/' : '/'}})

    )
};


--
Tim A. Thompson
Discovery Metadata Librarian
Yale University Library