private void collectValidationPointsForPortTypes() { for (QName ptName : portTypeRefNames) { PortType portType = getPortType(ptName); if (portType == null) { vResults.addError(new Message("NO_PORTTYPE", LOG, ptName)); continue; } XNode vPortTypeNode = getXNode(portType); for (Operation operation : getOperations(portType).values()) { XNode vOperationNode = getOperationXNode(vPortTypeNode, operation.getName()); if (operation.getInput() == null) { vResults.addError( new Message("WRONG_MEP", LOG, operation.getName(), portType.getQName())); continue; } javax.wsdl.Message inMsg = operation.getInput().getMessage(); if (inMsg == null) { addWarning( "Operation " + operation.getName() + " in PortType: " + portType.getQName() + " has no input message"); } else { XNode vInMsgNode = getXNode(inMsg); vInMsgNode.setFailurePoint(getInputXNode(vOperationNode, operation.getInput().getName())); vNodes.add(vInMsgNode); messageRefNames.add(inMsg.getQName()); } if (operation.getOutput() != null) { javax.wsdl.Message outMsg = operation.getOutput().getMessage(); if (outMsg == null) { addWarning( "Operation " + operation.getName() + " in PortType: " + portType.getQName() + " has no output message"); } else { XNode vOutMsgNode = getXNode(outMsg); vOutMsgNode.setFailurePoint( getOutputXNode(vOperationNode, operation.getOutput().getName())); vNodes.add(vOutMsgNode); messageRefNames.add(outMsg.getQName()); } } for (Iterator<?> iter = operation.getFaults().values().iterator(); iter.hasNext(); ) { Fault fault = (Fault) iter.next(); javax.wsdl.Message faultMsg = fault.getMessage(); XNode vFaultMsgNode = getXNode(faultMsg); vFaultMsgNode.setFailurePoint(getFaultXNode(vOperationNode, fault.getName())); vNodes.add(vFaultMsgNode); messageRefNames.add(faultMsg.getQName()); } } } }
// TODO: Should also check SoapHeader/SoapHeaderFault public boolean checkR2205() { Collection<Binding> bindings = CastUtils.cast(def.getBindings().values()); for (Binding binding : bindings) { if (!SOAPBindingUtil.isSOAPBinding(binding)) { System.err.println( "WSIBP Validator found <" + binding.getQName() + "> is NOT a SOAP binding"); continue; } if (binding.getPortType() == null) { // will error later continue; } for (Iterator<?> ite2 = binding.getPortType().getOperations().iterator(); ite2.hasNext(); ) { Operation operation = (Operation) ite2.next(); Collection<Fault> faults = CastUtils.cast(operation.getFaults().values()); if (CollectionUtils.isEmpty(faults)) { continue; } for (Fault fault : faults) { Message message = fault.getMessage(); Collection<Part> parts = CastUtils.cast(message.getParts().values()); for (Part part : parts) { if (part.getElementName() == null) { addErrorMessage( getErrorPrefix("WSI-BP-1.0 R2205") + "In Message " + message.getQName() + ", part " + part.getName() + " must specify a 'element' attribute"); return false; } } } } } return true; }
public void compile(OActivity output, Activity src) { ReplyActivity replyDef = (ReplyActivity) src; OReply oreply = (OReply) output; oreply.isFaultReply = replyDef.getFaultName() != null; oreply.partnerLink = _context.resolvePartnerLink(replyDef.getPartnerLink()); oreply.messageExchangeId = replyDef.getMessageExchangeId(); if (replyDef.getVariable() != null) { oreply.variable = _context.resolveVariable(replyDef.getVariable()); if (!(oreply.variable.type instanceof OMessageVarType)) throw new CompilationException( _cmsgsGeneral.errMessageVariableRequired(oreply.variable.name)); } if (oreply.partnerLink.myRolePortType == null) throw new CompilationException( _cmsgsGeneral.errPartnerLinkDoesNotDeclareMyRole(oreply.partnerLink.getName())); // The portType on the reply is not necessary, so we check its validty only when present. if (replyDef.getPortType() != null && !oreply.partnerLink.myRolePortType.getQName().equals(replyDef.getPortType())) throw new CompilationException( _cmsgsGeneral.errPortTypeMismatch( replyDef.getPortType(), oreply.partnerLink.myRolePortType.getQName())); oreply.operation = _context.resolveMyRoleOperation(oreply.partnerLink, replyDef.getOperation()); if (oreply.operation.getOutput() == null) throw new CompilationException( _cmsgsGeneral.errTwoWayOperationExpected(oreply.operation.getName())); if (oreply.isFaultReply) { Fault flt = null; if (replyDef .getFaultName() .getNamespaceURI() .equals(oreply.partnerLink.myRolePortType.getQName().getNamespaceURI())) flt = oreply.operation.getFault(replyDef.getFaultName().getLocalPart()); if (flt == null) throw new CompilationException( __cmsgsLocal.errUndeclaredFault( replyDef.getFaultName().getLocalPart(), oreply.operation.getName())); if (oreply.variable != null && !((OMessageVarType) oreply.variable.type) .messageType.equals(flt.getMessage().getQName())) throw new CompilationException( _cmsgsGeneral.errVariableTypeMismatch( oreply.variable.name, flt.getMessage().getQName(), ((OMessageVarType) oreply.variable.type).messageType)); oreply.fault = replyDef.getFaultName(); } else /* !oreply.isFaultReply */ { assert oreply.fault == null; if (oreply.variable == null) throw new CompilationException(__cmsgsLocal.errOutputVariableMustBeSpecified()); if (!((OMessageVarType) oreply.variable.type) .messageType.equals(oreply.operation.getOutput().getMessage().getQName())) throw new CompilationException( _cmsgsGeneral.errVariableTypeMismatch( oreply.variable.name, oreply.operation.getOutput().getMessage().getQName(), ((OMessageVarType) oreply.variable.type).messageType)); } for (Correlation correlation : replyDef.getCorrelations()) { OScope.CorrelationSet cset = _context.resolveCorrelationSet(correlation.getCorrelationSet()); switch (correlation.getInitiate()) { case UNSET: case NO: oreply.assertCorrelations.add(cset); break; case YES: oreply.initCorrelations.add(cset); break; default: // TODO: Make error for this. throw new AssertionError(); } for (Iterator<OProcess.OProperty> j = cset.properties.iterator(); j.hasNext(); ) { OProcess.OProperty property = j.next(); // Force resolution of alias, to make sure that we have one for this variable-property pair. _context.resolvePropertyAlias(oreply.variable, property.name); } } }
public ReplyAction readReplyAction(Element replyElem, CompositeActivity parent) { ReplyAction replyAction = new ReplyAction(); // partner link String partnerLinkName = replyElem.getAttribute(BpelConstants.ATTR_PARTNER_LINK); PartnerLinkDefinition partnerLink = parent.findPartnerLink(partnerLinkName); if (partnerLink == null) { bpelReader.getProblemHandler().add(new ParseProblem("partner link not found", replyElem)); return replyAction; } replyAction.setPartnerLink(partnerLink); // port type Role myRole = partnerLink.getMyRole(); // BPEL-181 detect absence of my role if (myRole == null) { bpelReader .getProblemHandler() .add(new ParseProblem("partner link does not indicate my role", replyElem)); return replyAction; } PortType portType = bpelReader.getMessageActivityPortType(replyElem, partnerLink.getMyRole()); // operation Operation operation = bpelReader.getMessageActivityOperation(replyElem, portType); if (operation.getStyle() != OperationType.REQUEST_RESPONSE) { bpelReader .getProblemHandler() .add(new ParseProblem("not a request/response operation", replyElem)); return replyAction; } replyAction.setOperation(operation); // message exchange // BPEL-74: map the empty message exchange to null for compatibility with Oracle replyAction.setMessageExchange( XmlUtil.getAttribute(replyElem, BpelConstants.ATTR_MESSAGE_EXCHANGE)); // fault name Message replyMessage; Attr faultNameAttr = replyElem.getAttributeNode(BpelConstants.ATTR_FAULT_NAME); if (faultNameAttr != null) { QName faultName = XmlUtil.getQNameValue(faultNameAttr); replyAction.setFaultName(faultName); Fault fault = operation.getFault(faultName.getLocalPart()); if (fault == null) { bpelReader.getProblemHandler().add(new ParseProblem("fault not found", replyElem)); return replyAction; } replyMessage = fault.getMessage(); } else replyMessage = operation.getOutput().getMessage(); // variable VariableDefinition variable = bpelReader.getMessageActivityVariable( replyElem, BpelConstants.ATTR_VARIABLE, parent, replyMessage); replyAction.setVariable(variable); // correlations Element correlationsElement = XmlUtil.getElement(replyElem, BpelConstants.NS_BPEL, BpelConstants.ELEM_CORRELATIONS); if (correlationsElement != null) replyAction.setCorrelations( bpelReader.readCorrelations(correlationsElement, parent, variable)); return replyAction; }
protected void addPortTypeTransformers( PortType portType, boolean provider, StringBuffer transformers, javax.wsdl.Definition wsdl, ResourceLocator locator, String srcFolder) { String attr1 = (provider ? "from" : "to"); String attr2 = (provider ? "to" : "from"); for (Object opobj : portType.getOperations()) { if (opobj instanceof javax.wsdl.Operation) { javax.wsdl.Operation op = (javax.wsdl.Operation) opobj; String qname = ""; String javaType = ""; String javaPackage = ""; javax.wsdl.Part p = (javax.wsdl.Part) op.getInput().getMessage().getParts().values().iterator().next(); qname = p.getElementName().toString(); javaType = getJavaType(wsdl, p.getElementName(), locator); if (javaType != null) { int ind = javaType.lastIndexOf('.'); if (ind != -1) { javaPackage = javaType.substring(0, ind); } } transformers.append("\t\t<xform:transform.jaxb\r\n"); transformers.append("\t\t\t" + attr1 + "=\"" + qname + "\"\r\n"); transformers.append("\t\t\t" + attr2 + "=\"java:" + javaType + "\"\r\n"); transformers.append("\t\t\tcontextPath=\"" + javaPackage + "\"/>\r\n"); if (op.getOutput() != null) { p = (javax.wsdl.Part) op.getOutput().getMessage().getParts().values().iterator().next(); qname = p.getElementName().toString(); javaType = getJavaType(wsdl, p.getElementName(), locator); if (javaType != null) { int ind = javaType.lastIndexOf('.'); if (ind != -1) { javaPackage = javaType.substring(0, ind); } } transformers.append("\t\t<xform:transform.jaxb\r\n"); transformers.append("\t\t\t" + attr2 + "=\"" + qname + "\"\r\n"); transformers.append("\t\t\t" + attr1 + "=\"java:" + javaType + "\"\r\n"); transformers.append("\t\t\tcontextPath=\"" + javaPackage + "\"/>\r\n"); } for (Object faultObj : op.getFaults().values()) { if (faultObj instanceof javax.wsdl.Fault) { javax.wsdl.Fault fault = (javax.wsdl.Fault) faultObj; p = (javax.wsdl.Part) fault.getMessage().getParts().values().iterator().next(); qname = p.getElementName().toString(); String javaFaultType = getJavaType(wsdl, p.getElementName(), locator); String pack = JavaGeneratorUtil.getJavaPackage(fault.getMessage().getQName().getNamespaceURI()); javaType = pack + "." + JavaGeneratorUtil.getJavaClassName( fault.getMessage().getQName().getLocalPart()); String transformerClassName = getFaultTransformerClassName(javaType, provider); String faultTransClass = pack + "." + transformerClassName; transformers.append("\t\t<xform:transform.java class=\"" + faultTransClass + "\"\r\n"); transformers.append("\t\t\t" + attr2 + "=\"" + qname + "\"\r\n"); transformers.append("\t\t\t" + attr1 + "=\"java:" + javaType + "\"/>\r\n"); // Create transformer class String folder = pack.replace('.', java.io.File.separatorChar); String javaFile = folder + java.io.File.separator + transformerClassName; java.io.File jFile = new java.io.File(srcFolder + java.io.File.separator + javaFile + ".java"); jFile.getParentFile().mkdirs(); try { java.io.FileOutputStream fos = new java.io.FileOutputStream(jFile); generateFaultTransformer(qname, javaType, javaFaultType, provider, fos); fos.close(); } catch (Exception e) { logger.log(Level.SEVERE, "Failed to create fault transformer", e); } } } } } }