use of com.sun.xml.ws.model.CheckedExceptionImpl in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method generatePortType.
/**
* Generates the WSDL portType
*/
protected void generatePortType() {
PortType portType = portDefinitions.portType().name(model.getPortTypeName().getLocalPart());
extension.addPortTypeExtension(portType);
for (JavaMethodImpl method : model.getJavaMethods()) {
Operation operation = portType.operation().name(method.getOperationName());
generateParameterOrder(operation, method);
extension.addOperationExtension(operation, method);
switch(method.getMEP()) {
case REQUEST_RESPONSE:
// input message
generateInputMessage(operation, method);
// output message
generateOutputMessage(operation, method);
break;
case ONE_WAY:
generateInputMessage(operation, method);
break;
default:
break;
}
// faults
for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
QName messageName = new QName(model.getTargetNamespace(), exception.getMessageName());
FaultType paramType = operation.fault().message(messageName).name(exception.getMessageName());
extension.addOperationFaultExtension(paramType, method, exception);
}
}
}
use of com.sun.xml.ws.model.CheckedExceptionImpl in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method generateBindingOperation.
protected void generateBindingOperation(JavaMethodImpl method, Binding binding) {
BindingOperationType operation = binding.operation().name(method.getOperationName());
extension.addBindingOperationExtension(operation, method);
String targetNamespace = model.getTargetNamespace();
QName requestMessage = new QName(targetNamespace, method.getOperationName());
List<ParameterImpl> bodyParams = new ArrayList<>();
List<ParameterImpl> headerParams = new ArrayList<>();
splitParameters(bodyParams, headerParams, method.getRequestParameters());
SOAPBinding soapBinding = method.getBinding();
operation.soapOperation().soapAction(soapBinding.getSOAPAction());
// input
TypedXmlWriter input = operation.input();
extension.addBindingOperationInputExtension(input, method);
BodyType body = input._element(Body.class);
boolean isRpc = soapBinding.getStyle().equals(Style.RPC);
if (soapBinding.getUse() == Use.LITERAL) {
body.use(LITERAL);
if (headerParams.size() > 0) {
if (bodyParams.size() > 0) {
ParameterImpl param = bodyParams.iterator().next();
if (isRpc) {
StringBuilder parts = new StringBuilder();
int i = 0;
for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
if (i++ > 0)
parts.append(' ');
parts.append(parameter.getPartName());
}
body.parts(parts.toString());
} else {
body.parts(param.getPartName());
}
} else {
body.parts("");
}
generateSOAPHeaders(input, headerParams, requestMessage);
}
if (isRpc) {
body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
}
} else {
// TODO localize this
throw new WebServiceException("encoded use is not supported");
}
if (method.getMEP() != MEP.ONE_WAY) {
// output
bodyParams.clear();
headerParams.clear();
splitParameters(bodyParams, headerParams, method.getResponseParameters());
TypedXmlWriter output = operation.output();
extension.addBindingOperationOutputExtension(output, method);
body = output._element(Body.class);
body.use(LITERAL);
if (headerParams.size() > 0) {
StringBuilder parts = new StringBuilder();
if (bodyParams.size() > 0) {
ParameterImpl param = bodyParams.iterator().hasNext() ? bodyParams.iterator().next() : null;
if (param != null) {
if (isRpc) {
int i = 0;
for (ParameterImpl parameter : ((WrapperParameter) param).getWrapperChildren()) {
if (i++ > 0) {
parts.append(" ");
}
parts.append(parameter.getPartName());
}
} else {
parts = new StringBuilder(param.getPartName());
}
}
}
body.parts(parts.toString());
QName responseMessage = new QName(targetNamespace, method.getResponseMessageName());
generateSOAPHeaders(output, headerParams, responseMessage);
}
if (isRpc) {
body.namespace(method.getRequestParameters().iterator().next().getName().getNamespaceURI());
}
}
for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
Fault fault = operation.fault().name(exception.getMessageName());
extension.addBindingOperationFaultExtension(fault, method, exception);
SOAPFault soapFault = fault._element(SOAPFault.class).name(exception.getMessageName());
soapFault.use(LITERAL);
}
}
use of com.sun.xml.ws.model.CheckedExceptionImpl in project metro-jax-ws by eclipse-ee4j.
the class WSDLGenerator method generateSOAPMessages.
/**
* Generates messages for a SOAPBinding
* @param method The {@link JavaMethod} to generate messages for
* @param binding The {@link com.sun.xml.ws.api.model.soap.SOAPBinding} to add the generated messages to
*/
protected void generateSOAPMessages(JavaMethodImpl method, com.sun.xml.ws.api.model.soap.SOAPBinding binding) {
boolean isDoclit = binding.isDocLit();
// Message message = portDefinitions.message().name(method.getOperation().getName().getLocalPart());
Message message = portDefinitions.message().name(method.getRequestMessageName());
extension.addInputMessageExtension(message, method);
com.sun.xml.ws.wsdl.writer.document.Part part;
BindingContext jaxbContext = model.getBindingContext();
boolean unwrappable = true;
for (ParameterImpl param : method.getRequestParameters()) {
if (isDoclit) {
if (isHeaderParameter(param))
unwrappable = false;
part = message.part().name(param.getPartName());
part.element(param.getName());
} else {
if (param.isWrapperStyle()) {
for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
part = message.part().name(childParam.getPartName());
part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
}
} else {
part = message.part().name(param.getPartName());
part.element(param.getName());
}
}
}
if (method.getMEP() != MEP.ONE_WAY) {
message = portDefinitions.message().name(method.getResponseMessageName());
extension.addOutputMessageExtension(message, method);
for (ParameterImpl param : method.getResponseParameters()) {
if (isDoclit) {
part = message.part().name(param.getPartName());
part.element(param.getName());
} else {
if (param.isWrapperStyle()) {
for (ParameterImpl childParam : ((WrapperParameter) param).getWrapperChildren()) {
part = message.part().name(childParam.getPartName());
part.type(jaxbContext.getTypeName(childParam.getXMLBridge().getTypeInfo()));
}
} else {
part = message.part().name(param.getPartName());
part.element(param.getName());
}
}
}
}
for (CheckedExceptionImpl exception : method.getCheckedExceptions()) {
QName tagName = exception.getDetailType().tagName;
String messageName = exception.getMessageName();
QName messageQName = new QName(model.getTargetNamespace(), messageName);
if (processedExceptions.contains(messageQName))
continue;
message = portDefinitions.message().name(messageName);
extension.addFaultMessageExtension(message, method, exception);
// tagName.getLocalPart());
part = message.part().name("fault");
part.element(tagName);
processedExceptions.add(messageQName);
}
}
use of com.sun.xml.ws.model.CheckedExceptionImpl in project metro-jax-ws by eclipse-ee4j.
the class WsaTubeHelper method getFaultActionFromSEIModel.
String getFaultActionFromSEIModel(Packet requestPacket, Packet responsePacket) {
String action = null;
if (seiModel == null || wsdlPort == null) {
return action;
}
try {
SOAPMessage sm = responsePacket.getMessage().copy().readAsSOAPMessage();
if (sm == null) {
return action;
}
if (sm.getSOAPBody() == null) {
return action;
}
if (sm.getSOAPBody().getFault() == null) {
return action;
}
Detail detail = sm.getSOAPBody().getFault().getDetail();
if (detail == null) {
return action;
}
String ns = detail.getFirstChild().getNamespaceURI();
String name = detail.getFirstChild().getLocalName();
WSDLOperationMapping wsdlOp = requestPacket.getWSDLOperationMapping();
JavaMethodImpl jm = (wsdlOp != null) ? (JavaMethodImpl) wsdlOp.getJavaMethod() : null;
if (jm != null) {
for (CheckedExceptionImpl ce : jm.getCheckedExceptions()) {
if (ce.getDetailType().tagName.getLocalPart().equals(name) && ce.getDetailType().tagName.getNamespaceURI().equals(ns)) {
return ce.getFaultAction();
}
}
}
return action;
} catch (SOAPException e) {
throw new WebServiceException(e);
}
}
use of com.sun.xml.ws.model.CheckedExceptionImpl in project metro-jax-ws by eclipse-ee4j.
the class SOAPFaultBuilder method createException.
/**
* This should be called from the client side to throw an {@link Exception} for a given soap mesage
*/
public Throwable createException(Map<QName, CheckedExceptionImpl> exceptions) throws JAXBException {
DetailType dt = getDetail();
Node detail = null;
if (dt != null)
detail = dt.getDetail(0);
// return ProtocolException if the detail is not present or there is no checked exception
if (detail == null || exceptions == null) {
// throw a protocol exception
return attachServerException(getProtocolException());
}
// check if the detail is a checked exception, if not throw a ProtocolException
QName detailName = new QName(detail.getNamespaceURI(), detail.getLocalName());
CheckedExceptionImpl ce = exceptions.get(detailName);
if (ce == null) {
// No Checked exception for the received detail QName, throw a SOAPFault exception
return attachServerException(getProtocolException());
}
if (ce.getExceptionType().equals(ExceptionType.UserDefined)) {
return attachServerException(createUserDefinedException(ce));
}
Class exceptionClass = ce.getExceptionClass();
try {
Constructor constructor = exceptionClass.getConstructor(String.class, (Class) ce.getDetailType().type);
Exception exception = (Exception) constructor.newInstance(getFaultString(), getJAXBObject(detail, ce));
return attachServerException(exception);
} catch (Exception e) {
throw new WebServiceException(e);
}
}
Aggregations