Skip to main content
summaryrefslogtreecommitdiffstats
blob: a180801bd3715112cb6e72ddb1ea2f98627c506b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*******************************************************************************
 * Copyright (c) 2002-2005 IBM Corporation and others.
 * All rights reserved.   This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *   IBM - Initial API and implementation
 *******************************************************************************/
package org.eclipse.wst.wsi.internal.core.profile.validator.impl.envelope;

import javax.wsdl.Binding;
import javax.wsdl.BindingOperation;

import org.eclipse.wst.wsi.internal.core.WSIConstants;
import org.eclipse.wst.wsi.internal.core.WSIException;
import org.eclipse.wst.wsi.internal.core.analyzer.AssertionFailException;
import org.eclipse.wst.wsi.internal.core.analyzer.AssertionNotApplicableException;
import org.eclipse.wst.wsi.internal.core.profile.TestAssertion;
import org.eclipse.wst.wsi.internal.core.profile.validator.EntryContext;
import org.eclipse.wst.wsi.internal.core.profile.validator.impl.AssertionProcess;
import org.eclipse.wst.wsi.internal.core.profile.validator.impl.BaseMessageValidator;
import org.eclipse.wst.wsi.internal.core.report.AssertionResult;
import org.eclipse.wst.wsi.internal.core.util.HTTPUtils;
import org.eclipse.wst.wsi.internal.core.util.OperationSignature;
import org.eclipse.wst.wsi.internal.core.util.TypesRegistry;
import org.eclipse.wst.wsi.internal.core.wsdl.WSDLUtils;
import org.eclipse.wst.wsi.internal.core.xml.XMLUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;


/**
	 * BP1318
	 * 
	 * The grandchildren elements of soap:Body do not have a soap:encodingStyle attribute.
	 */
public class BP1318 extends AssertionProcess
{
  private final BaseMessageValidator validator;

  /**
   * @param BaseMessageValidator
   */
  public BP1318(BaseMessageValidator impl)
  {
    super(impl);
    this.validator = impl;
  }

  public AssertionResult validate(
    TestAssertion testAssertion,
    EntryContext entryContext)
    throws WSIException
  {
    try
    {
      if (this.validator.isOneWayResponse(entryContext))
        throw new AssertionNotApplicableException();

      // Parse message
      Document responseDoc = entryContext.getMessageEntryDocument();
      Document requestDoc = entryContext.getRequestDocument();

      // messages are empty or invalid, DOM objects are null
      if (responseDoc == null || requestDoc == null) {
        throw new AssertionNotApplicableException();
      }

      //if (isFault(responseDoc))
      //  throw new AssertionNotApplicableException();

      // Get SOAPAction
      String headers = entryContext.getRequest().getHTTPHeaders();
      String action = null;
      if (headers != null)
        action = (String) HTTPUtils.getHttpHeaderTokens(headers, ":").get("SOAPAction".toUpperCase());

      // Get the binding that is being processed                
      Binding binding = validator.analyzerContext.getCandidateInfo().getBindings()[0];

      //Create the types registry
      TypesRegistry registry =
        new TypesRegistry(
          this.validator.getWSDLDocument().getDefinitions(),
          validator);

      // Find an operation match        
      OperationSignature.OperationMatch match =
        OperationSignature.matchOperation(
          requestDoc,
          action,
          binding,
          registry);
      if (match == null)
        throw new AssertionNotApplicableException();

      // Get the binding operation based on the match
      BindingOperation bindingOperation = match.getOperation();

      // If this is not rpc-literal, then return notApplicable result
      if (!WSDLUtils
        .isRpcLiteral(match.getOperationStyle(), bindingOperation))
      {
        throw new AssertionNotApplicableException();
      }
      // look for <soap:Body> elements:
      NodeList soapBodyList =
        responseDoc.getElementsByTagNameNS(
          WSIConstants.NS_URI_SOAP,
          XMLUtils.SOAP_ELEM_BODY);
      if ((soapBodyList == null) || (soapBodyList.getLength() == 0))
        // Response does not contain any soap Body elements
        throw new AssertionNotApplicableException();

      // check that no <soap:Body> child or grandchild elements contains a soap:encodingStyle attribute
      // For each <soap:Body>
      boolean grandChildFound = false;
      for (int n = 0; n < soapBodyList.getLength(); n++)
      {
        Element nextBodyElem = (Element) soapBodyList.item(n);
        // REMOVE: This will get all nodes (child, grandchildren, etc.)
        //NodeList childList = nextBodyElem.getElementsByTagName("*");
        NodeList childList = nextBodyElem.getChildNodes();
        if (childList != null)
        {
          // check all child elements
          for (int m = 0; m < childList.getLength(); m++)
          {
            if (childList.item(m).getNodeType() == Node.ELEMENT_NODE)
            {
              Element nextChildElem = (Element) childList.item(m);
              // check children of this child
              // REMOVE: This will get all nodes (child, grandchildren, etc.)
              NodeList grandChildList = nextChildElem.getChildNodes();
              if (grandChildList != null)
              {
                for (int p = 0; p < grandChildList.getLength(); p++)
                {
                  if (grandChildList.item(p).getNodeType()
                    == Node.ELEMENT_NODE)
                  {
                  	grandChildFound = true;
                    Element nextGrandChildElem =
                      (Element) grandChildList.item(p);
                    if (nextGrandChildElem
                      .getAttributeNodeNS(
                        WSIConstants.NS_URI_SOAP,
                        "encodingStyle")
                      != null)
                    {
                      // Assertion failed (ADD highlight the child here ?)
                      throw new AssertionFailException(
                        entryContext.getMessageEntry().getMessage());
                    }
                  }
                }
              }
            }
          }
        }
      }
      if (!grandChildFound)
      {
      	throw new AssertionNotApplicableException();
      }
    }
    catch (AssertionFailException e)
    {
      result = AssertionResult.RESULT_FAILED;
      failureDetail = this.validator.createFailureDetail(e.getMessage(), entryContext);
    }
    catch (AssertionNotApplicableException e)
    {
      result = AssertionResult.RESULT_NOT_APPLICABLE;
    }
    // Return assertion result
    return validator.createAssertionResult(testAssertion, result, failureDetail);
  }
}

Back to the top