Jump to content
Lorenzo Sampietro

RAD Studio 10.4.2: RAD Server and “Duplicate enpoints” image or text

Recommended Posts

Good morning,

 

I've opened the same question to stack overflow: https://stackoverflow.com/questions/67299714/rad-studio-10-4-2-rad-server-and-duplicate-enpoints-image-or-text

 

I'm following this David Intersimone's video tutorial about RAD Server: https://www.youtube.com/watch?v=eCyTiDq_jBY&list=WL&index=6&t=2723s

At minute 43 he explain how to setup multiple access types using EndpoinProduce directive. You can find the same example at page 142 of "The Complete Guide To RAD Server".

I exactly copy the example but it still now working. Here you can find the code:



unit Unit1;

// EMS Resource Module

interface

uses
  System.SysUtils, System.Classes, System.JSON,
  EMS.Services, EMS.ResourceAPI, EMS.ResourceTypes;

type
  [ResourceName('AcceptTypes')]
  TAcceptTypesResource1 = class(TDataModule)
  published
    [ResourceSuffix ('*')]
    [EndpointProduce ('application/xml')]
  //  [EndPointResponseDetails(200, 'Ok', TAPIDoc.TPrimitiveType.spObject, TAPIDoc.TPrimitiveFormat.None, '', '')]
  //  [EndPointResponseDetails(404, 'Not Found', TAPIDoc.TPrimitiveType.spNull, TAPIDoc.TPrimitiveFormat.None, '', '')]
    procedure GetText(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);


    [ResourceSuffix ('*')]
    [EndpointProduce ('image/jpeg')]
  //  [EndPointRequestSummary('Tests', 'ListItems', 'Retrieves list of items', 'application/json', '')]
  //  [EndPointResponseDetails(200, 'Ok', TAPIDoc.TPrimitiveType.spObject, TAPIDoc.TPrimitiveFormat.None, '', '')]
    procedure GetImage(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
  end;

implementation

{%CLASSGROUP 'System.Classes.TPersistent'}

{$R *.dfm}

procedure TAcceptTypesResource1.GetImage(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create('c:\RADServer\page\content.jpeg', fmOpenRead);
  AResponse.Body.SetStream(fs, 'image/jpeg', True);
end;

procedure TAcceptTypesResource1.GetText(const AContext: TEndpointContext; const ARequest: TEndpointRequest; const AResponse: TEndpointResponse);
var
  fs: TFileStream;
begin
  fs := TFileStream.Create('c:\RADServer\page\content.txt', fmOpenRead);
  AResponse.Body.SetStream(fs, 'text/plain', True);
end;

procedure Register;
begin
  RegisterResource(TypeInfo(TAcceptTypesResource1));
end;

initialization
  Register;
end.

The page HTML that invoke the software is:

<html>
   
<head>
    <title>a page for rad server</title>
  </head>
  <building>
    <h1>a page</h1>
    <p>an image below</p>
    <img src="/AcceptTypes/test.jpeg">
    <p>&nbsp;</p>
    <h1>some more</h1>
    <iframe src="/AcceptTypes/test.txt">
  </building>
</html>

When I run the software RAD Server returns this error:

{"Thread":2216,"Error":{"Type":"HTTP","Code":"500","Reason":"Error","Error":"Resource error","Description":"Duplicate endpoints: GetText, GetImage. Each endpoint must have an unique HTTP method, URL or produce / consume types"}}

It seems it don't recognize the endpoints.

Do you have any idea?

thank you

Share this post


Link to post

Request must contain valid Accept header, then RAD Server will choose the correct endpoint. If there is no Accept, or it is not unique identifying endpoint, then above error is returned. Check what your browser is sending in request Accept headers.

Edited by Dmitry Arefiev

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×