Author: jonathan
Date: Wed Jun 25 14:47:11 2008
New Revision: 18641
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=18641

Log:
Initial commit of WSRequest proxy jsp.

Added:
   trunk/mashup/java/modules/www/WSRequestXSSproxy.jsp

Added: trunk/mashup/java/modules/www/WSRequestXSSproxy.jsp
URL: 
http://wso2.org/svn/browse/wso2/trunk/mashup/java/modules/www/WSRequestXSSproxy.jsp?pathrev=18641
==============================================================================
--- (empty file)
+++ trunk/mashup/java/modules/www/WSRequestXSSproxy.jsp Wed Jun 25 14:47:11 2008
@@ -0,0 +1,196 @@
+<%--
+ * Copyright 2008 WSO2, Inc. http://www.wso2.org
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+--%>
+<%@ page import="org.apache.axis2.client.Options" %>
+<%@ page import="org.apache.axis2.client.ServiceClient" %>
+<%@ page import="org.apache.axis2.addressing.EndpointReference" %>
+<%@ page import="org.apache.axiom.om.OMElement" %>
+<%@ page import="org.apache.axiom.om.util.Base64" %>
+<%@ page import="javax.xml.stream.XMLStreamReader"%>
+<%@ page import="javax.xml.stream.XMLInputFactory"%>
+<%@ page import="org.apache.axiom.om.impl.builder.StAXOMBuilder"%>
+<%@ page import="java.io.StringReader"%>
+<%@ page import="org.apache.axiom.soap.SOAP11Constants"%>
+<%@ page import="org.apache.axiom.soap.SOAP12Constants"%>
+<%@ page import="org.apache.axis2.Constants"%>
+<%@ page import="org.apache.axis2.description.WSDL2Constants"%>
+<%@ page import="org.apache.axis2.util.JavaUtils"%>
+<%@ page import="org.apache.axis2.addressing.AddressingConstants"%>
+<%@ page import="org.apache.axis2.transport.http.HttpTransportProperties"%>
+<%@ page import="org.apache.axis2.transport.http.HTTPConstants"%><%@ page 
import="org.apache.axis2.AxisFault"%><%@ page 
import="org.apache.axis2.context.OperationContext"%><%@ page 
import="org.apache.axis2.context.MessageContext"%><%@ page 
import="org.apache.axiom.soap.SOAPEnvelope"%><%@ page 
import="org.apache.axiom.om.OMNamespace"%>
+<%@ page contentType="application/javascript" language="java" %>
+<%!
+
+    public static String decode(String s) throws Exception {
+        if ("~".equals(s)) return null;
+        return new String(Base64.decode(s), "UTF-8");
+    }
+
+%><%
+    String query = request.getQueryString();
+    String[] params = query.split(",");
+
+    // Extract and decode all the parameters used to call WSRequest
+    String scriptId = params[0];
+    boolean async = "true".equals(params[1]);
+    String uri = decode(params[2]);
+    String username = decode(params[3]);
+    String password = decode(params[4]);
+    String payload = decode(params[5]);
+
+    Options opts = new Options();
+    if (params.length > 5) {
+        for (int option=6; option<params.length; option++) {
+            String decoded = decode(params[option]);
+            String optionName = decoded.split(":")[0];
+            String optionValue = decoded.substring(optionName.length() + 1);
+
+            if ("action".equals(optionName)) {
+                opts.setAction(optionValue);
+            } else if ("useBinding".equals(optionName)) {
+                if (optionValue.equalsIgnoreCase("SOAP 1.1")) {
+                    
opts.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                } else if (optionValue.equalsIgnoreCase("SOAP 1.2")) {
+                    
opts.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                } else if (optionValue.equalsIgnoreCase("HTTP")) {
+                    opts.setProperty(Constants.Configuration.ENABLE_REST, 
Constants.VALUE_TRUE);
+                }
+            } else if ("useSOAP".equals(optionName)) {
+                if (optionValue.equalsIgnoreCase("1.1")) {
+                    
opts.setSoapVersionURI(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                } else if ((optionValue.equalsIgnoreCase("1.2")) || 
(optionValue.equalsIgnoreCase("true"))) {
+                    
opts.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                } else if (optionValue.equalsIgnoreCase("false")) {
+                    opts.setProperty(Constants.Configuration.ENABLE_REST, 
Constants.VALUE_TRUE);
+                }
+            } else if ("HTTPInputSerialization".equals(optionName)) {
+                
opts.setProperty(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION, optionValue);
+                opts.setProperty(Constants.Configuration.MESSAGE_TYPE, 
optionValue);
+            } else if ("HTTPQueryParameterSeparator".equals(optionName)) {
+                
opts.setProperty(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR, 
optionValue);
+            } else if ("HTTPLocation".equals(optionName)) {
+                opts.setProperty(WSDL2Constants.ATTR_WHTTP_LOCATION, 
optionValue);
+            } else if ("HTTPMethod".equals(optionName)) {
+                if (optionValue.equalsIgnoreCase("GET")) {
+                    opts.setProperty(Constants.Configuration.HTTP_METHOD,
+                                     Constants.Configuration.HTTP_METHOD_GET);
+                } else if (optionValue.equalsIgnoreCase("POST")) {
+                    opts.setProperty(Constants.Configuration.HTTP_METHOD,
+                                     Constants.Configuration.HTTP_METHOD_POST);
+                } else if (optionValue.equalsIgnoreCase("PUT")) {
+                    opts.setProperty(Constants.Configuration.HTTP_METHOD,
+                                     Constants.Configuration.HTTP_METHOD_PUT);
+                } else if (optionValue.equalsIgnoreCase("DELETE")) {
+                    opts.setProperty(Constants.Configuration.HTTP_METHOD,
+                                     
Constants.Configuration.HTTP_METHOD_DELETE);
+                }
+            } else if ("HTTPLocationIgnoreUncited".equals(optionName)) {
+                opts.setProperty(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED,
+                                JavaUtils.isTrueExplicitly(optionValue));
+
+            } else if ("useWSA".equals(optionName)) {
+                if (optionValue.equalsIgnoreCase("submission")) { // set 
addressing to
+                    // WSA submission version
+                    opts.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,
+                                        
AddressingConstants.Submission.WSA_NAMESPACE);
+                } else { // set addressing to WSA 1.0 version
+                    opts.setProperty(AddressingConstants.WS_ADDRESSING_VERSION,
+                                        
AddressingConstants.Final.WSA_NAMESPACE);
+                }
+
+            } else if ("from".equals(optionName)) {
+                opts.setFrom(new EndpointReference(optionValue));
+            } else if ("replyto".equals(optionName)) {
+                opts.setReplyTo(new EndpointReference(optionValue));
+            } else if ("messageid".equals(optionName)) {
+            } else if ("faultto".equals(optionName)) {
+                opts.setFaultTo(new EndpointReference(optionValue));
+            } else if ("useWSS".equals(optionName)) {
+                HttpTransportProperties.Authenticator authenticator = new 
HttpTransportProperties.Authenticator();
+                authenticator.setUsername(username);
+                if (password != null) { // set password if present
+                    authenticator.setPassword(password);
+                }
+                authenticator.setPreemptiveAuthentication(true);
+                opts.setProperty(HTTPConstants.AUTHENTICATE, authenticator);
+
+            }
+        }
+    }
+
+    opts.setTo(new EndpointReference(uri));
+
+    // Parse
+    OMElement payloadElement = null;
+    if (payload != null) {
+        try {
+            XMLStreamReader parser = 
XMLInputFactory.newInstance().createXMLStreamReader(
+                   new StringReader(payload));
+            StAXOMBuilder builder = new StAXOMBuilder(parser);
+            payloadElement = builder.getDocumentElement();
+        } catch (Exception e) {
+            throw new Error("INVALID_INPUT_EXCEPTION. Invalid input was : " + 
payload);
+        }
+    }
+    
+    //creating service client
+    ServiceClient sc = new ServiceClient();
+    sc.setOptions(opts);
+    if (opts.getProperty(AddressingConstants.WS_ADDRESSING_VERSION) != null)
+        sc.engageModule(Constants.MODULE_ADDRESSING);
+
+
+    String body = "";
+    try {
+        //invoke service
+        OMElement responseMsg = sc.sendReceive(payloadElement);
+
+        body = responseMsg.toString();
+
+    } catch (AxisFault axisFault) {
+        OperationContext operationContext = sc.getLastOperationContext();
+        if (operationContext != null) {
+            MessageContext messageContext =
+                    
operationContext.getMessageContext(WSDL2Constants.MESSAGE_LABEL_IN);
+            if (messageContext != null) {
+                SOAPEnvelope envelope = messageContext.getEnvelope();
+                if (envelope != null) {
+                    OMElement bodyElement = 
envelope.getBody().getFirstElement();
+                    if ("Exception".equals(bodyElement.getLocalName())) {
+                        OMNamespace ns = 
bodyElement.declareNamespace("http://wso2.org/ns/WSRequestXSS";, "http");
+                        bodyElement.addAttribute("status", "unknown error", 
ns);
+                    }
+                    body = bodyElement.toString();                    
+                }
+            }
+        }
+    }
+
+    /*
+    // If there is a SOAP fault, we need to serialize that as the body.
+    // If there is an HTTP error code, we need to report it using a similar 
structure.
+    if (httpstatus != 20x && soapVer == "0") { // http error
+        String httpStatus = "400";
+        String httpStatusText = "Test HTTP error";
+        body = "<error http:status='" + httpStatus + "' http:statusText='" + 
httpStatusText + "' xmlns:http='http://wso2.org/ns/WSRequest'>" + body + 
"</error>";
+    }
+    */
+
+    // escape the XML as a Javascript expression.
+    body = body.replace("\"", "\\\"");
+    body = body.replace("\n", "\"+\n\"");
+
+%>
+WSRequest._tunnelcallback("<%= scriptId%>", "<%= body %>");

_______________________________________________
Mashup-dev mailing list
[email protected]
http://www.wso2.org/cgi-bin/mailman/listinfo/mashup-dev

Reply via email to