|
From: <dgl...@us...> - 2003-08-11 07:25:40
|
Update of /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/stage
In directory sc8-pr-cvs1:/tmp/cvs-serv2175/modules/soap/src/com/babeldoc/soap/pipeline/stage
Modified Files:
SoapWriterPipelineStage.java
Log Message:
Soap response is now stored in an attribute 'SoapWriterResponse' in the document.
Implemented username/password authentication.
Index: SoapWriterPipelineStage.java
===================================================================
RCS file: /cvsroot/babeldoc/babeldoc/modules/soap/src/com/babeldoc/soap/pipeline/stage/SoapWriterPipelineStage.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** SoapWriterPipelineStage.java 7 Aug 2003 04:21:44 -0000 1.11
--- SoapWriterPipelineStage.java 11 Aug 2003 07:25:37 -0000 1.12
***************
*** 75,78 ****
--- 75,79 ----
import java.io.ByteArrayOutputStream;
+ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collection;
***************
*** 90,97 ****
*/
public class SoapWriterPipelineStage extends PipelineStage {
! public static final String SOAP_URL = "soapUrl";
! public static final String SOAP_ACTION = "soapAction";
! public static final String RESULT_STAGE = "resultStage";
! public static final String RESPONSE_DOC = "responseDoc";
/**
--- 91,101 ----
*/
public class SoapWriterPipelineStage extends PipelineStage {
! public static final String SOAP_URL = "soapUrl";
! public static final String SOAP_ACTION = "soapAction";
! public static final String RESULT_STAGE = "resultStage";
! public static final String RESPONSE_DOC = "responseDoc";
! public static final String AUTHENTICATION = "authentication";
! public static final String USERNAME = "username";
! public static final String PASSWORD = "password";
/**
***************
*** 112,125 ****
//add specific options
! options.add(new ConfigOption(SOAP_URL, IConfigOptionType.URL, null,
! false, I18n.get("soap.101")));
! options.add(new ConfigOption(SOAP_ACTION, IConfigOptionType.STRING,
null, false, I18n.get("soap.102")));
! options.add(new ConfigOption(RESULT_STAGE, IConfigOptionType.STRING,
null, true, I18n.get("soap.103")));
! options.add(new ConfigOption(RESULT_STAGE, IConfigOptionType.STRING,
null, true, I18n.get("soap.103")));
! options.add(new ConfigOption(RESPONSE_DOC, IConfigOptionType.BOOLEAN,
null, false, I18n.get("soap.106")));
return options;
--- 116,135 ----
//add specific options
! options.add(new ConfigOption(SOAP_URL, IConfigOptionType.URL,
! null, false, I18n.get("soap.101")));
! options.add(new ConfigOption(SOAP_ACTION, IConfigOptionType.STRING,
null, false, I18n.get("soap.102")));
! options.add(new ConfigOption(RESULT_STAGE, IConfigOptionType.STRING,
null, true, I18n.get("soap.103")));
! options.add(new ConfigOption(RESULT_STAGE, IConfigOptionType.STRING,
null, true, I18n.get("soap.103")));
! options.add(new ConfigOption(RESPONSE_DOC, IConfigOptionType.BOOLEAN,
null, false, I18n.get("soap.106")));
+ options.add(new ConfigOption(AUTHENTICATION, IConfigOptionType.BOOLEAN,
+ null, false, I18n.get("soap.107")));
+ options.add(new ConfigOption(USERNAME, IConfigOptionType.STRING,
+ null, false, I18n.get("soap.108")));
+ options.add(new ConfigOption(PASSWORD, IConfigOptionType.STRING,
+ null, false, I18n.get("soap.109")));
return options;
***************
*** 140,144 ****
*/
public static String sendSoapMessage(String soapUrl, String soapAction,
! boolean returnResponse, PipelineDocument document) throws Exception {
// create a message
MessageFactory mf = MessageFactory.newInstance();
--- 150,155 ----
*/
public static String sendSoapMessage(String soapUrl, String soapAction,
! boolean returnResponse, Authentication authentication, PipelineDocument document)
! throws Exception {
// create a message
MessageFactory mf = MessageFactory.newInstance();
***************
*** 152,155 ****
--- 163,177 ----
headers.addHeader("SOAPAction", soapAction);
+ // get the SOAP header
+ SOAPHeader header = message.getSOAPPart().getEnvelope().getHeader();
+
+ // if needed, add authentication
+ if (authentication != null) {
+ soapUrl = encodeURLForAuthentication(
+ soapUrl,
+ authentication.getUsername(),
+ authentication.getPassword());
+ }
+
// establish the connection
URLEndpoint endPoint = new URLEndpoint(soapUrl);
***************
*** 188,194 ****
String responseDoc = getOptions(RESPONSE_DOC);
boolean returnResponse = Boolean.valueOf(responseDoc).booleanValue();
String response = null;
try {
! response = sendSoapMessage(soapUrl, soapAction, returnResponse, this.getDocument());
} catch (Exception e) {
throw new PipelineException(I18n.get("soap.104"), e);
--- 210,233 ----
String responseDoc = getOptions(RESPONSE_DOC);
boolean returnResponse = Boolean.valueOf(responseDoc).booleanValue();
+
+ // determine if authentication is required
+ String authentication = getOptions(AUTHENTICATION);
+ boolean isAuthentication = Boolean.valueOf(authentication).booleanValue();
+ Authentication authenticationParams = null;
+ if (isAuthentication) {
+ authenticationParams = new Authentication(
+ getOptions(USERNAME),
+ getOptions(PASSWORD));
+ }
+
+ // post the soap message
String response = null;
try {
! response = sendSoapMessage(
! soapUrl,
! soapAction,
! returnResponse,
! authenticationParams,
! this.getDocument());
} catch (Exception e) {
throw new PipelineException(I18n.get("soap.104"), e);
***************
*** 196,209 ****
if (returnResponse) {
! try {
! return super.processHelper("text/xml", new String[] {response});
! }
! catch (Exception e) {
! throw new com.babeldoc.core.pipeline.PipelineException("SOAPWriter", e);
! }
}
! else {
! return super.processHelper();
! }
}
}
--- 235,318 ----
if (returnResponse) {
! // add the response as an attribute of the document
! this.getDocument().put("SoapWriterResponse", response);
}
! return super.processHelper();
! }
!
! /**
! * Encodes a URL for authentication
! * @return the encoded URL
! * @param url the web service url to post to
! * @param username the username for authentication
! * @param password the password for authentication
! * @throws Exception
! */
! private static String encodeURLForAuthentication(
! String url,
! String username,
! String password)
! throws Exception {
!
! // insert the encoded username and password into the passed URL such that
! // the URL:
! // http(s)://www.mysoapservice.com/service
! // is transformed into:
! // http(s)://encoded-username:enc...@ww.../service
! String retv = url.replaceFirst("://", "://"
! + URLEncoder.encode(username,"UTF-8")
! + ":" + URLEncoder.encode(password,"UTF-8") + "@");
! return retv;
! }
!
! /**
! * Stores the authentication parameters for use in sendSoapMessage
! */
! private class Authentication {
! private String username;
! private String password;
!
! /**
! * Creates an Authentication instance
! * @param username Username with which to authenticate
! * @param password Password with which to authenticate
! */
! public Authentication(String username, String password) {
! this.username = username;
! this.password = password;
! }
!
! /**
! * Returns the password.
! * @return String
! */
! public String getPassword() {
! return password;
! }
!
! /**
! * Returns the username.
! * @return String
! */
! public String getUsername() {
! return username;
! }
!
! /**
! * Sets the password.
! * @param password The password to set
! */
! public void setPassword(String password) {
! this.password = password;
! }
!
! /**
! * Sets the username.
! * @param username The username to set
! */
! public void setUsername(String username) {
! this.username = username;
! }
!
}
}
|