How can I override the CXF services list URL? - cxf

My webservice has an REST endpoint URL like /myapp/admin/services. If I set org.apache.cxf.servlet.hide-service-list-page=false then my URL is hijacked by the CXF services list. This happens because the listings URL is relative in org.apache.cxf.transport.servlet.ServletController.
OK, fine, so I shouldn't have used the phrase "services" in my URL structure. Mea culpa. But now how do I fix this? I'd like to override the "/services" default in ServletController. I just need my container to invoke setServiceListRelativePath() on that class, but I can't figure out how. I imagine there's some magic Spring snippet to do this?
If it matters, I'm using CXF as bundled in the Talend Service Factory.

(turning my comment above into an answer, and modernizing since TSF no longer exists)
Under Karaf, add the following to etc/org.apache.cxf.osgi.cfg: "org.apache.cxf.servlet.service-list-path=/desired/path"

You can try this in your web.xml to override the CXF service list path
<init-param>
<param-name>service-list-path</param-name>
<param-value>/*</param-value>
</init-param>

Related

How to add an trailing slash to the camel http component of camel

Im am trying to call a rest post service from my Camel route.
The rest service is deployed at https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag/.
Calling the Service from a Rest Client like VS Code works if there is a trailing slash (after verteileauftrag).
In my camel route I have configured the following:
restConfiguration().host("https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1").component("http").bindingMode(RestBindingMode.json);
and in then later using the config:
.to("rest:post:verteileauftrag?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")
If I execute the code, I get a 404 HTTP Error from the Backend as the URL used is
https://csp-verteileauftrag-camunda-v1-csp-ims-dev-az.apcn.osp4-preprod.hel.kko.ch/api/v1/verteileauftrag. So without a trailing slash.
I have tried to add it like .to("rest:post:verteileauftrag/?outType=ch.helsana.csp.verteileauftrag.rest.model.apiadapter.ResponseType")
but no success.
Do you have any idea how to tell the http component in the rest configuration how to add the trailing slash?
Thank you very much.
Using redhat fuse 7_10_2.
Regards Michel
Based on a collegues example I reimplemented the Rest Service call with a normal .to("URL") configuration in the routebuilder with setting the appropriate Headers for HTTP Post and content type json. Would still be interessted in any answer, but not waiting on one.

Spring Boot application gives "405 method not supported" exception for only Angular/HTML/JSP resources

I have an application written with Spring Boot and AngularJS. When I try to hit a REST service as part of this application, I am able to hit it with POST method wherever POST is configured for request mapping.
But if I try to request AngularJS bind pages, I get a "405 method not supported" exception. So I try to create HTML and JSP pages too, which are not bound to Angular but still, I am getting the same exception.
Where can I start debugging this, and what is the likely reason?
i am sharing here furthere details about issue.
Basically this existing application created/developed with Jhipster, angularjs, Spring boot and spring security does not allow to access html/angularjs related resources with POST from outside. I will explain here what different scenarios work and what is not not working. 1.Postman trying to access base url trying to fetch index.html from same application- Give 405 Post method not allowed.2.Created an independent Test.html in same application and trying to access it from postman- Gives 405 Post method not allowed.3.Created a service which allows POST access in same application- Able to hit service from WSO2 IS IDP and also from Postman.4.Created a separate application on tomcat and provided as callback in WSO2 IDP with starting point for SSO from base url of existing application- Able to hit callback URL on tomcat server. Firefox shows that a POST request was generated for callback URL from WSO2 IS IDP to tomcat based application 5.Created a separate application with Angular js and Spring boot and provided as callback in WSO2 IDP with starting point for SSO from base url of existing application- Able to hit callback URL on tomcat server. Firefox shows that a POST request was generated for callback URL from WSO2 IS IDP to new application with Spring boot and Angularjs. This took me down to conclusion that one of three is causing this issue
1. Spring security generated from JHipster
2. Angularjs
3. Some CORS or other filter from Spring Security is causing this issue.
Till now we have tried to different debugging methods like
1. disable CORS,
2. in angularjs-resource.js enable POST for get operation,
3. In SecurityCOnfigurer, try to permit POST method for base URL or resolve it to GET in httpsercurity authorizerequest etc.
4. Also ignoring resources in websecurity.
Application stack for existing application which we are trying to implement SSO is as below
1. Angularjs 1.5.8
2. Springboot 1.5.9.release
3. WSO2IS 5.4.1
4. WSO2AM 2.1.0
5. JHipster
Let me know if any particular area which we might have missed to analyze or different methods to try.
Thanks,
Sandeep
Try to disable CSRF in security config
#Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
#Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
...
}
...
}
#SpringBootApplication
#Import({
...
SecurityConfig.class
...
})
public class SpringBootApp {
...
}

Angular CORS works with $http but not with $resource

I am new to angular, using v1.6, I have implemented a basic service for GET requests to communicate with Jetty service on a different host.
After annotating my service endpoints with CrossBorderResourceSharing. I am able to use $http without issues and I can seen the CORS flag in chrome debugger as well.
However $resource does not work gives the CORS error and does not show the CORS flag in debugger either , I am not using any custom settings for both just the basic call.
Let me know if sharing code snippet would help.
You need to enable CORS in the server endpoint.
Add the following to your WEB-INF/web.xml
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>

Create proxy for Apache CXF Web services in wso2 ESB

I am a very beginner in ESB. So, kindly excuse me for this basic question.
Currently we have web services created with Apache CXF and Spring running. Now, we need to create proxy services for these in WSo2 ESB. Can someone please let us know how can we do this?
I created Pass Through proxy and use wsdl definition as from URL, but when i use try it option i get he endpoint reference (EPR) for the Operation not found is /services/ and the WSA Action = null.
If this EPR was previously reachable,please contact the server administrator.
Since ESB 4.6, pass-through transport is enabled by default : The message body is not build so, SOAP Body based dispatching is not supported => in this case, the error you're speaking about is thrown
One solution could be to add this parameter in your proxy conf : <parameter name="disableOperationValidation" locked="false">true</parameter>
Have a look there for other options : Using WSO2 ESB PassThrough Proxy on WebLogic (Spring) Web Service
How did you create the proxy service? If you have the wsdl of the Backend service you can use it to create the proxy service like follows.
<proxy xmlns="http://ws.apache.org/ns/synapse" name="testProxy2" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
<target>
<outSequence>
<send/>
</outSequence>
<endpoint>
<wsdl service="SimpleStockQuoteService"
port="SimpleStockQuoteServiceHttpSoap11Endpoint"
uri="http://localhost:9000/services/SimpleStockQuoteService?wsdl"/>
</endpoint>
</target>
<description/>
</proxy>
The ESB gets the endpoint url from the Service name and Port defined in the WSDL. For SOAP 1.1 the WSA action will be the SOAPAction header and for SOAP 1.2 the WSA action goes with the action element of Content-Type header. For example,
Content-Type: application/soap+xml;charset=UTF-8;action="TheSoapAction"
Try to use a SOAP client like SOAPUI to test your proxy service.

Unable to see saved entities using cloud end point rest API

I have a gae project that uses cloud end points in Java which is a very simple CRUD application.
I have some PUT requests that change the datastore entities and GET requests that retrieve them. I find the GET requests always do not return the latest value of the entities. This is happening for several GET requests. When I check the saved value in my datastore viewer I can confirm the new value is saved correctly.
I tried this with Google API explorer and also with another REST client (called Postman available in chrome web store).
The pattern seems to be this -
1) send PUT request to change entity
2) send GET request to retrieve entity. sometimes I see old value and sometime I see new value. I can confirm latest data is saved from datastore viewer. This happens for multiple GET requests.
This seems like pretty basic functionality and may be I am doing something wrong. This is how my api annotations look like -
#Api (name = "content",
scopes = { "https://www.googleapis.com/auth/userinfo.email" }
)
public class ContentAPI extends APIBase {
#ApiMethod(path="setcontent", httpMethod = HttpMethod.PUT)
public APIResponse setContent(#Named("content_html") String html,
#Named("tag") String tag, #Named("publish") boolean publish, User user) {
...
//save content in the datastore
}
#ApiMethod(path="getcontent", httpMethod = HttpMethod.GET)
public APIResponse getContent(#Named("tag") String tag,
User user) {
...
//retrieve the saved content and send it back.
}
Has anyone encountered such issues before ? Any help would be appreciated.
[Edit] - this looks like a datastore issue and not a cloud endpoint issue. I have opened another question [here] (Unable to get saved entity using objectify)
Regards,
Sathya
It turns out this is not an issue with cloud end point.
I am using objectify as my data access API and I had forgotten to add objectify filter in web.xml as mentioned in Objectify wiki page
I added the following in my web.xml and the problem was solved.
<filter>
<filter-name>ObjectifyFilter</filter-name>
<filter-class>com.googlecode.objectify.ObjectifyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>ObjectifyFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

Resources