0

This question related to cross site submission across JSP/Servelet based web application and ASP.NET MVC based web application. I could able to submit a NameValueCollection object from an ASP.NET Web project to another ASP.NET MVC project like below.

using (var client = new WebClient())
{
client.Credentials = CredentialCache.DefaultNetworkCredentials;
string transId = Guid.NewGuid().ToString(); //In Java we may use UUID class
var data = new NameValueCollection
{
{ "TransId", transId },
{ "Name", "Regi" },
{ "DOB", "10/17/2013" },
{ "ZIPCode", "673010" },
};
var result = client.UploadValues("http://localhost:50976/api/Trans/Trans", data);
string s = Encoding.ASCII.GetString(result); //May be Base64.encodeToString(fileData, Base64.CRLF) in Java?

if (s == "1")
{

Response.Redirect("http://localhost:50976/Product/ProductList?TransId=" + transId + "");
}
}

ASP.NET MVC project has a WebAPI which is catching this submission like below.

public int Trans(TransViewModel transViewModel)
{

            return 1;
}

My ViewModel definition like below

public class TransViewModel
{
        public string TransId { get; set; }
        public string Name { get; set; }
        public DateTime DOB { get; set; }
}

So now I need to replace my 1st WebProject where ASP.NET MVC application is calling, with a Java based web application. How can I accomplish the same submission using alternate JAVA classes in place of WebClient and also to submit a NameValueCollection type to the same ASP.NET MVC application? This submission should be accepted by ASP.NET MVC application like above through a ViewModel

Jaish Mathews
  • 766
  • 1
  • 9
  • 25
  • Java is not running on the client you need to learn the Java framework. –  Oct 21 '13 at 18:00
  • Don't you mean Javascript maybe? or you mean the JVM – Carlos Grappa Oct 21 '13 at 18:02
  • I know Java is not running on client. I mean JSP/Servelet based site. I have already have this web application. There I need to add the functionality to route to an ASP.NET MVC application. – Jaish Mathews Oct 21 '13 at 18:03

2 Answers2

0

Hmm.. I haven't tried but if you just use regular HTTP GET or POST it doesn't matter what web framework you are using. What ASP.NET MVC want is just a NORMAL request (for example: http://yourwebsite.com:8081/Main/Index?name=Me&email=me@gmail.com).If you send it from any java or other web frameworks your MVC router will be able to map them to a particular action method. In my example this is the Main controller and Index action (HTTP GET) with parameters name and email (string type). The same for Post (add HTTP POST attribute for the action). Problems could have place if you were using models. In this case I always use fiddler to see what exactly I am sending to MVC and also you have to understand how standard MVC model binding works. If you find that your java data structure can't be handled with the MVC standard model binder you can whether change the data structure or implement custom model binder and directly get access to all request data. MVC is a very pluggable framework and I believe this is one of the best web frameworks ever created!

Anton
  • 731
  • 4
  • 5
  • Yeah. It’s making sense especially the points to be taken care before choosing a solid approach. Irony is that even though loaded inside a browser, all actions are basically HTML and HTTP based. Then also we need to find a way for cross technology transition of DTO objects across web without any mediator. We can pass query string across sites though. Otherwise we may less knowledgeable :). In between, just think reverse as, if I use WebClient in ASP.NET MVC and sending a NameValueCollection, how java web application can catch it? – Jaish Mathews Oct 22 '13 at 16:50
0

I am not sure that you are trying to do. But I think that there is no way to DIRECTLY pass data between MVC and let's say plain java servlet. You always send data as HTTP requests and it's up to web framework how to handle them. If you need a similar to MVC you can use Spring MVC (java). Again I am not really sure what you are trying to achieve. However, you can make any HTTP based calls from server as well. For example, you have a servlet mapped to /doSomething in your java environment. In the servlet inside get method you have all access to request parameters. So in your MVC project you are free to just make a server side http based call to the servlet mapped address and pass any parameters. In the servlet you generate output and return to the mvc server. After it's up to you what to do with it!

Anton
  • 731
  • 4
  • 5
  • I decided to use the plain HTTP Post so that both side can accept the submitted key value. – Jaish Mathews Oct 24 '13 at 05:29
  • Simple and elegant.. another approach is to use web services or MUCH better to use RESTfull .I would use WebAPI in .net or Jersy in java. So you can map methods on url+http method! – Anton Oct 25 '13 at 00:03
  • Anton, Thanks. This is a temp communication setup between 2 applications till one application fully migrate to another and so this will be retired once migration has been completed with existence of one and only one application. That's why decided to don't go with creation of any additional independent services. – Jaish Mathews Oct 27 '13 at 05:03