Difference Betwn posting XML to Developer TN via Generic Java Client amp WM API based Java Client

I am trying to post XML to IS Service through
1 ) Generic Java client based Code ( See the code below)
2) WM API ( client.jar) based Code
3) Browser

I am getting through the 2 & 3 way but getting exception ( Reply:[ISS.0084.9004] Access Denied) while posting XML through way # 1. Access permission are proper as it works for another ways ( 2 & 3)
Generic Code i am using :
[highlight=java]
String reply = “”;
String tnURL = “”;
String xmlData = “”;
tnURL = “http://mahesh:mahesh@localhost:5555/invoke/exercise3/xmlInput”;
xmlData = " 19th Century American Novel ENG361_11 J. Smith ";
URL url = new URL(tnURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty(“Content-Type”,“text/xml; charset=utf-8”);
httpConn.setDoOutput(true);

// Set the Action header
httpConn.setRequestMethod( “POST” );
// Post the message.
OutputStream out = httpConn.getOutputStream() ;
byte requestXML = xmlData.getBytes();
out.write(requestXML);
out.close();
reply = httpConn.getResponseMessage();
int responseCode = httpConn.getResponseCode();
System.out.println(“Reply:”+ reply);
[/highlight]

Now i am getting Access Denied error

Can anybody through some light on it … How to post the XML to IS Service / TN without using the WM API code ???

Thanks
Deepak

You have to set the HTTP header to include Basic Authentication and provide the username and password for the service you are trying to invoke (within IS there will be an ACL applied to your service). Check your API code to figure out how to do this.

Can anybody provides me the code to how to include Basic Authentication in HTTP Header.
I tried : httpConn.setRequestProperty(“Authorization”,“mahesh:mahesh”);
Where mahesh:mahesh (userid/pwd)

Will

I am using normal java API to post the xml

Thanks
Deepak

Deepak,

What you are doing is right except that the username and password combination string should be base64 encoded.

Here’s another snippet that may work for you:
String authString = “mahesh:mahesh”;
String auth = "Basic " +
new sun.misc.BASE64Encoder().encode(authString.getBytes());
httpConn.setRequestProperty(“Authorization”,auth);

Thanks a lot all of you !! I am enlightened to see the so fast responses on this forum !!.

I am able to do the posting through java client.
I was trying to get reply from IS service by using pub.flow.setResponse service. But always i am not getting the message i have set in the “response” parameter of setResponse service. Rather I am getting “Ok” on every hit of IS Service…
Plz let me know how to get reply back from IS Service.

Thanks
Deepak

Deepak,

httpConn.getResponseMessage() returns the server message (see the API docs for this method)

you can call httpConn.getInputStream and process from there…

Haithem

Haithem ,

Thanks for your input, its working for me finally !!
One difference I have noticed that outputs of my IS Service are coming while I invoke it through WM API Java Client code but not in the case of while doing it through generic java code. If i invoke IS Service through generic Java Client code, I am getting response whatever i have set in “pub.flow.setRespose”.

Thanks
Deepak

"If i invoke IS Service through generic Java Client code, I am getting response whatever i have set in “pub.flow.setRespose”. "

That is what is supposed to happen. The IS pipeline is not returned when using generic HTTP code. The IS client library and the server do extra work to get all the pipeline values–which is nice but forces clients to use the wM IS client.jar, which may not be acceptable/desirable.

I usually recommend that client code stick to the generic Java facilities and avoid using the wM IS API. Simply return all the data you want to return within the document you set during the pub.flow:setResponse call.

I would add to Rob’s comments just a little (at least in IS 4.6),
(Rob - please correct me if I’m wrong)

If you DON’T use the “setResponse” flow - IS returns the contents of the pipeline - BUT - formatted per the output template specified for that flow. If you don’t have an output template specified - you would get the default template which formats the output into a nice (pretty) HTML table. But as Rob has said - you are not working with pipeline data - just an inputstream. You have to parse the content as required.

If you do use “setResponse” the effect of that is to override the output template, and the response stream contains whatever was passed into the “setResponse”. Again you are left to process the content as an inputstream on the client side.

That was definitely an ommission on my part Haithem. Thanks for filling in that hole.

When such a code is used (Taken from first Post in this Thread):
[highlight=java]
URL url = new URL(tnURL);
URLConnection connection = url.openConnection();
HttpURLConnection httpConn = (HttpURLConnection) connection;
// Set the appropriate HTTP parameters.
httpConn.setRequestProperty(“Content-Type”,“text/xml; charset=utf-8”);
httpConn.setDoOutput(true);

// Set the Action header
httpConn.setRequestMethod( “POST” );
// Post the message.
OutputStream out = httpConn.getOutputStream() ;
byte requestXML = xmlData.getBytes();
out.write(requestXML);
[/highlight]
How one can read the data in webMethods Service. What do I need to do if I do not use httpConn.setRequestMethod( “POST” ); in my Generic Client.

With the content type set to text/xml as in your example, the data will be parsed as an XML document into a internal webMethods “node” object, which will be passed as an input to your service. You need to convert that “node” pipeline variable into a webMethods document (or record in 4.6) using pub.xml:xmlNodeToDocument (or the equivalent service in 4.6). That document will then contain all the data in your original XML request.

I am successfully posting XML to WM using the code above. However when I try to open the response with the getInputStrean(), I get the following exception:

Sorry I didn’t include the exception:
Unexpected end of file from server

Uday,

You are getting reply in that format becoz IS directly converting the pipeline data in to xml format and providing you the response , for your customized output ,

  1. either define variables , assign values to those , create XML from these variables and in that setResponse service set that XML.
  2. or directly assign the required XML formatted string to setResponse service

Thnks

Hi All
I found your mail ids from WmUsers.com website…
I have a similar problem so I thought of discussing over mail…

Here I am writing the problem of authentication from Websphere to MQ that we have… Please Help Us

  1. we have a Authenticated service in Webmethods IS. having Default ( Administrator/manage) ACLs.

  2. Then we Create a WSDL for this services using SOAP-MSG protocol , and an Input Document Type(inDoc) .

  3. It has been found that WSDL generated for the service is the same as for the same service without any Authentication or Anonymous access.

4)we import this WSDL into IBM webSphere to make a Webservice Client.

Problem
5) Now when we test this with web Service explorer in WebSphere it is not working the error is like…
There is nothing to be displayed in the form view. Please switch to the source view for the SOAP request and response.

SOAP response Envelop is :

[highlight=xml]

<?xml> SOAP-ENV:Client [ISS.0088.9134] Exception occurred while processing the body of the message [url="http://localhost:5555/soap/default"]http://localhost:5555/soap/default[/url] com.wm.app.b2b.server.AccessException [ISS.0084.9004] Access Denied [/highlight] Web Sphere Client is working fine for a webMethods service having Anonymous access. Please mail if you Need more clearer picture on this.. ,or give me you Phone Number so that I can discuss with you about the Problem.

Shubham-
Did you figure out the problem with the Access Denied error? i have the same problem accessing a web service using asp.net client with basic auth? appreciate any help
Thanks,
Ed

Hi,

I got same problem ([ISS.0084.9004] Access Denied) when calling a web service which is located in wm IS. Appreciate any help reging this

[highlight=xml]

<?xml> SOAP-ENV:Client [ISS.0088.9134] Exception occurred while processing the body of the message [URL="http://10.116.70.85:4343/soap/rpc"]http://10.116.70.85:4343/soap/rpc[/URL] com.wm.app.b2b.server.AccessException [ISS.0084.9004] Access Denied [/highlight]

Hi,
after some workaround it is working fine.
Action required: Change Execute ACL property for the target service

Thanks,
Chandu