I'm trying to create a new Web API based on the ASP.Net 5 Web API template in VS2015, with DryIoc at container.
I've created a new Web API project and installed the DryIoc using package-manager
Install-Package DryIoc.Dnx.DependencyInjection -Pre
but I'm not sure how to wire up the container... haven't been able to find any 'Web API' samples showing that....
Any help would be greatly appreciated
I've figured it out now...
The default startup.cs file contains:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
}
but it has to be replace with:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var container = new Container().WithDependencyInjectionAdapter(services);
container.Register<IRepository, Repository>(Reuse.Singleton);
var serviceProvider = container.Resolve<IServiceProvider>();
return serviceProvider;
}
also the ' System.Runtime.Extensions >= 4.0.11-rc2-23706' error can just be ignored
I don't have a specific WebApi sample at the moment. But WebApi and Mvc are "unified" in AspNetCore, and I do have primitive Mvc sample. Hope it helps.
Btw, I am open for ideas / PRs how to improve it further.
Related
I'm trying the Camunda Enterprise today and notice the issue:
java.lang.IllegalStateException: Cannot create a session after the response has been committed
at org.apache.catalina.connector.Request.doGetSession(Request.java:2993)
at org.apache.catalina.connector.Request.getSession(Request.java:2432)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:908)
at org.apache.catalina.connector.RequestFacade.getSession(RequestFacade.java:920)
at org.camunda.bpm.webapp.impl.security.auth.AuthenticationFilter.doFilter(AuthenticationFilter.java:68)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at com.parkway.camunda.config.filter.CorsFilter.doFilterInternal(CorsFilter.java:25)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
...
Not sure this one is a bug or not ?
Only happen on
Spring-Boot: (v2.2.1.RELEASE)
Camunda BPM: (v7.12.0-ee)
Camunda BPM Spring Boot Starter: (v3.4.0)
I've tried with the same set of code and it's working fine on
Spring-Boot: (v2.2.1.RELEASE)
Camunda BPM: (v7.10.0)
Camunda BPM Spring Boot Starter: (v3.2.0)
Can someone help me to check ?
Thanks,
After search on the Internet for a day, I finally found the issue.
Root cause: because I'm calling REST API outside of Camunda website without turn on the Authentication mechanism and also using /api/abc/do-something
Ref: https://docs.camunda.org/manual/7.6/reference/rest/overview/authentication/
The REST API ships with an implementation of HTTP Basic Authentication. By default it is switched off.
Any request that does not address a specific engine (i.e., it is not of the form /engine/{name}/...) will be authenticated against the default engine.
Solution:
Change API path: from /api/abc/do-something -> /engine/api/abc/do-something
Switch on the Authentication by adding this configuration class (if you are using Spring Boot)
#Configuration
public class CamundaSecurityFilter {
#Bean
public FilterRegistrationBean processEngineAuthenticationFilter() {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setName("camunda-auth");
registration.setFilter(getProcessEngineAuthenticationFilter());
registration.addInitParameter("authentication-provider",
"org.camunda.bpm.engine.rest.security.auth.impl.HttpBasicAuthenticationProvider");
registration.addUrlPatterns("/*");
return registration;
}
#Bean
public Filter getProcessEngineAuthenticationFilter() {
return new ProcessEngineAuthenticationFilter();
}
}
Thanks to this guys: https://forum.camunda.org/t/turn-on-basic-http-authentication-for-rest-api-in-spring-boot/3431
Let me clear one thing that i don't wanna use "Add Service Reference" method. I want to call a soap service using HttpWebRequest in windows store app. I have working soap web service given by my client. I only have access to the web service but not source code. I have searched the internet but couldn't find solution for Windows store app.
Thanks in advance and Happy New Year.
Why do you want to avoid using Add Service Reference? Even so, I strongly discourage you from using HttpWebRequest directly as you will lose all the benefits of having the SOAP protocol already implemented.
You can use ChannelFactory<T>, though; even from a Windows Store app:
First create the interface from the web service WSDL using svcutil.exe:
svcutil /serviceContract http://localhost:61547/Service1.svc?wsdl
Include the generated code file in your Windows Store project.
Create the channel and call a method on it from your code:
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress("http://localhost:61547/Service1.svc");
var factory = new ChannelFactory<IService1>(binding, endpoint);
var channel = factory.CreateChannel();
var result = channel.GetData(3);
((IClientChannel)channel).Close();
I tried it out with a sample web service and it worked flawlessly.
I need to write a webservice client and call it from Jenkins. Below are my questions:
What is the best way to call a web service from Jenkins? Any default plug in available? I need to pass a XML data as input to the web service.
If plug in is not the option, can you please let me know what are the other ways we can achieve this (ANT+JAVA etc)?
If you have any sample code, that would be great.
Thanks
Aravind
It would be great to know you just need to call your client as part of some complex flow, implemented as a Jenkins job, or you want to concentrate on webservice testing.
WillieT has pointed you to several simple recipes which can be used to solve some basic tasks. If you need more power, better reporting, some additional features please consider the following:
Apache JMeter (details)
Building a WebService Test Plan
Web Service Testing in JMeter
Webservice testing with JMeter
JMeter can be integrated into Jenkins using Performance plugin. Report example:
Grinder (details)
I prefer to use this tool, but it might be to complex/heavy for you.
Grinder script gallery
How to Test REST Web Service Using The Grinder
Grinder can be integrated into Jenkins using Grinder plugin. Report example:
If you develop a plugin, e.g. extends hudson.tasks.Builder, include the following in pom.xml for JAX-RS Client:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>2.25.1</version>
</dependency>
A sample JAX-RS Client:
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import org.glassfish.jersey.client.ClientConfig;
public class RestClient {
private static String BASE_URL = "http://localhost:8090/rest";
private static String ACCESS_TOKEN = "8900***bc1";
public static String query(String path) {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getBaseURI());
// token authentication
String result = target.path(path).request().header("Authorization", "Token " + ACCESS_TOKEN)
.accept(MediaType.APPLICATION_JSON).get(String.class);
return result;
}
private static URI getBaseURI() {
return UriBuilder.fromUri(BASE_URL).build();
}
}
where http://localhost:8090/rest is the base rest url outside of Jenkins environment. Anywhere in your plugin code, you can simple call this as needed:
String rsData = RestClient.query("/project_type");
assume the full rest web service url is
http://localhost:8090/rest/project_type
You may also use Apache HttpClient, or OkHttp
I used 'HTTP Request' Plugin. This plugin works for REST as well as SOAP api.
enter image description here
Plugin image
What type of web service is supported by gwt application i have tried using Jersey, RESTful, Restlet, but nothing works with GWT. I want to deploy Web-Service on Tomcat and GWT application on app engine.
You can use RPC and RequestBuilder:
https://developers.google.com/web-toolkit/doc/latest/DevGuideServerCommunication
You can also use RESTful services:
How to call RESTFUL services from GWT?
Thanx all for your suport . . i have got the answer for my question.
i created a restfull web service using Jersey and called it using the following code in my gwt app engine application:
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(UriBuilder.fromUri("http://localhost:8080/de.vogella.jersey.first").build());
String obj=service.path("rest").path("bye").accept(MediaType.TEXT_PLAIN).get(String.class);
and the web application code is :
package de.vogella.jersey.first;
import javax.ws.rs.*;
#Path("/bye")
public class Hello {
// This method is called if TEXT_PLAIN is request
#GET
#Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return "Hello it worked";
}
For Web Application Code refer to this link:
http://www.vogella.com/articles/REST/article.html
I've created a WebService using the JAX-WS API. This service runs without any problem using an Endpoint class.
main(String args[])
{
(...)
MyService service=new MyService();
service.setParam1("limit=100");
service.setParam2("hello");
service.setParam3("max-value=10");
Endpoint endpoint = Endpoint.create(service);
endpoint.publish("http://localhost:8090/ws");
(...)
}
now, I'd like to deploy this service in glassfish. However, as I wrote in my example, I'd like to initialize my service with a some parameters. How can I achieve this ? should I use another API ?
Many thanks in advance
OK, I finally found the answer : using javax.xml.ws.WebServiceContext was the solution .see this other answer How can I access the ServletContext from within a JAX-WS web service?