API Manager error creating SOAP API: (Double Gateway) - wso2

We are using API Manager 2.1.0 with a distributed deployment (double gateways).
When we create a SOAP API using a soap endpoint, we get an error.
These are the steps we followed in the API creator web interface:
Create a new API 'I Have SOAP endpoint'
In the Design API we add all the information required and save
When saving, we have an error when importing the WSDL:
ERROR {org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader} - Error occurred while getting the wsdl address location {org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader}
java.net.MalformedURLException: no protocol: null/testphone/1.0
at java.net.URL.<init>(URL.java:593)
at java.net.URL.<init>(URL.java:490)
at java.net.URL.<init>(URL.java:439)
at org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader.setServiceDefinition(APIMWSDLReader.java:307)
at org.wso2.carbon.apimgt.impl.utils.APIMWSDLReader.updateWSDL(APIMWSDLReader.java:156)
at org.wso2.carbon.apimgt.impl.utils.APIUtil.createWSDL(APIUtil.java:1375)
at org.wso2.carbon.apimgt.impl.APIProviderImpl.updateWsdl(APIProviderImpl.java:731)
at org.wso2.carbon.apimgt.impl.APIProviderImpl.updateAPI(APIProviderImpl.java:836)
at org.wso2.carbon.apimgt.impl.UserAwareAPIProvider.manageAPI(UserAwareAPIProvider.java:72)
at org.wso2.carbon.apimgt.hostobjects.APIProviderHostObject.saveAPI(APIProviderHostObject.java:1061)
at org.wso2.carbon.apimgt.hostobjects.APIProviderHostObject.jsFunction_updateAPIImplementation(APIProviderHostObject.java:672)
at sun.reflect.GeneratedMethodAccessor392.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126)
at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:386)
and the WSDL imported (in the registry) has a null in the location in wsdl:port.
If we use only one gateway and import the same WSDL we do not have the error and everything works smoothly.
The problem is not related to the WSDL and it happens with all WSDL.
How can we solve it?

We have solved the problem. These are the steps we used following this link (https://wso2.org/jira/browse/APIMANAGER-5843) and (https://github.com/wso2/carbon-apimgt/pull/4301/commits/c9d38bd0864bc84b3d8f5731ccc6a49068448f33):
Download the source code of the version of your API Carbon Mgt and locate APIUtil.java (org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/utils/APIUtil.java)
Find the method getGatewayendpoint(String transports) and replace it with this code lines:
public static String getGatewayendpoint(String transports) {
String gatewayURLs;
Map<String, Environment> gatewayEnvironments = ServiceReferenceHolder.getInstance()
.getAPIManagerConfigurationService()
.getAPIManagerConfiguration()
.getApiGatewayEnvironments();
if (gatewayEnvironments.size() > 1) {
for (Environment environment : gatewayEnvironments.values()) {
if (APIConstants.GATEWAY_ENV_TYPE_HYBRID.equals(environment.getType())) {
gatewayURLs = environment.getApiGatewayEndpoint(); // This might have http,https
// pick correct endpoint
return APIUtil.extractHTTPSEndpoint(gatewayURLs, transports);
}
}
for (Environment environment : gatewayEnvironments.values()) {
if (APIConstants.GATEWAY_ENV_TYPE_PRODUCTION.equals(environment.getType())) {
gatewayURLs = environment.getApiGatewayEndpoint(); // This might have http,https
// pick correct endpoint
return APIUtil.extractHTTPSEndpoint(gatewayURLs, transports);
}
}
for (Environment environment : gatewayEnvironments.values()) {
if (APIConstants.GATEWAY_ENV_TYPE_SANDBOX.equals(environment.getType())) {
gatewayURLs = environment.getApiGatewayEndpoint(); // This might have http,https
// pick correct endpoint
return APIUtil.extractHTTPSEndpoint(gatewayURLs, transports);
}
}
} else {
gatewayURLs = ((Environment) gatewayEnvironments.values().toArray()[0]).getApiGatewayEndpoint();
return extractHTTPSEndpoint(gatewayURLs, transports);
}
return null;
}
Locate org.wso2.carbon.apimgt.impl_6.1.66 and replace the class with the new APIUtil.java
Add this patch according to WSO2 documentation
Now you can publish on mutliple gateway

Related

Could not find definition for webservice at wildfly 9

I wrote a webservice and the building Maven is all ok, but the deployment on wildfly 9 receives error:
Could not find definition for service {http://ws.sieciowyandroid.rogal.com/soap/Map}MapService.
all log server: here
wsdl is: here
and schema: here
and my code:
#SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
#WebService(name = "MapWebServiceEJB", targetNamespace = "http://ws.sieciowyandroid.rogal.com/soap/Map",
serviceName = "MapService", portName = "MapPort", wsdlLocation = "wsdl/api.wsdl")
public class MapWebService implements MapPort {
#Override
public GetThumbnailResp getThumbnail(#WebParam(partName = "in0", name = "GetThumbnailReq", targetNamespace = "http://ws.sieciowyandroid.rogal.com/soap/GetThumbnail") GetThumbnailReq in0) {
GetThumbnailResp response = new GetThumbnailResp();
try {
response.setResult("czesc "+ in0.getName());
} catch (Exception e) {
response.setResult("ERROR");
}
return response;
}
}
I did not notice a fault that could cause this exception.
I will be grateful for your help
This may or may not be related, but if you are using Maven to package the dependencies, then you may be stripping out the schema file mappings. I had a similar problem with Spring Framework and the answer posted here solve my problem. You can likely replace the spring references with the appropriate resources for your issue.
Idea to avoid that spring.handlers/spring.schemas get overwritten when merging multiple spring dependencies in a single jar

simple azure web service, http404 error on publish when adding /dowork to URL

I am trying my first web app service using Azure services. I've created it in VS, and it works locally. All it does it return a string that says "hello user" is JSON.
[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
// To create an operation that returns XML,
// add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
// and include the following line in the operation body:
// WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
[OperationContract]
[WebGet(UriTemplate = "/DoWork")]
public string DoWork()
{
// Add your operation implementation here
return "hello user";
}
// Add more operations here and mark them with [OperationContract]
}
}
Problem is when I publish it, says successful. I can see it running on portal.
When I goto published site I get the standard THIS WEB APP HAS BEEN SUCCESSFULLY CREATED, but... when I add the /DoWork to the URL I get HTTP error 404.
I know I must be missing something simple...
any ideas?
you're missing the name of the service. In your case would be something like:
http://engineappservicev001.azurewebsites.net/something.svc/dowork
More info in here:
http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services

calling web service from login module n websphere

I have a websphere login module which calls a web service to get some information while authenticating. There is a different web service URL for different environments. Can anyone suggest the best way of deploying this so I dont have to redeploy the code between environments.
I have added the wsdl's to the META-INF folder in my deployed jar file. And set custom properties for the login module so I can determine which wsdl file to get.
However when I search for the wsdl it does not correctly load it as it throws a null pointer after intialisation.
[6/26/14 15:23:48:786 BST] 00000048 SystemOut O Debug: com.xxx.login.module.xxxCustomLoginModule
[6/26/14 15:23:48:786 BST] 00000048 SystemOut O got wsdl Url file:/usr/websphere7/ndb70SU3_B
117/lib/ext/xxxCustomLoginModule.jar!/META-INF/wsdl/my-pre.wsdl
the code I use to load it is the same as in the geenrated files
MYWS adamStub = null;
debugOut("WebserviceUrl = " +this.options.get("webServiceWsdlLocation"));
if(this.options.get("webServiceWsdlLocation") != null) {
URL wsdlUrl = getWsdlUrl();
debugOut("got wsdl Url " + wsdlUrl.getPath());
new MYWS (wsdlUrl, new QName(QNAME_WEBSERVICES, IADAM_L));
} else {
adamStub = new MYWS ();
}
and the get wsdl method
private URL getWsdlUrl() {
URL wsdlUrl = null;
try {
wsdlUrl = adam.xxxxxxx.class.getResource(
(String)this.options.get("webServiceWsdlLocation"));
if(wsdlUrl == null)
throw new MalformedURLException((String)this.options.get("webServiceWsdlLocation")+
" does not exist in the module.");
} catch(MalformedURLException e) {
e.printStackTrace();
}
return wsdlUrl;
}
I thought that this would have been the best way to do it for different environments but it cant seem to load the wsdl correctly. The get wsdl code is taken directly from the generated class and the line below works fine
adamStub = new MYWS ();
All suggestions are appreciated. I dont want to regenerate the client for each environment or from my build.
UPDATE:
Made a proper schoolboy error here forgot to do the assignment
new MYWS (wsdlUrl, new QName(QNAME_WEBSERVICES, IADAM_L));

why NotFound error occur in REST services with windows Phone app?

i tried to connect REST web servie from windows phone 8 application.
it was working proberly for weeks but after no change in it I get this generic error :
System.Net.WebException: The remote server returned an error:
NotFound.
i tried to test it by online REST Clients and services works properly
i tried to handle Exception and parse it as webException by this code :
var we = ex.InnerException as WebException;
if (we != null)
{
var resp = we.Response as HttpWebResponse;
response.StatusCode = resp.StatusCode;
and i get no more information and final response code is : "NotFound"
any one have any idea about what may cause this error?
there is already a trusted Certificate implemented on the server . the one who has the server suggested to have a DNS entry for the server, this entry should be at the customer DNS or in the phone hosts file .that what i done and worked for awhile but now it doesn't work however i checked that there is no thing changed
this is sample for Get Request it works proberly on Windwos Store apps :
async Task<object> GetHttps(string uri, string parRequest, Type returnType, params string[] parameters)
{
try
{
string strRequest = ConstructRequest(parRequest, parameters);
string encodedRequest = HttpUtility.UrlEncode(strRequest);
string requestURL = BackEndURL + uri + encodedRequest;
HttpWebRequest request = HttpWebRequest.Create(new Uri(requestURL, UriKind.Absolute)) as HttpWebRequest;
request.Headers["applicationName"] = AppName;
request.Headers["applicationPassword"] = AppPassword;
if (AppVersion > 1)
request.Headers["applicationVersion"] = AppVersion.ToString();
request.Method = "GET";
request.CookieContainer = cookieContainer;
var factory = new TaskFactory();
var getResponseTask = factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null);
HttpWebResponse response = await getResponseTask as HttpWebResponse;
// string s = response.GetResponseStream().ToString();
if (response.StatusCode == HttpStatusCode.OK)
{
XmlSerializer serializer = new XmlSerializer(returnType);
object obj = serializer.Deserialize(response.GetResponseStream());
return obj;
}
else
{
var Instance = Activator.CreateInstance(returnType);
(Instance as ResponseBase).NetworkError = true;
(Instance as ResponseBase).StatusCode = response.StatusCode;
return Instance;
}
}
catch (Exception ex)
{
return HandleException(ex, returnType);
}
}
i tried to monitor connections from Emulator and i found this error in connection :
**
Authentication failed because the remote party has closed the
transport stream.
**
You saw the client implement a server side certificate in the service. Did you have that certificate installed on the phone? That can be the cause of the NotFound error. Please, can you try to navigate to the service in the phone or emulator internet explorer prior to testing the app? If you do that, you can see the service working in the emulator/phone internet explorer? Maybe at that point internet explorer ask you about installing the certificate and then you can open your app, and it works.
Also remember if you are testing this in the emulator, every time you close it, the state is lost so you need to repeat the operation of installing the certificate again.
Hope this helps.
If you plan to use SSL in production in general public application (not company-distribution app), you need to ensure your certificate has one of the following root authorities:
SSL root certificates for Windows Phone OS 7.1.
When we had same issue, we purchased SSL certificate from one of those providers and after installing it on server we were able to make HTTPS requests to our services with no problem.
If you have company-distribution app, you can use any certificate from company's Root CA.

MonoTouch Web Service Request over SSL Gets 'authentication or decryption has failed'

A web service request over SSL raises a WebException on Monotouch v4.0.4.1:
'Error getting response stream (Write: The authentication or decryption has failed)'
Since the server's SSL certificate is self-signed (and btw I think it is not X.509), I am bypassing the certificate validation using ServicePointManager.ServerCertificateValidationCallback. The exact same code works fine on Windows .NET, where the web service call returns the correct result. On Monotouch adding a Writeline shows that the ServerCertificateValidationCallback delegate code is never reached.
Note: Although probably not relevant, the content of the request is SOAP with embedded WS-Security UsernameToken.
Has anyone got something like this to work on MonoTouch? Have seen reports of similar symptom but no resolution. The code and stacktrace are below, any comment appreciated. Can email a self-contained test case if wanted.
I gather there is an alternative approach using certmgr.exe to store the self-signed server certificate in the local trust store, but can't seem to find that app in the MonoTouch distribution. Could anyone point me to it?
..
public class Application
{
static void Main (string[] args)
{
UIApplication.Main (args);
}
}
// The name AppDelegate is referenced in the MainWindow.xib file.
public partial class AppDelegate : UIApplicationDelegate
{
// This method is invoked when the application has loaded its UI and its ready to run
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// If you have defined a view, add it here:
// window.AddSubview (navigationController.View);
string soapResponse;
string soapRequest = #" SOAP envelope is here but omitted for brevity ";
soapResponse = WebService.Invoke("myOperation", soapRequest);
window.MakeKeyAndVisible ();
return true;
}
// This method is required in iPhoneOS 3.0
public override void OnActivated (UIApplication application)
{
}
}
public class WebService
{
public static string Invoke(string operation, string soapRequest)
// Input parameters:
// operation = WS operation name
// soapRequest = SOAP XML request
// Output parameter:
// SOAP XML response
{
HttpWebResponse response;
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, ssl) => true;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://myserver.com:7570/MyEndpoint");
request.Method = "POST";
request.Headers.Add("SOAPAction", "/MyEndpoint/" + operation);
request.ContentType = "text/xml;charset=UTF-8";
request.UserAgent = "Smartphone";
request.ContentLength = soapRequest.Length;
request.GetRequestStream().Write(System.Text.Encoding.UTF8.GetBytes(soapRequest), 0, soapRequest.Length);
request.GetRequestStream().Close();
response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.UTF8))
{
return reader.ReadToEnd();
}
}
catch (WebException e)
{
throw new WebException(e.Message);
}
}
}
Stack trace (some names changed to protect the innocent, original available on request):
WS.WebService.Invoke (operation="myOperation", soapRequest="<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" \n\txmlns:ns1=\"http://mycompany/Common/Primitives/v1\" \n\txmlns:ns2=\"http://mycompany/Common/actions/externals/Order/v1\" \n\txmlns:ns3=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\">\n\t<SOAP-ENV:Header> <wsse:Security SOAP-ENV:mustUnderstand=\"1\" \n\txmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"> \n\t<wsse:UsernameToken wsu:Id=\"UsernameToken-1\" \n\txmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\"> \n\t<wsse:Username>myusername</wsse:Username> <wsse:Password \n\tType=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">mypw</wsse:Password> \n\t<wsse:Nonce>{0}</wsse:Nonce> \n\t<wsu:Created xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\">{1}</wsu:Created> \n\t</wsse:UsernameToken> </wsse:Security> \n\t</SOAP-ENV:Header><SOAP-ENV:Body><ns2:tp_getOrderDetailRequest><ns2:header><ns1:source>TEAM</ns1:source>\n\t<ns1:userAccessKey>12345678901234567</ns1:userAccessKey></ns2:header>\n\t<ns2:OrderId>myid1</ns2:OrderId>\n\t<ns2:OrderId>myid2</ns2:OrderId>\n\t</ns2:tp_getOrderDetailRequest>\n\t</SOAP-ENV:Body>\n\t</SOAP-ENV:Envelope>") in /Users/billf/Projects/WS/WS/Main.cs:103
WS.AppDelegate.FinishedLaunching (app={MonoTouch.UIKit.UIApplication}, options=(null)) in /Users/billf/Projects/WS/WS/Main.cs:52
MonoTouch.UIKit.UIApplication.Main (args={string[0]}, principalClassName=(null), delegateClassName=(null)) in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:26
MonoTouch.UIKit.UIApplication.Main (args={string[0]}) in /Developer/MonoTouch/Source/monotouch/monotouch/UIKit/UIApplication.cs:31
WS.Application.Main (args={string[0]}) in /Users/billf/Projects/WS/WS/Main.cs:18
MonoTouch (just like Mono) does not support TLS_DH* cipher suites (like TLS_DHE_DSS_WITH_AES_128_CBC_SHA).
When a server is configured to accept only them then the negotiation stage fails very early (an Alert is received from the server after the Client Hello message is sent) which explains why the callback was never called.
Ensure your server allows the more traditional cipher suites, e.g. the very secure (but slow) TLS_RSA_WITH_AES_256_CBC_SHA or the faster (and very common) Cipher Suite: TLS_RSA_WITH_RC4_128_[MD5|SHA], and Mono[Touch] should work well using them.
Note that this is unrelated to SOAP or web-services (and even X.509 certificates) - it's just plain SSL.
1) An untrusted root certificate is not the only problem that could result in this exception.
ServicePointManager.ServerCertificateValidationCallback = (sender, cert, chain, ssl) => true;
Add a Console.WriteLine in there so you'll see if it gets called (or not).
throw new WebException(e.Message);
and another here, with full stack trace (not just the Message property).
2) Each application is isolated. This means that:
applications cannot updates the global iOS certificate stores (that would create security issues);
if a certmgr tool existed (for MT) it could only use a local (mono) store that would be usable only for itself (which would not be of any help for your own apps)