Magento - Custom REST API giving 404 - rest

I've followed a tutorial online on how to create a custom REST API endpoint for Magento 1.9.2. However, after completing the oauth process and getting a secret and key I always get a 404 trying to call the endpoint.
I think my problem is coming from the api.xml file as I don't quite understand the values that can be used for the various options. The file is below:
<config>
<api2>
<resource_groups>
<categories translate="title" module="EG_Categories">
<title>Categories API</title>
<sort_order>10</sort_order>
</categories>
</resource_groups>
<resources>
<categories translate="title" module="EG_Categories">
<group>categories</group>
<model>categories/api2_categoriesapi</model>
<title>Category API</title>
<sort_order>10</sort_order>
<privileges>
<admin>
<create>1</create>
<retrieve>1</retrieve>
</admin>
<guest>
<retrieve>1</retrieve>
</guest>
</privileges>
<attributes>
<name>Category Name</name>
<parent>Parent ID</parent>
</attributes>
<routes>
<route>
<route>/categories/retrieve</route>
<action_type>collection</action_type>
</route>
</routes>
<versions>1</versions>
</categories>
</resources>
</api2>
</config>
In particular, I haven't been able to find out if collection is the correct value for the action type to activate the _retrieveCollection method in the class file.
I have one class file located at app/code/local/EG/Categories/Model/Api2/Categories.php.
Also in APi2 is /Categories/Rest/Admin/V1.php.
Any advice would be much appreciated.

Related

Spring security - GWT redirect after Authentication

I have a GWT application that I am trying to login using spring security. Currently, after a successful login, I am redirected back to the Login page. I am guessing this is because of my spring configuration and my lack of spring security knowledge.
In my spring-security.xml I define my intercepts like so:
<security:http auto-config="true">
<security:intercept-url pattern="/login" access="permitAll" />
<security:intercept-url pattern="/**" access="isAuthenticated()" />
</security:http>
I am guessing that the issue is on the access=isAuthenticated() but I am not sure. I want it to redirect to the gwt page/app which will handle the view based on the role returned. I made a very simple gwt app with this method and it worked.
I am using the Spring generated login page and not a JSP.
spring-security.xml
<?xml version="1.0" encoding="UTF-8"?>
<b:beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:b="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">
<!-- This is where we configure Spring-Security -->
<security:http auto-config="true">
<security:intercept-url pattern="/login" access="permitAll" />
<security:intercept-url pattern="/**" access="isAuthenticated()" />
</security:http>
<b:bean id="graplAuthentication" class="com.foo.rim.security.GraplAuthentication"/>
<security:authentication-manager alias="authenticationManager">
<security:authentication-provider ref="graplAuthentication" />
</security:authentication-manager>
</b:beans>
This turned out to be two things.
1) I needed to add the user-expressions="true" so it would pick up the access=
<security:http auto-config="true" use-expressions="true">
2) I had a custom user Authentication class and forgot to set the the Authenticated boolean to true. Both of these got it working correctly.

Camel REST - Path based routing

I have to develop a Camel REST route with path-based routing.
The scenario is as follows: we have a business partner which provided a REST web service for displaying documents. The REST web service is deployed on 3 different servers, depending on the geographic location.
So we basically have 3 server like these:
http://north.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
http://center.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
http://south.acme.com/flowdocv2/rest/repository/attachment/{id}/findById
My aim is to develop a single Camel route to map these server, accepting the name of the server in the path. Something like this:
http://my.camel.com/center/repository/attachment/{id}/findById
http://my.camel.com/north/repository/attachment/{id}/findById
http://my.camel.com/south/repository/attachment/{id}/findById
My (simplified and not working) blueprint.xml:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0"
xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<cm:property-placeholder persistent-id="my.config.file"/>
<reference id="sharedNettyHttpServer" interface="org.apache.camel.component.netty4.http.NettySharedHttpServer"/>
<camelContext id="my_context" xmlns="http://camel.apache.org/schema/blueprint">
<restConfiguration component="netty4-http">
<endpointProperty key="nettySharedHttpServer" value="#sharedNettyHttpServer"/>
</restConfiguration>
<rest path="/center/repository">
<get uri="/attachment/{attachmentId}/findById">
<route streamCache="true" trace="true">
<to uri="http://center.acme.com/flowdocv2/rest?bridgeEndpoint=true"/>
</route>
</get>
</rest>
<rest path="/north/repository">
<get uri="/attachment/{attachmentId}/findById">
<route streamCache="true" trace="true">
<to uri="http://north.acme.com/flowdocv2/rest?bridgeEndpoint=true"/>
</route>
</get>
</rest>
</camelContext>
</blueprint>
The problem is that I don't know how to remove /center, /north or /south from the path, so the header is forwared to the destination service, which doesn't know how to deal with it.
Invoking:
http://my.camel.com/center/repository/attachment/{id}/findById
results in the following URL being invoked on the destination server:
http://center.acme.com/flowdocv2/rest/center/repository/attachment/{id}/findById
How to get rid of center? I don't want to deploy 3 camel routes on different ports.
Thank you
I think it is actually a bit easier. As long as you do not hang onto netty and you are using Camel 2.11+ you can use camel-urlrewrite
Basically, you define a single rewrite rule in a configuration and add this to your route bundle.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN"
"http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd">
<urlrewrite>
<rule>
<name>Generic Proxy</name>
<note>
This rule completely rewrites the url to call.
Basically, in Camel's "to", you could write whatever you want
</note>
<from>^/(.*?)/(.*)</from>
<to>http://$1.acme.com/flowdocv2/rest/$2</to>
</rule>
</urlrewrite>
Now, you can utilize a rather simple route:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.0.0" xmlns:cxf="http://camel.apache.org/schema/blueprint/cxf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0
https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="myRewrite" class="org.apache.camel.component.urlrewrite.HttpUrlRewrite">
<property name="configFile" value="class/path/to/proxyrewrite.xml" />
</bean>
<camelContext id="my_context" xmlns="http://camel.apache.org/schema/blueprint">
<route id="proxyRoute">
<from uri="jetty:http://localhost:9090/proxy" />
<to uri="jetty:http://somewhere/myapp2?bridgeEndpoint=true&throwExceptionOnFailure=false&urlRewrite=#myRewrite" />
</route>
</camelContext>
</blueprint>
However, netty is not supported, so I chose the next best thing.
When you call http://localhost:9090/proxy/north/foo, the rewrite will actually change the url to call to http://north.acme.com/flowdoc2/rest/foo.
There are a few caveats with this. First, you have to use one of the supported components for UrlRewrite. Second, it seems that you have to have the rewrite config file in you classpath - so no blueprint-only route. Third: I did not test it, but I think you get the gist. I make this a community wiki answer, so that others, more capable than me, can expand on this answer.

Self Hosted (console) WCF configuration

i had a WCF server running through a Console application, it will run as an azure service so i don't to host it in ISS.
I belived it work well and share datas to my web app through ajax request. But when i maked a service that recieve a filestream, i realized that my binding configuration is not used at all. My WCF work same without binding section.
My probleme concerne especially the key "maxReceivedMessageSize" because default value limit me to 8Ko request and it is a problem for uploading file.
Bindings section (that i can comment) :
<webHttpBinding>
<binding name="MyBindingConfig" crossDomainScriptAccessEnabled="true" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" transferMode="Buffered">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" />
<security mode="None" />
</binding>
</webHttpBinding>
Services section :
<service name="MyData.Service.MyDataServiceRestFull">
<endpoint binding="webHttpBinding"
contract="MyData.Service.IMyDataServiceRestFull" bindingName="MyBindingConfig" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:9997/MyDataServer"/>
</baseAddresses>
</host>
</service>
Note that i tryed with basicHttpBinding and i had same issue.
The problem is that you're incorrectly referring to your binding in your <endpoint/> element. You're using the bindingName attribute, when you should be using the bindingConfiguration attribute:
<endpoint binding="webHttpBinding"
contract="MyData.Service.IMyDataServiceRestFull"
bindingConfiguration="MyBindingConfig" />

odatagen: Failed to generate proxy classes. Please verify the metadata (iOS)

Im working on Open Data Protocol (OData) which is a standardized protocol for creating and consuming data API's.
OData builds on core protocols like HTTP and commonly accepted methodologies like REST .
I have installed, configured and built OData successfully on iOS6
Currently I'm creating a Proxy class to connect to the OData Service using the following commands:
cd /Users/Shamsu/Applications/ODataObjC/ODataSDKV1-1.3/Framework/bin/ODatagenBinary/MacOSX10.7.sdk/Debug
./odatagen /uri=http://35.35.6.4/MyApp.MyApp3D.DataService/MyApp3DDataService.svc/ /out=/Users/Ramshad/Applications/ODataObjC/ODataSDKV1-1.3/Framework/bin/ODatagenBinary/MacOSX10.7.sdk/Debug /u=sa /p=123
However, I'm getting the error: "odatagen: Failed to generate proxy classes. Please verify the metadata"
I can see the "metadata.xml" file is updated as
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="1.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="MyAppDBModel" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="User">
<Key>
<PropertyRef Name="UserID" />
</Key>
<Property Name="UserID" Type="Edm.Guid" Nullable="false" />
<Property Name="UserName" Type="Edm.String" MaxLength="10" FixedLength="true" Unicode="true" />
<Property Name="UserDescription" Type="Edm.String" MaxLength="50" FixedLength="false" Unicode="true" />
<Property Name="Active" Type="Edm.Int64" />
</EntityType>
</Schema>
<Schema Namespace="MyApp.MyApp3D.DataService" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityContainer Name="MyAppDBEntities" m:IsDefaultEntityContainer="true" p6:LazyLoadingEnabled="true" xmlns:p6="http://schemas.microsoft.com/ado/2009/02/edm/annotation">
<EntitySet Name="User" EntityType="MyAppDBModel.User" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx> "
Note: the metadata.xml file is located at out param location (/Users/Ramshad/Applications/ODataObjC/ODataSDKV11.3/Framework/bin/ODatagenBinary/MacOSX10.7.sdk/Debug /metadata.xml)
I'm unable to identify the issue. Any problem with my windows WCF service /ODataService configuration/database configuration ? Permission assigned as * (read,write).
Any help on this issue is appreciated.
Thanks.
I looked a bit closer at the XSLT document I linked to in my original comment, and it seems that the odatagen tool hasn't been updated to work with CSDL v3. The version of CSDL (i.e., the format used to serialize the metadata document) is indicated by the xml namespace of the Schema element. In your metadata, that namespace is http://schemas.microsoft.com/ado/2009/11/edm, which indicates CSDL v3. You can see in the XSLT document here that this namespace isn't recognized by the odatagen tool.
Since the odatagen tool is open source (see the source on github), you can try to tweak the code and XSLT files to make it work for your situation. You could try to just add the v3 namespace to the recognized schema namespaces, and if your metadata doesn't use any v3 features, I would imagine it would just work. Off the top of my head I'm not sure of the exact differences between v2 and v3, so I can't immediately say whether the metadata you've posted above would be valid in CSDL v2.
Alternatively, you could try to generate the $metadata document so that it's using CSDL v2 instead.
Sorry I don't have a better answer for you. Unfortunately, the odatagen tool has fallen a bit behind. But you're more than welcome to contribute to the project :)

Unable to Create Live Smooth Streaming Publishing Point Programatically

I'm trying to use the REST API for IIS Media Services to create a Live Publishing point programatically. For this, I'm sending a POST call to this URL:
http://127.0.0.1/services/smoothstreaming/publishingpoints.isml/settings
I've included two custom headers to the request:
Content-Type: application/atom+xml
Slug: /test.isml
And this is the body of the request:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<id>http://127.0.0.1/test.isml/settings</id>
<title>Test</title>
<updated>2012-07-12T19:13:25Z</updated>
<content type="application/xml">
<SmoothStreaming xmlns="http://schemas.microsoft.com/iis/media/2011/03/streaming/management">
<Settings>
<Title>Test</Title>
<SourceType>Push</SourceType>
<AutoStart>false</AutoStart>
<AutoRestartOnEncoderReconnect>false</AutoRestartOnEncoderReconnect>
<LookAheadChunks>2</LookAheadChunks>
<Archive enabled="false">
<Path useEventIdOnPath="false" />
</Archive>
<ClientConnections enabled="true">
<ClientManifestVersion>2.0</ClientManifestVersion>
</ClientConnections>
<ServerConnections enabled="false">
<SendEndOfStreamOnStop>false</SendEndOfStreamOnStop>
</ServerConnections>
</Settings>
</SmoothStreaming>
</content>
</entry>
IIS is giving me a 405/Bad Request error with this body:
<?xml version="1.0" encoding="UTF-8"?>
<SmoothStreaming xmlns="http://schemas.microsoft.com/iis/media/2011/03/streaming/management">
<Error>
<ErrorCode>0x80880026</ErrorCode>
<ErrorMessage>The resource contains one or more elements that contain invalid data. For information about valid resource representations, please see the documentation for the supported schemas.</ErrorMessage>
</Error>
</SmoothStreaming>
Anyone knows what I'm doing wrong here?
Ommiting the "Archive" and "ServerConnections" nodes fixed it. Not sure it there's anything wrong in them, or if they're only supposed to be included when enabled=true.